using System.Text; using System.Collections.Generic; using System.Linq; using System; public class Hello { public static void Main() { var sb = new StringBuilder(); var n = int.Parse(Console.ReadLine().Trim()); for (int i = 0; i < n; i++) sb.Append(getAns(Console.ReadLine().Trim())); Console.Write(sb); } public static string getAns(string s) { var sL = s.Length; var a = new List(); var b = new List(); for (int i = 0; i < sL; i++) a.Add(int.Parse(s[i].ToString())); while (a.Count() > 1) { b.Clear(); for (int j = 0; j < a.Count() - 1; j++) { var w = a[j] + a[j + 1]; if (w >= 10) w -= 9; b.Add(w); } a.Clear(); foreach (var x in b) a.Add(x); } return string.Format("{0}\n", a[0]); } }