#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    string x;
    cin >> x;
    int n = (1 + x.length()) * x.length() * 0.5;
    cout << n + (x[0] - '1') * 10 << endl;
  }
}
