a=[1,2,5,6,5,6,7,7,1,0] for _ in[0]*int(input()):n=int(input());print(a[n%10])