A caterpillar is trapped in a glass that is 12 inches tall. The caterpillar can climb 4 inches per hour, but then it rests for an hour and slips back 1 inch. How many hours will it take for the caterpillar to get out?