// Arup Guha
// 11/26/2013
// Solution to 2013 Pacific Northwest problem H: Holodeck Hacking
import java.util.*;

public class h {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			long input = stdin.nextLong();
			int size = numDigits(input);
			System.out.println(solve(input, size, true) + solve(input, size-1, true));
		}

	}

	// Returns the number of digits in n.
	public static int numDigits(long n) {
		int cnt = 0;
		while (n > 0) {
			cnt++;
			n /= 10;
		}
		return cnt;
	}

	// Returns number of x's of size digits such that x+rev(x) = n.
	public static long solve(long n, int size, boolean flag) {

		// extra is minimum value of starting digit of x.
		int extra = 1;
		if (flag) extra = 0;

		// Base cases - a bit tricky, you just have to think about the recursion whittling down to the last couple digits...
		if (n < 0) return 0;
		if (n == 0 && size >= 0) return 1;
		if (n < 10) {
			if (size == 1 && n%2 == 0) return 1;
			return 0;
		}
		if (n >= 10 && n < 20 && n%2 == 0 && size == 1) return 1;

		// Set up recursion - basically, if the last digit is d0, there are d0+extra ways to fill in the last digit so that
		// the two digits sum to d0 and 10-d0-1 ways so that the sum is d0+10, so try both options.
		int d0 = (int)(n%10L);
		long smallSub = d0*(pow10(size-1)+1);
		long bigSub = (d0+10)*(pow10(size-1)+1);
		long ans = (d0+extra)*solve( (n-smallSub)/10, size-2, false) + (10-d0-1)*solve( (n-bigSub)/10, size-2, false);

		return ans;
	}

	// Returns 10^exp.
	public static long pow10(int exp) {
		long ans = 1;
		for (int i=0; i<exp; i++) {
			ans = ans*10;
		}
		return ans;
	}

}