using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { int T = int.Parse(Console.ReadLine()); for(int i = 0; i < T; i++) { Console.WriteLine(ans(Console.ReadLine())); } } static int ans(string s) { List A = new List(), B; B = s.Select(q => int.Parse(q.ToString())).ToList(); while (B.Count>1) { for(int i = 0; i < B.Count - 1; i++) { int q = B[i] + B[i + 1]; q = q % 10 + q / 10; A.Add(q); } B = A.ToList(); A.Clear(); } return B[0]; } }