Triangle It!

View as PDF

Points: 3 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Assembly, C, C#, C++, Go, Haskell, Java, JS, Pascal, Perl, Python, Rust, Sed

Harry is building a pasta bridge for an engineering competition. Harry wants to try using many different types of right angled triangles, built up from three pasta noodles.

Harry already has two noodles picked out, with lengths and . He wants to know if it is possible to cut a new length of noodle , such that the three pasta noodles can be combined together to create a right angled triangle.

Input

Input will start with a single integer , the number of test cases. lines follow. On each line, there will be two integers , and .

Output

For each test case, output a single integer .

If there is an integer length of noodle that can form a right angled triangle, is the length of that noodle. Otherwise, is -1.

Example Run

Input:

2
3 5
5 1

Output:

4
-1

Explanation:

If we have noodles of size 3, 5 and 4, we can create a right angled triangle as follows:

There is no third integer length such that 5, 1, can form a right angled triangle.