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