#include #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++) #define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0])) typedef long long ll; using namespace std; const ll mod = 1e9+7; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; deque c; ll k; rep(i,t) { cin >> k ; string s = to_string(k); deque b; rep(i,s.size()){ b.push_back(s[i]-'0'); } while(b.size()>1){ deque a; swap(a,b); repi(i,1,a.size()){ a[i-1]+=a[i]; a[i-1]=(a[i-1]/10)+(a[i-1]%10); while(a[i-1]>=10){ a[i-1]=(a[i-1]/10)+(a[i-1]%10); } b.push_back(a[i-1]); } } c.push_back(b[0]); } rep(i,t){ cout << c.front() << endl; c.pop_front(); } return 0; }