class Calc0041 MOD = 10 ** 9 + 9 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @t = args.shift.first.to_i @ms = args.map(&:first).map(&:to_i) end def run ms = @ms.map { |m| m / 111111 } memo = build_memo(ms.max) ms.map { |m| memo[m] } end def build_memo(max) memo = Array.new(max + 1) { |m| m + 1 } (2..9).each do |k| memo2 = Array.new(max + 1) { 0 } (0..max).each do |m| memo2[m] = (memo[m] + (m >= k ? memo2[m - k] : 0)) % MOD end (1..max).each do |m| memo[m] = (memo[m] + (m - k >= 0 ? memo2[m - k] : 0)) % MOD end end memo end end puts Calc0041.new(STDIN.readlines).run if __FILE__ == $0