#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VS; typedef pair PII; typedef long long LL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define MP make_pair #define MT make_tuple #define EACH(i,c) for(auto i: c) #define SORT(c) sort((c).begin(),(c).end()) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while(T--){ string S; cin >> S; while(S.length() > 1){ int n = S.length(); string tmp = ""; REP(i, n - 1){ int t = S[i] - '0' + S[i + 1] - '0'; tmp = tmp + to_string(t / 10 + t % 10); } S = tmp; //cout << S << endl; } cout << S << endl; } return 0; }