#include using namespace std; int ctoi(char c) { return c - '0'; } string itos(int i) { ostringstream s; s << i; return s.str(); } int main() { int n; cin >> n; while (n--) { string s; cin >> s; if (s.length() == 1) { cout << s << endl; } else { string t = ""; while (s.length() > 1) { for (int i = 0; i < s.length()-1; ++i) { int tmp = ctoi(s[i])+ctoi(s[i+1]); if (tmp >= 10) { t += itos(ctoi(itos(tmp)[0])+ctoi(itos(tmp)[1])); } else { t += itos(tmp); } } s = t; t = ""; } cout << s << endl; } } return 0; }