// Arup Guha
// 9/11/2012
// Solution to 9/9/2012 UCF Individual Contest Problem: Factorial using powers of 2, 5

import java.util.*;

public class b3 {
	
	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;

		// In this table we'll store the last digit of n! EXCEPT for
		// all factors of 2 and 5.
		for (int i=2; i<ans.length; i++) {
			
			// Divide out factors of 2 and 5, which screw up our answer.
			int save = i;
			while (save%2 == 0) save /= 2;
			while (save%5 == 0) save /= 5;
			
			// Now, we just store the accurate last digit for our adjusted version of
			// n! without any 2s and 5s in its prime representation.
			ans[i] = (ans[i-1]*save)%10;
		}
		
		// Now, we can use ans to reconstruct the real answer.
		int numCases = stdin.nextInt();
		for (int i=0; i<numCases; i++) {
			int n = stdin.nextInt();
			System.out.println(solve(n, ans));
		}
		
	}
	
	// We want to solve the problem given ans and the input value n.
	public static int solve(int n, int[] ans) {
		
		// Figure out how many 2's and 5's are in n!'s prime factorization.
		// Each pair of (2,5) makes a 10 and should "disappear"
		// We need to take the leftover 2's and multiply this into our last digit.
		int twos = numExp(n, 2);
		int fives = numExp(n, 5);
		
		// This is how many leftover twos there are.
		int uniquetwos = twos - fives;
		
		// Here we multiply them in.
		int start = ans[n];
		for (int j=0; j<uniquetwos; j++)
			start = (start*2)%10;
		return start;
	}
	
	// Returns the number of times base divides evenly into n!
	public static int numExp(int n, int base) {
		
		// This is the standard technique used to solve this problem.
		int sum = 0;
		while (n > 0) {
			sum += (n/base);
			n = n/base;
		}
		return sum;
	}
	
}