#include <bits/stdc++.h>
using namespace std;
int ans[9];
int main() {
  int t;
  cin >> t;
  while (t--) {
    string num;
    cin >> num;
    int numMinusOne = num[0] - '0' - 1;
    int ans = numMinusOne * 10;
    int sz = num.size();
    sz = (sz * (sz + 1)) / 2;
    cout << ans + sz << endl;
  }
}
