read_line.to_i.times do n = read_line.to_i64 if n == 0 puts 0 next end ans = 0i64 mul = 1i64 {n + 1, 5}.min.times do |i| ans += mul mul *= n - i mul %= 10 end puts ans % 10 end