import java.util.*;


public class Main {
	public static void main(String args[]) {
	Scanner scanner = new Scanner(System.in);
	int t = scanner.nextInt();
	int[] list = new int[t]; 
	for(int y=0;y<t;y++) {
		list[y]=scanner.nextInt();
	}
	scanner.close();
	for(int i=0;i<t;i++) {
		int n = list[i];
		Set<Integer> set = new HashSet<Integer>();
		
		for(int j=1;j<n+1;j++) {
			
			if(String.valueOf(j).contains(String.valueOf(0))) {
				set.add(0);
			}
			
			else{
			int lastMult=(String.valueOf(j).charAt(0)-'0');
			for(int b=1; b<String.valueOf(j).length(); b++) {
				lastMult=lastMult*(String.valueOf(j).charAt(b)-'0');
			}
			
				set.add(lastMult);
			
		}
			}
		System.out.println(set.size());
	}
	
	}
}