MOD = 10**9 + 9

# Precompute the maximum required k_max based on constraints analysis
max_k = 10**5  # Sufficient for M up to 1e10

# Initialize dp array
dp = [0] * (max_k + 1)
dp[0] = 1

# Fill dp using dynamic programming
for i in range(1, 10):  # i represents the multiplier for 111111
    for j in range(i, max_k + 1):
        dp[j] = (dp[j] + dp[j - i]) % MOD

# Compute prefix sums
prefix_sum = [0] * (max_k + 1)
current_sum = 0
for k in range(max_k + 1):
    current_sum = (current_sum + dp[k]) % MOD
    prefix_sum[k] = current_sum

# Read input and process each test case
import sys
input = sys.stdin.read().split()
T = int(input[0])
cases = list(map(int, input[1:T+1]))

for M in cases:
    k_max = M // 111111
    if k_max > max_k:
        k_max = max_k
    print(prefix_sum[k_max] % MOD)