for z in range(int(input())):
    l=[1,2]
    n=int(input())
    if n%6==0:
        print(0)
    elif n%6==1:
        print(1)
    elif n%6==2:
        print(4)
    elif n%6==3:
        print(6)
    elif n%6==4:
        print(5)
    elif n%6==5:
        print(2)
