You show off card tricks so often that your family is worn out. To put a stop to it, your dad picks a trick he believes you cannot do.
He blindfolds you and hands you a deck of N cards. He tells you that exactly K of them are face up, but not which ones. A second deck starts out empty.
Here is the goal. After the last operation the two decks have to hold the same number of face-up cards. That number does not have to be K. You are blindfolded and cannot see the arrangement, so one sequence of operations has to succeed for every possible initial arrangement of the face-up cards.
You may perform the following two operations in any order, any number of times.
To impress your dad you accepted the challenge, and you decided to find the shortest possible sequence of operations. Write a program that computes its length.
The first line contains a single integer T, the number of test cases. Each of the following T lines contains two integers N and K, separated by a space.
For each test case, print on one line the minimum number of operations needed to reach the goal. If the goal cannot be reached, print −1 instead.