Setting the Alarm
Tag(s):

## Easy-Medium

Problem
Editorial
Analytics

It's already late and ThunderCracker needs to get up early tomorrow. He needs to quickly set his alarm so that he wakes up on time. This is how his alarm looks :

The alarm follows the $12$-hr format (i.e. hh $\in [1, 12]$, mm $\in [0, 59]$). To adjust the time of the alarm, there are $5$ keys that can be pressed : (hh+), (hh-), (mm+), (mm-), (#).

Key Effect
hh+ Increases the hour by 1. If hh is 12, it becomes 1.
hh- Decreases the hour by 1. If hh is 1, it becomes 12.
mm+ Increases the minute by 1. If mm is 59, it becomes 0, and the hour increases by 1.
mm- Decreases the minute by 1. If mm is 0, it becomes 59, and the hour decreases by 1.
# Toggles betweem am and pm.
Additionally, whenever hh changes from 11 to 12, or 12 to 11, the am/pm is toggled internally.

Here are some examples to understand how the alarm works :

Current Time Move Time to be Set
11:44 pm mm+ 11:45 pm
11:45 pm hh+ 12:45 am
12:45 am hh+ 01:45 am
01:45 am # 01:45 pm
12:00 pm hh- 11:00 am
11:59 am mm+ 12:00 pm

You are given the time that the alarm shows currently, and also the time for which the alarm is to be set. Help ThunderCracker set the alarm in the minimum number of moves (where each move represents a press of any of the keys.)

Input :

The first line of the input consists of $T$, the number of test cases. $T$ test cases follow.
Each test case consists of $2$ lines, the current time on the alarm, and the time to be set respectively, both in hh:mm am/pm format. (See sample input for details)

Output :

For each test case, print on a new line, a single integer, denoting the minimum number of moves required to set the alarm.

Constraints :

$1 ≤ T ≤ 10^4$
All the times will be in valid $12$-hr format.

Note : This problem has binary scoring. You will receive points only if you pass all test files successfully.

SAMPLE INPUT
2
01:20 am
01:25 pm
11:00 am
12:00 am
SAMPLE OUTPUT
6
2
Explanation

For the first test case, the moves required are : (mm+), (mm+), (mm+), (mm+), (mm+), (#).
For the second test case, the moves required are : (#), (hh+).

Time Limit: 5.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in

Challenge Name

Inscription '16

OTHER PROBLEMS OF THIS CHALLENGE
• Math > Basic Math
• Math > Number Theory
• Math > Linear Algebra