#include <bits/stdc++.h>
using namespace std;
void solve() {
  string str;
  cin >> str;
  long long len = str.size();
  long long k = (str[0] - '0' - 1) * 10 + len * (len + 1) / 2;
  cout << k << endl;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test, tc = 0;
  cin >> test;
  while (test--) {
    solve();
  }
}
