import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { sb.append(calc(br.readLine())).append("\n"); } System.out.print(sb); } static int calc(String s) { char[] arr = s.toCharArray(); int n = arr.length; int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = arr[i] - '0'; } for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { nums[j] = cInt(nums[j], nums[j + 1]); } } return nums[0]; } static int cInt(int x, int y) { int ans = x + y; return ans % 10 + ans / 10; } }