#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    if (n == 1)
      cout << n << endl;
    else {
      int m = (n % 10) - 1;
      int p = ceil(log10(n));
      cout << (m * 10) + ((p * (p + 1)) / 2) << '\n';
    }
  }
  return 0;
}
