#include <bits/stdc++.h>
using namespace std;
int fr[1000] = {0};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  fast();
  int t, x;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> x;
    if (x > 1000) {
      cout << (x / 1000) * 10 << "\n";
    } else if (x > 100) {
      cout << (x / 100) * 10 - 4 << "\n";
    } else if (x > 10) {
      cout << (x / 10) * 10 - 7 << "\n";
    } else {
      cout << x * 10 - 9 << "\n";
    }
  }
  return 0;
}
