#include <bits/stdc++.h>
using namespace std;
int main() {
  int test_cases;
  cin >> test_cases;
  for (int i = 0; i < test_cases; i++) {
    int x;
    cin >> x;
    string s = to_string(x);
    int size = s.size();
    int first_digit = s[0] - '0';
    cout << (first_digit - 1) * 10 + (size * (size + 1) / 2) << endl;
  }
}
