#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void coder_RB6() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  coder_RB6();
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int x = n % 10;
    long long int y = 0;
    y = (x - 1) * 10;
    long long int cnt = 0;
    while (n != 0) {
      n = n / 10;
      cnt++;
    }
    for (long long int i = 1; i <= cnt; i++) {
      y = y + i;
    }
    cout << y << endl;
  }
}
