Dad's Card Trick

No attempts yetTime limit1sMemory limit256 MB

Problem

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 NN cards. He tells you that exactly KK 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 KK. 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.

  1. Move one card from one deck to the other.
  2. Flip one card in either deck. A face-up card becomes face down, and a face-down card becomes face up.

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.

Input

The first line contains a single integer TT, the number of test cases. Each of the following TT lines contains two integers NN and KK, separated by a space.

  • 1T201 \le T \le 20
  • 1KN10001 \le K \le N \le 1000

Output

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-1 instead.