#include #include using namespace std; int main() { int t; cin >> t; string s; while(t-- > 0){ cin >> s; while(s.length() > 1){ string next = ""; for(int i = 0; i < s.length() - 1; i++){ int tmp = (s[i] - '0') + (s[i+1] - '0'); if(tmp >= 10) tmp -= 9; next += to_string(tmp); } s = next; } cout << s << endl; } return 0; }