#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string k;
  cin >> n;
  int total;
  for (int i = 0; i < n; i++) {
    cin >> k;
    total = ((k[0] - '0') - 1) * 10;
    int length = k.length();
    while (length != 0) {
      total += length;
      length--;
    }
    cout << total << endl;
  }
  return 0;
}
