#include <bits/stdc++.h>
using namespace std;
int countdigits(int n) {
  int i, b = 0;
  while (n) {
    b++;
    n = n / 10;
  }
  return b;
}
int main() {
  int t, i, n, x, cnt = 0;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n;
    cnt = countdigits(n);
    n = n % 10;
    if (cnt == 1) {
      x = (n - 1) * 10 + 1;
    }
    if (cnt == 2) {
      x = (n - 1) * 10 + 3;
    }
    if (cnt == 3) {
      x = (n - 1) * 10 + 6;
    }
    if (cnt == 4) {
      x = (n - 1) * 10 + 10;
    }
    cout << x << endl;
    x = 0;
  }
}
