import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i = 0; i < t; i++) { String s = sc.next(); while(s.length() > 1) { String q = ""; for(int j = 0; j < s.length() - 1; j++) { int a = Integer.parseInt(String.valueOf(s.charAt(j))); int b = Integer.parseInt(String.valueOf(s.charAt(j + 1))); int c = a + b; if(c > 9) c = (c % 10) + 1; q += c; } s = q; } int ans = Integer.parseInt(String.valueOf(s.charAt(0))); System.out.println(ans); } } }