#Lutece0540. SaSet

SaSet

Migrated from Lutece 540 SaSet

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Saya defines a set consists of square numbers({ii=x2,xN}\left \{ i\mid i=x^2,x\in N \right \} or {0,1,4,9,16}\{0,1,4,9,16\cdots\}) called Saya Set(SaSet for short). The addition on this set is defined by Saya:

a+0(aSaSet)=aa+0(a\in SaSet)=a

$a+1(a\in SaSet)=min(\left \{x\mid x>a,x\in SaSet\right \})$

(min(S)min(S) here is a function which returns the minimum element in the given set SS. For example, min(SaSet)=0min(SaSet)=0.)

Examples:

0+1=10+1=1, 1+1=41+1=4, 4+1=94+1=9\cdots

a0(aSaSet)=aa-0(a\in SaSet)=a

$a-1(a\in SaSet)=max(\left \{x\mid x<a, x\in SaSet\right \})$

(max(S)max(S) here is a function which returns the maximum element in the given set SS.)

Example:

11=01-1=0, 41=14-1=1, 91=49-1=4\cdots

a+b(a,bSaSet)=a+1+(b1)a+b(a,b\in SaSet)=a+1+(b-1)

Example:

4+4=4+1+(41)=9+1=164+4=4+1+(4-1)=9+1=16

Input

There is only one integer TT(1T501\leq T\leq 50) in the first line, which denotes the number of test cases.

Then T lines follows, each line will consists of two integers aa and bb(0a+b4000\leq a+b\leq 400,a,bSaSeta,b\in SaSet). You are asked to calculate the answer of a+ba+b.

Output

For each case, output an integer, which denotes the result of a+ba+b according to the definitions above.

Samples

2
0 0
4 4
0
16

Resources

Saya Mathematics@蒲公英的黄昏