All Submissions


Your little brother is counting numbers with his left hand. Starting with his thumb and going toward his pinky, he counts each finger in order. After counting his pinky, he reverses direction and goes back toward his thumb. He repeats this process until he reaches his target number. He never skips a finger. For example, to count to ten, he would count: thumb, index, middle, ring, pinky, ring, middle, index, thumb, index.

Sadly, one of his fingers hurts and he can only count on it a limited number of times. His fingers are numbered 1 through 5 from thumb to pinky. You are given an Integer weakFinger, the finger that hurts, and an Integer maxCount, the maximum number of times he can use that finger.Print the largest number he can count to. If he cannot even begin counting, Print 0.

Input
First line contains T denoting Number of Test cases.
Each of the next T lines contains two integers denoting weakFinger and maxCount Respectively.

Output
For every test case print one Integer Denoting the maximum number which can be counted given the above constraints.
If he cannot even begin counting print 0.

Constraints
T=111
1<=weakFinger<=5
0<=maxCount<=100000

Sample Input

3
2 3
1 0
5 0


Sample Input

15
0
4


Problem Setter : Arjun Singh Bhatia



Languages: Brain,C,C++,Java,C#,JavaScript,Pascal,Perl,PHP,Python,Ruby,Text

Time Limit: 2 Second(s)
Score: 100 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings

RankNameScore
1xyz0
2Ams0
3TIP0
4team420
5xyzz0
6asdasdasd0
7abcd0
8khankhan0
9Gabriel0
10gigel0