import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 p = [1, 2, 5, 6, 5, 6, 7, 0, 1, 0] for _ in range(ii()): print(p[ii() % 10])