#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  int solutions[40];
  cin >> t;
  for (int i = 0; i < t; ++i) {
    int x;
    cin >> x;
    int num_bef;
    string a = std::to_string(x);
    int q = ((a[0] - '0') - 1) * 10;
    if (a.size() == 1) {
      q += 1;
    }
    if (a.size() == 2) {
      q += 3;
    }
    if (a.size() == 3) {
      q += 6;
    }
    if (a.size() == 4) {
      q += 10;
    }
    solutions[i] = q;
  }
  for (int j = 0; j < t; ++j) {
    cout << solutions[j] << endl;
  }
}
