#include #define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i)) #define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i)) using namespace std; template auto make_vectors(X x, T a) { return vector(x, a); } template auto make_vectors(X x, Y y, Z z, Zs... zs) { auto cont = make_vectors(y, z, zs...); return vector(x, cont); } template struct mint { int32_t value; mint() : value() {} mint(int64_t value_) : value(value_ < 0 ? value_ % MOD + MOD : value_ >= MOD ? value_ % MOD : value_) {} inline mint operator + (mint other) const { int32_t c = this->value + other.value; return mint(c >= MOD ? c - MOD : c); } inline mint operator * (mint other) const { int32_t c = (int64_t)this->value * other.value % MOD; return mint(c < 0 ? c + MOD : c); } inline mint & operator += (mint other) { this->value += other.value; if (this->value >= MOD) this->value -= MOD; return *this; } inline mint & operator *= (mint other) { this->value = (int64_t)this->value * other.value % MOD; if (this->value < 0) this->value += MOD; return *this; } }; template using matrix = array, H>; template matrix operator * (matrix const & a, matrix const & b) { matrix c = {}; REP (y, A) REP (z, B) REP (x, C) c[y][x] += a[y][z] * b[z][x]; return c; } template array operator * (matrix const & a, array const & b) { array c = {}; REP (y, H) REP (z, W) c[y] += a[y][z] * b[z]; return c; } template matrix unit_matrix() { matrix a = {}; REP (i, N) a[i][i] = 1; return a; } template matrix powmat(matrix x, int64_t k) { matrix y = unit_matrix(); for (; k; k >>= 1) { if (k & 1) y = y * x; x = x * x; } return y; } constexpr int MOD = 1e9 + 9; constexpr int SIZE = 6; const array VALUE = { 1, 5, 10, 50, 100, 500 }; int main() { // prepare vector, SIZE>, SIZE> > dp(VALUE[SIZE - 1] + 1); REP (l, SIZE) { dp[0][l][l] = 1; } REP (a, dp.size()) REP (m, SIZE) REP3 (r, m, SIZE) { REP (l, m + 1) if (a + VALUE[l] < dp.size()) { dp[a + VALUE[l]][l][r] += dp[a][m][r]; } } matrix, SIZE, SIZE> f = {}; REP (y, SIZE) REP (x, SIZE) { f[y][x] = dp[VALUE[SIZE - 1]][y][x]; } array, SIZE> x = {}; x[SIZE - 1] = 1; auto solve1 = [&](int64_t m) { int64_t a = m / VALUE[SIZE - 1]; int64_t b = m % VALUE[SIZE - 1]; auto y = powmat(f, a) * x; mint answer = 0; REP (l, SIZE) REP (r, SIZE) { answer += dp[b][l][r] * y[r]; } return answer; }; // query int t; cin >> t; while (t --) { int64_t m; cin >> m; cout << solve1(m).value << endl; } return 0; }