import java.util.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { int n = sc.nextInt(); for (int i = 0;i < n;i++) { solve(sc.next()); } } public static void solve(String s) { while (s.length() != 1) { StringBuilder sb = new StringBuilder(); for (int i = 0;i < s.length()-1;i++) { int sum = Integer.valueOf(s.substring(i, i+1)) + Integer.valueOf(s.substring(i+1, i+2)); if (sum >= 10) sum -= 9; sb.append(sum); } s = sb.toString(); } System.out.println(s); } }