#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	int t;
	string s;
	vector<string> S;
	cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> s;
		while (s.size() != 1) {
			int temp;
			string ans;
			for (unsigned j = 0; j < s.size() - 1; j++) {
				temp = (int)(s[j]-'0') + (int)(s[j + 1] - '0');
				if (temp >= 10) {
					temp = (int)(to_string(temp)[0] - '0') + (int)(to_string(temp)[1] - '0');
				}
				ans += to_string(temp);
			}
			s = ans;
		}
		S.push_back(s);
	}
	for (unsigned i = 0; i < S.size(); i++) {
		cout << S[i] << endl;
	}
	return 0;
}