#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int mod = 1e9 + 7;
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0)
    if (b & 1) {
      res = (long long)(res * 1ll * a);
      --b;
    } else {
      a = (long long)(a * 1ll * a);
      b >>= 1;
    }
  return (long long)res;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  vector<string> v;
  for (int i = 1; i <= 9; i++) {
    string s = "";
    for (int j = 1; j < 5; j++) {
      s += to_string(i);
      v.push_back(s);
    }
  }
  while (q--) {
    int x;
    cin >> x;
    int s = 0;
    for (int i = 0; i < v.size(); i++) {
      if (x == atoi(v[i].c_str())) {
        s += v[i].size();
        cout << s << endl;
        s = 0;
        break;
      } else {
        s += v[i].size();
      }
    }
  }
  return 0;
}
