when you are going up hill you need to overcome more load so you drive the smaller gear which drives the bigger gear therefore amplifying the torque...
when you are on flat land you need more speed, so you drive the bigger gear which drives the smaller gear therefore amplifying the rpm