#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    V<int> a = {1, 2, 5, 6, 5, 6, 7, 0, 1, 0};
    while (tt--) {
        long long N;
        cin >> N;
        if (N == 0) {
            cout << 2 << '\n';
        } else {
            cout << a[N % 10] << '\n';
        }
    }
    return 0;
}