Cats & Dogs have become friends now. They are going to a picnic and they decided to sit together in groups to have their lunch.
There are N Cats & M Dogs. They can form any number of groups to sit together, subject to rules below.
Rules:
They will sit in a straight line
A Cat cannot sit beside another Cat or alone
A Dog cannot sit beside another Dog or alone
You need to find minimum number of groups they need to form. If no group can be formed then print -1.
Input Format:
First line of input will be a number of Test Cases T
Next T lines of input will contains two numbers N and M, delimited by space
Output Format:
Print minimum number of groups to be formed for each Test Case in new line
OR
Print -1 if no group can be formed
Constraints:
- 0<T<=10^6
- 0<N,M<=10^18
Example: Sample input and output
S.No. | Input | Output |
1 | 2 5 5 1 3 | 1 -1 |
2 | 3 7 8 3 5 6 7 | 1 2 1 |


0 Comments