#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, j, k, n, m;
    int a[4] = {1, 11, 111, 1111};
    int sum = 0;
    int x;
    cin >> x;
    for (i = 1; i <= 9; i++) {
      for (j = 0; j < 4; j++) {
        if (a[j] * i == x) {
          sum = sum + j + 1;
          i = 101;
          j = 101;
        } else
          sum = sum + j + 1;
      }
    }
    cout << sum << endl;
  }
}
