#include "stdio.h" int t; char letter[100002]; int num[100000]; int ans[100000]; int dis; int main() { scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%s", letter); for (int i = 0;i<100002; i++) { if (letter[i] == NULL) { dis = i; break; } num[i] = letter[i] - '0'; } while (dis > 1) { for (int j = 0; j < dis-1; j++) { num[j] = num[j] + num[j + 1]; if (num[j] > 9)num[j] -= 9; } dis--; } ans[i] = num[0]; } for (int i = 0; i < t; i++) { printf("%d\n", ans[i]); } }