Problems
10051 - Mysterious Watch
SUBMIT PROBLEM

Mysterious Watch

Time Limit: 0.5 sec

 

The Problem

There are always some dumb friends in every friend circle like Siyam and Shafak. They always have trouble with solving problem of round things. (So dumb to see for eye problem :p ). 

 

 

Siyam has a watch but it is a very peculiar watch. Because the watch has only 40 marks (1 to 40) placed in its perimeter while normal watch has 60 marks placed in the perimeter. It has only one dial too. The picture above shows how the watch looks (the picture only shows 4 important marks 10,20,30,40. But it has 1 to 40 marked places). Siyam is so exploring by nature. He wants to know how many degrees the clock dial will rotate if it wants to rotate from one point to another. But he got confused while determining this. So he gave this problem to Shafak to solve it. But Shafak also got confused. Now he wants your help.

 

This watch has a special quality. It can move either clock wise or anti clock wise, for an example the dial can move from 10 to 20 in clock wise direction by moving only 10 unit distance or it can also move 10 to 20 by passing 30 unit of distance. Your work is to calculate  the minimum degree that the dial must rotate to go from one to another place.

 

The Input

The first line of input will contain the number of test cases T (0<T<=5000). Next T line will contain two integers N1 and N2 (0<N1 , N2<=40)  separated by space.

 

The Output

For every line of input, print the minimum degree that the dial should rotate to reach from N1 to N2.

 

Sample Input

2

11 21

21 11

 

Sample Output

90

90

 

 

 

Note:
In the first sample, if the dial rotates 90 degree in clock wise direction than it reaches from 11 to 21.

In the second sample, if the dial rotates 90 degree in anti clock wise direction than it reaches 21 to 11. 

 

 

Online Practice Contest 2 [School & College Level]

Problem Setter: Iram Sagor