#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int count = 0;
    int sum = 0;
    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 index = 0;
    while (a[index] != n) {
      count++;
      sum = count + sum;
      if (count == 4) {
        count = 0;
      }
      index++;
    }
    cout << sum + count + 1 << endl;
  }
}
