#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
struct Matrix {
    int n;
    vector<vector<int>> a;
    Matrix() : n(0) {}
    Matrix(int _n) {
        n = _n;
        a.resize(n, vector<int>(n, 0));
    }

    static Matrix identity(int n) {
        Matrix res(n);
        for (int i = 0; i < n; i++) {
            res.a[i][i] = 1;
        }
        return res;
    }

    Matrix operator*(const Matrix& other) const {
        Matrix res(n);
        for (int i = 0; i < n; i++) {
            for (int k = 0; k < n; k++) {
                if (a[i][k] != 0) {
                    for (int j = 0; j < n; j++) {
                        res.a[i][j] = (res.a[i][j] + a[i][k] * other.a[k][j]) % MOD;
                    }
                }
            }
        }
        return res;
    }

    // Matrix power(int exp) const {
    //     Matrix result = Matrix::identity(n);
    //     Matrix base = *this;

    //     while (exp > 0) {
    //         if (exp & 1) {
    //             result = result * base;
    //         }
    //         base = base * base;
    //         exp >>= 1;
    //     }
    //     return result;
    // }

    int sum() const {
        int total = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                total = (total + a[i][j]) % MOD;
            }
        }
        return total;
    }
    void print() const {
        for (auto& x : a) {
            for (auto& y : x) {
                cout << y << " ";
            }
            cout << '\n';
        }
    }
};

vector<Matrix> precalc;
Matrix power(int exp) {
    Matrix result = Matrix::identity(100);
    int pos = 0;
    while (exp > 0) {
        if (exp & 1) {
            result = result * precalc[pos];
        }
        pos++;
        exp >>= 1;
    }
    return result;
}
signed main() {
    int t;
    cin >> t;
    Matrix base(100), mul(100);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                if (i != 0)
                    base.a[i * 10 + j][j * 10 + k] = gcd(i, j) != gcd(j, k);
                mul.a[i * 10 + j][j * 10 + k] = gcd(i, j) != gcd(j, k);
            }
        }
    }
    precalc.push_back(mul);
    for (int i = 1; (1LL << i) <= 2e9; i++) {
        precalc.push_back(precalc[i - 1] * precalc[i - 1]);
    }
    while (t--) {
        int n;
        cin >> n;
        if (n == 2) {
            cout << 90 << endl;
            continue;
        }
        cout << (base * power(n - 3)).sum() << endl;
    }
}
