#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const ll MOD = 1e9+9; const int MAXN = 3100; int C[6] = {1, 5, 10, 50, 100, 500}; ll dp[MAXN]; ll pow_mod(ll x, ll p) { if (p == 0) return 1; if (p == 1) return x; if (p%2) return (pow_mod(x, p-1)*x) % MOD; ll tmp = pow_mod(x, p/2); return (tmp*tmp)%MOD; } // mod_inverse ll mod_inverse(ll a, ll m) { return (pow_mod(a, m-2)); } void solve(ll M) { if (M < MAXN) { cout << dp[M] << endl; return; } ll ans = 0; ll q = M%500; ll m = (M/500) % MOD; for (int i = 0; i < 6; i++) { ll tmp = 1; for (int j = 0; j < 6; j++) { if (i == j) continue; (tmp *= m-j) %= MOD; (tmp *= mod_inverse(i-j, MOD)) %= MOD; } (tmp *= dp[i*500+q]) %= MOD; (ans += tmp) %= MOD; } ans = (ans+MOD)%MOD; cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; for (int i = 0; i < MAXN; i++) dp[i] = 1; for (int i = 1; i < 6; i++) { for (int j = C[i]; j < MAXN; j++) (dp[j] += dp[j-C[i]]) %= MOD; } while (T--) { ll M; cin >> M; solve(M); } return 0; }