require "big" read_line.to_i.times do n = read_line.to_i64 if n == 0 puts 2 next end ans = 0i64 mul = 1i64 m = n while m >= 0 ans += mul mul *= m m -= 1 mul %= 10 if mul == 0 break end end puts ans % 10 end def naive(n) mul = BigInt.new(1) sum = 0i64 n.downto(1) do |i| sum += (mul % 10).to_i mul *= i end sum += (mul % 10).to_i return sum % 10 end