class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int[] ansList = Enumerable.Repeat(-1, n).ToArray(); for (int i = 0; i < n; i++) { string str = Console.ReadLine(); if (str.Length > 2) { List list = new List(); for (int j = 0; j < str.Length; j++) { list.Add(int.Parse(str[j].ToString())); } ansList[i] = RecursionNumber(list, ansList[i]); } else { ansList[i] = int.Parse(str)/10 + int.Parse(str) % 10; } } for(int i = 0; i < n; i++) { Console.WriteLine(ansList[i]); } } private static int RecursionNumber(List list,int ans) { List newList = new List(); for (int i = 1; i < list.Count; i++) { int num = list[i - 1] + list[i]; if(num >= 10) { num = (num / 10) + (num % 10); } newList.Add(num); } if (newList.Count > 2) { ans = RecursionNumber(newList, ans); } else { ans = newList[0] + newList[1]; if (ans >= 10) { ans = (ans / 10) + (ans % 10); } } return ans; } }