#include using namespace std; using int64 = long long; using uint64 = unsigned long long; using T = tuple; // (k-4, k-3, k-2, k-1) vector seq; int cycleStart = 0, cycleLength = 0; void buildSeq() { map recorder; // Tが初めて出現した添字を記録する T t{0, 0, 0, 1}; seq = vector{0, 0, 0, 1}; while (recorder.count(t) == 0) { int T1, T2, T3, T4, T5; tie(T1, T2, T3, T4) = t; T5 = (T1 + T2 + T3 + T4) % 17; T1 = T2; T2 = T3; T3 = T4; T4 = T5; recorder[t] = seq.size(); seq.push_back(T5); t = make_tuple(T1, T2, T3, T4); } cycleStart = recorder[t]; cycleLength = seq.size() - cycleStart; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); buildSeq(); int Q; cin >> Q; for (int i = 0; i < Q; i++) { int64 n; cin >> n; n--; if (n < cycleStart) { cout << seq[n] << endl; } else { cout << seq[cycleStart + (n - cycleStart) % cycleLength] << endl; } } return 0; }