#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, a, b;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> x;
    a = x % 10;
    b = x / a;
    cout << (10 * (a - 1) + (b >= 1) + 2 * (b >= 11) + 3 * (b >= 111) +
             4 * (b >= 1111))
         << endl;
  }
}
