#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 3e5, M = N;
mt19937_64 rang(
    chrono::high_resolution_clock::now().time_since_epoch().count());
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
vector<int> g[N];
void solve() {
  string s;
  cin >> s;
  int len = s.length();
  int n = s[0] - '0';
  int ans = 10 * (n - 1) + len * (len + 1) / 2;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(chrono::high_resolution_clock::now().time_since_epoch().count());
  clock_t z = clock();
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  fprintf(stderr, "Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC),
      fflush(stderr);
  return 0;
}
