#include <bits/stdc++.h>
using namespace std;
int cycles;
vector<vector<int> > g;
vector<int> vis;
void dfs(int u) {
  vis[u] = 1;
  for (auto v : g[u]) {
    if (vis[v]) {
      if (vis[v] == 1) cycles++;
      continue;
    }
    dfs(v);
  }
  vis[u] = 2;
}
long long gcd(long long a, long long b) {
  long long x = max(a, b);
  long long y = min(a, b);
  if (y == 0) return x;
  if (x % y == 0) return y;
  return gcd(y, x % y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    cin >> s;
    int l = s.length();
    int d = s[0] - '0';
    int ans = (d - 1) * (4 + 3 + 2 + 1);
    for (int i = 1; i <= l; i++) ans += i;
    cout << ans << "\n";
  }
}
