题目描述
Little Vaishnavi is bored during the vacation which is going on. Being the only little girl in the neighbourhood she did not have any one else to play with. Her parents are so strict that they will not let her out of the house even to see what the kids from the other houses are playing.
So she decided to make a game of her own. As of now there is construction going on in her house there were lots of plywood sheets of rectangular size in her house. Now she is making a small game. She will take 5 such plywood pieces, out of which she will be taking one which is damaged! It can be placed anywhere among the 5 pieces.Now she will start jumping on the plywood and will be counting the number of jumps.
Say she will start from 1 and then she will go to plywood 2, then 3,then 4 and then 5th piece. After reaching the 5th plywood she will come back to 4th plywood, then to 3rd, than to 2nd and then to 1st. After that she will again jump to 2nd and then 3rd and so on! But as we know out of the 5 plywood pieces one will be defective. It will not support more than K jumps. After the Kth jump on the defective piece it will break.
Given the position of the defective plywood and the value of K we have to tell our cute Vaishnavi upto what will be the maximum of the count go up to?
Input:
The first line contains T, the number of test cases.
Followed by T lines each contain two numbers M and K
2 integers M and K where M is the position of the defective piece among the 5 pieces and K is the maximum jumps that can be made on the defective piece.
Output:
For every Test case Print the maximum count till vaishnavi can go up to.
Separate the answers for each test case by an empty line.
Constraints :
1 ≤ T ≤ 100
1 ≤ M ≤ 5
0 ≤ K ≤ 10^5
Problem Setter : Bipin Baburaj
Problem Tester : Darshak Mehta
SAMPLE INPUT
2
2 3
1 0
SAMPLE OUTPUT
15
0
Explanation
TestCase#1:
First Vaishnavi will jump from 1st ->2nd ->3rd ->4th->5th->4th->3rd->2nd->1st->2nd-> 3rd->4th->5th->4th->3rd.
If she moves to 2 then it will break so count is 15
输入格式
见题面
输出格式
见题面