import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (0 < t--) { char[] tmp = sc.next().toCharArray(); int n = tmp.length; int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = tmp[i] - '0'; } for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { arr[j] = calc(arr[j], arr[j + 1]); } } sb.append(arr[0]).append("\n"); } System.out.print(sb); } static int calc(int x, int y) { int ans = x + y; return ans / 10 + ans % 10; } }