#include <bits/stdc++.h>
using namespace std;
int add(int l) {
  if (l == 1) return 1;
  if (l == 2) return 3;
  if (l == 3) return 6;
  if (l == 0) return 0;
}
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    long int p;
    cin >> p;
    long int a[36] = {1, 11, 111, 1111, 2, 22, 222, 2222, 3, 33, 333, 3333,
                      4, 44, 444, 4444, 5, 55, 555, 5555, 6, 66, 666, 6666,
                      7, 77, 777, 7777, 8, 88, 888, 8888, 9, 99, 999, 9999};
    int x;
    for (int i{0}; i < 36; i++) {
      if (p == a[i]) {
        x = i + 1;
      }
    }
    int div = x / 4;
    int rem = x % 4;
    cout << (div * 10) + add(rem) << '\n';
    t--;
  }
}
