#include #include using namespace std; int main() { int i, j, n, l, a[1000]; string s; cin >> n; for (j = 0; j < n; j++) { cin >> s; l = s.length(); for (i = 0; i < l; i++) { a[i] = (s[i]) - 48; } while (l != 1) { for (i = 0; i < l - 1; i++) { a[i] += a[i + 1]; if (a[i] > 9) { a[i] -= 9; } } l -= 1; } cout << a[0] << endl; } return 0; }