#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  cin >> t;
  int ar[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 br[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};
  while (t--) {
    int n;
    cin >> n;
    int y;
    for (int i = 0; i < 36; i++) {
      if (ar[i] == n) {
        y = i;
        break;
      }
    }
    int s = 0;
    for (int i = 0; i <= y; i++) {
      s = s + br[i];
    }
    cout << s << endl;
  }
}
