#include <bits/stdc++.h>
using namespace std;
const long long int mx = 1e6 + 10, inf = 1e9 + 10;
int t, x, y;
string s;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> s;
    y = (int(s[0] - '0') - 1) * (10);
    x = (s.size() * (s.size() + 1)) / 2;
    cout << x + y << endl;
  }
  return 0;
}
