import java.io.PrintStream; import java.util.Scanner; public class Y432 { Y432() throws Exception { Scanner in = new Scanner(System.in); PrintStream out = new PrintStream(System.out); int t = in.nextInt(); for (int tt = 0; tt < t; tt++) { char[] s = in.next().toCharArray(); int n = s.length; for (int i=n; i>1; i--) { for (int j=0; j < i - 1; j++) { int g = (int)s[j] - (int)'0' + (int)s[j+1] - (int)'0'; g = g / 10 + g % 10; s[j] = (char)(g + '0'); } } out.println(s[0]); } } public static void main(String argv[]) throws Exception { new Y432(); } }