#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector vi; typedef vector vvi; typedef vector vs; typedef pair pii; typedef long long ll; #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i,n) FOR(i,0,(n)-1) const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 10; int calc(int a, int b) { int res = a + b; if (res > 9) { return (res / 10) + (res % 10); } else { return res; } } int main() { int n; cin >> n; REP(i, n) { string s; cin >> s; int ans = 0, size = s.size(); vi a(size); REP(i, size) { a[i] = s[i] - '0'; } for (int i = size - 1; i > 0; i--) { REP(j, i) { a[j] = calc(a[j], a[j + 1]); } } cout << a[0] << endl; } return 0; }