#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long b[36] = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2,
                       3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4};
    long long 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};
    long long n, ans = 0;
    cin >> n;
    for (long long i = 0; i < 36; i++) {
      if (a[i] == n) {
        cout << ans + b[i] << endl;
        break;
      } else {
        ans = ans + b[i];
      }
    }
  }
}
