#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++) #define ALL(x) (x).begin(), (x).end() const double PI = acos(-1); int solve(const string &s) { int ret = 0; vector a; for (char c: s) a.push_back(c - '0'); while (a.size() > 1) { for (int i = 0; i + 1 < a.size(); i++) { a[i] += a[i+1]; if (a[i] >= 10) { a[i] = a[i] / 10 + a[i] % 10; } } a.pop_back(); } return a[0]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T; cin >> T; while (T--) { string s; cin >> s; cout << solve(s) << endl; } return 0; }