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