#include //const static double de_PI = 3.14159265358979323846; //const static int de_MOD = 1000000007; //const static int de_MAX = 999999999; //const static int de_MIN = -999999999; int main(void) { //std::ifstream in("123.txt"); std::cin.rdbuf(in.rdbuf()); int T = 0; std::cin >> T; std::vector ans(T); for (int i = 0; i < T; i++) { std::string S; std::cin >> S; std::vector A(S.length()); for (unsigned int j = 0; j < S.length(); j++) { A[j] = S[j] - '0'; } while (A.size() > 1) { std::vector nextA(A.size() - 1); for (unsigned int j = 0; j < A.size() - 1; j++) { nextA[j] = (A[j] + A[j + 1]) % 10 + (A[j] + A[j + 1]) / 10; } A.clear(); A = nextA; } ans[i] = A[0]; } for (int i = 0; i < T; i++) { std::cout << ans[i] << std::endl; } }