#include <bits/stdc++.h>
using namespace std;
long long nod(long long n) {
  long long count = 0;
  while (n) {
    count++;
    n /= 10;
  }
  return count;
}
signed main() {
  long long t, n, ans;
  cin >> t;
  while (t--) {
    cin >> n;
    long long k = nod(n);
    ans = 10 * ((n % 10) - 1) + k * (k + 1) / 2;
    cout << ans << endl;
  }
  return 0;
}
