// Arup Guha
// 9/11/2012
// Solution to 9/9/2012 UCF Individual Contest Problem: Factorial

import java.util.*;

public class b {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		
		// Just seed our table with the first couple factorials.
		int[] ans = new int[1001];
		ans[0] = 1;
		ans[1] = 1;
		
		// All that matters to calculate the last digit of n! is the last digit in (n-1)!
		// So that's all we store in our table...
		for (int i=2; i<ans.length; i++) {
			
			// The value that matters.
			int value = ans[i-1]*i;
			
			// Strip off all 0s.
			while (value%10 == 0)
				value = value/10;
				
			// This is as much as we need to save.
			ans[i] = value%1000000;
		}
		
		// Now, we can output these.
		int numCases = stdin.nextInt();
		for (int i=0; i<numCases; i++) {
			int n = stdin.nextInt();
			System.out.println(ans[n]%10);
		}
		
	}
	
}