#include #include #include #include #include #include #define REP(i,n) for(int i=0;i -1) { str.replace(i, old_s.size(), new_s); } return str; } int count5126(string str, string a) { int i = 0, cnt = 0; if (a == "") { return -1; } while ((i = str.find(a, i)) > -1) { ++cnt; i += a.size(); } return cnt; } vector split5126(string str, string sep){ int s = 0, p = 0; vector v; if (sep == "") { v.push_back(str); return v; } while ((p = str.find(sep, s)) > -1) { v.push_back(str.substr(s, p - s)); s = p + sep.size(); } v.push_back(str.substr(s, str.size())); return v; } string slice5126(string str, int a, int b){ int s = a < 0 ? str.size() + a : a; int e = b < 0 ? str.size() + b : b; e = b == 0 ? str.size() : e; return str.substr(s, (s > e ? s : e) - s); } string solva (string s) { int a; while (s.size() > 1) { for (int i = 0; i < s.size() - 1; ++i) { a = ((int)s[i] - 48) + ((int)s[i + 1] - 48); a = a > 9 ? a % 10 + 1 : a; s[i] = (char)(a + 48); } s = slice5126(s, 0, -1); } return s; } int main() { int n; string s; cin >> n; for (int i = 0; i < n; ++i) { cin >> s; cout << solva(s) << endl; } return 0; }