import java.util.*; public class Exercise156 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int number = sc.nextInt(); for(int i = 0; i < number; i++){ System.out.println(calc(sc.nextLong())); } } public static String calc(Long num){ String numStr = String.valueOf(num); while(Long.parseLong(numStr) > 9){ char[] numArray = new char[numStr.length()]; for(int i = 0; i < numStr.length(); i++){ numArray[i] = numStr.charAt(i); } String str = ""; for(int i = 0; i < numStr.length() - 1; i++){ int x = Character.getNumericValue(numArray[i]) + Character.getNumericValue(numArray[i + 1]); if(x > 9){ x = x - 10 + 1; } str = str + String.valueOf(x); } numStr = str; } return numStr; } }