# Arup Guha
# 7/2/2025
# Solution to SI@UCF CP Camp Contest #1 Problem: Next Square

# Returns the smallest perfect square greater than or equal to n.
def solve(n):

    # The perfect square we're looking for is somewhere in between
    # these two bounds.
    low = 1
    high = 1000000000

    # Run a binary search.
    while low < high:

        # Go halfway.
        mid = (low+high)//2

        # Our guess is too low, answer has to at least be mid+1 squared.
        if mid*mid < n:
            low = mid + 1

        # Can't be higher than this.
        else:
            high = mid

    # This is the most useful form of the answer.    
    return low*low

# This is what we'll run.
def main():

    # Process cases.
    nC = int(input())
    for loop in range(nC):

        # Get n, get next square and subtract.
        n = int(input())
        nextSq = solve(n)
        print(nextSq-n)

# Run it.
main()
    
