#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, d, n, c = 0;
  cin >> t;
  while (t--) {
    cin >> a;
    c = 0;
    d = a % 10;
    while (a > 0) {
      a = a / 10;
      c++;
    }
    n = (10 * (d - 1));
    for (int i = 1; i <= c; i++) n = n + i;
    cout << n << endl;
  }
  return 0;
}
