#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, c, m;
  string s;
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> s;
    if (s.size() < 4) {
      c = s[0] - '0';
      m = (c - 1) * 4;
      if (s.size() == 1) {
        cout << (m / 4 * 10) + 1 << endl;
      } else if (s.size() == 2) {
        cout << (m / 4 * 10) + 3 << endl;
      } else {
        cout << (m / 4 * 10) + 6 << endl;
      }
    } else {
      c = s[0] - '0';
      cout << c * 10 << endl;
    }
  }
  return 0;
}
