#include <bits/stdc++.h>
using namespace std;
long long int tolong(const string &s) {
  stringstream ss;
  ss << s;
  long long int x;
  ss >> x;
  return x;
}
long long int power(long long int x, long long int y,
                    long long int p = 1000000007) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
void solve() {
  int x;
  cin >> x;
  vector<int> v = {1, 11, 111, 1111};
  vector<int> d = {1, 2, 3, 4};
  int count = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 0; j < d.size(); j++) {
      count += d[j];
      if (i * v[j] == x) {
        cout << count << '\n';
        return;
      }
    }
  }
  cout << count << '\n';
}
