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.
First line contains T denoting Number of Test cases.
Each of the next T lines contains two integers denoting weakFinger and maxCount Respectively.
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.
Problem Setter : Arjun Singh Bhatia