T = gets.to_i factorial = [1] (1 .. 10).each do |i| factorial << factorial[-1] * i end T.times do n = gets.to_i ans = 0 if n >= 5 i = n f = 1 while i > 0 f *= i break if f % 10 == 0 i -= 1 ans += f end else ans = (0 .. n).sum { |i| factorial[n] / factorial[i] } end puts ans % 10 end