#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int MOD = 1000000007;
double eps = 1e-9;
long double PI = ((long double)22 / (long double)7);
vector<long long int> v;
long long int dfs(int t, int a, int b) {
  long long int ans = 0;
  if (t == -1) return 1;
  if (a == 0) {
    long long int var1 = v[t] + 1;
    long long int var2 = 9 - v[t];
    ans += var1 * (dfs(t - 1, b, 0));
    if (var2 != 0 && t > 1) ans += var2 * (dfs(t - 1, b, 1));
  } else {
    long long int var1 = v[t];
    long long int var2 = 10 - v[t];
    if (t > 1) ans += var2 * (dfs(t - 1, b, 1));
    if (var1 != 0) ans += var1 * (dfs(t - 1, b, 0));
  }
  return ans;
}
void solve() {
  long long int n;
  cin >> n;
  long long int var = n;
  while (var > 0) {
    v.push_back(var % 10);
    var /= 10;
  }
  reverse((v).begin(), (v).end());
  cout << dfs(((long long int)(v).size()) - 1, 0, 0) - 2 << "\n";
  v.clear();
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
