n=int(input()) destances=[] for _ in range(n): a=int(input()) b=(a**2)%10000 destances.append(b) for destance in destances: print(destance)