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