import java.util.Scanner; public class No432 { 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(); String s[] = S.split(""); int Si[] = new int[s.length]; for(int j = 0;j < s.length;j++) { Si[j] = Integer.parseInt(s[j]); } for(int j = s.length - 1;j > 0;j--) { for(int k = 0;k < j;k++) { if(Si[k] + Si[k+1] >= 10) { Si[k] = Si[k] + Si[k+1] - 9; }else { Si[k] = Si[k] + Si[k+1]; } } } System.out.println(Si[0]); } } }