#include <bits/stdc++.h>
using namespace std;
signed main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    string s;
    cin >> s;
    cout << 10 * (s[0] - '1') + s.size() * (s.size() + 1) / 2 << "\n";
  }
}
