#include <bits/stdc++.h>
using namespace std;
void GivePrimes(vector<int> &series_of_primes) {
  bool IsPrime[1000005];
  memset(IsPrime, true, sizeof(IsPrime));
  for (int p = 2; p * p < 1000005; p++) {
    if (IsPrime[p] == true) {
      for (int i = p * p; i < 1000005; i += p) IsPrime[i] = false;
    }
  }
  for (int q = 2; q < 1000005; q++) {
    if (IsPrime[q]) series_of_primes.push_back(q);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int rem = x % 10;
    int ans = (rem - 1) * 10;
    int len = 0;
    while (x > 0) {
      x = x / 10;
      len++;
    }
    ans += ((len) * (len + 1)) / 2;
    cout << ans << '\n';
    ;
  }
  return 0;
}
