for _ in range(int(input())):
    y, x = map(int, input().split()) # *  4, 2
    z = max(x, y)
    # * z = 4
    z2 = (z-1)**2
    # * z2 = 9
    ans = 0
    if z%2 == 1:
        if y == z:
            ans = z2+x
        else:
            ans = z2+2*z-y
    else:
        if x==z:
            ans = z2+y
        else:
            ans = z2+2*z-x
            
    print(ans)
12f81cb4b9794c7c59101ee84f44d25757aceb6a
<mask token>

for _ in range(int(input())):
    y, x = map(int, input().split())
    z = max(x, y)
    z2 = (z - 1) ** 2
    ans = 0
    if z % 2 == 1:
        if y == z:
            ans = z2 + x
        else:
            ans = z2 + 2 * z - y
    elif x == z:
        ans = z2 + y
    else:
        ans = z2 + 2 * z - x
    print(ans)

for _ in range(int(input())):
    y, x = map(int, input().split()) # *  4, 2
    z = max(x, y)
    # * z = 4
    z2 = (z-1)**2
    # * z2 = 9
    ans = 0
    if z%2 == 1:
        if y == z:
            ans = z2+x
        else:
            ans = z2+2*z-y
    else:
        if x==z:
            ans = z2+y
        else:
            ans = z2+2*z-x
            
    print(ans)