#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int t;
  cin >> t;
  while (t--) {
    string x;
    cin >> x;
    int d = x[0] - '0';
    int l = x.size();
    cout << (d - 1) * 10 + l * (l + 1) / 2 << endl;
  }
  return 0;
}
