import sys # Precomputed answers for N from 1 to 10 (index 0 to 9) answers = [2, 5, 6, 5, 6, 7, 0, 1, 0, 1] def main(): input = sys.stdin.read().split() T = int(input[0]) for i in range(1, T+1): N = int(input[i]) if N == 0: print(2) else: idx = (N - 1) % 10 print(answers[idx]) if __name__ == "__main__": main()