using System; using System.Collections.Generic; using System.Linq; using System.Numerics; using static System.Math; namespace SortItems { class Program { static void Main(string[] args) { var t = long.Parse(Console.ReadLine()); for (var i = 0; i < t; i++) { var s = Console.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToList(); // 入力値が1桁の場合下記処理は不要 while (s.Count() > 1) { // 数値格納庫 var num = new List(); for (var j = 0; j < s.Count() - 1; j++) { if (s[j] + s[j+1] >= 10) { num.Add((s[j] + s[j + 1]) % 10 + 1); } else { num.Add(s[j] + s[j + 1]); } } s = num; } Console.WriteLine(s.First()); } } } }