#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int arr[t];
  for (int i = 0; i < t; i++) cin >> arr[i];
  for (int i = 0; i < t; i++) {
    if (arr[i] == 1) cout << 1 << endl;
    if (arr[i] == 11) cout << 3 << endl;
    if (arr[i] == 111) cout << 6 << endl;
    if (arr[i] == 1111) cout << 10 << endl;
    if (arr[i] == 2) cout << 11 << endl;
    if (arr[i] == 22) cout << 13 << endl;
    if (arr[i] == 222) cout << 16 << endl;
    if (arr[i] == 2222) cout << 20 << endl;
    if (arr[i] == 3) cout << 21 << endl;
    if (arr[i] == 33) cout << 23 << endl;
    if (arr[i] == 333) cout << 26 << endl;
    if (arr[i] == 3333) cout << 30 << endl;
    if (arr[i] == 4) cout << 31 << endl;
    if (arr[i] == 44) cout << 33 << endl;
    if (arr[i] == 444) cout << 36 << endl;
    if (arr[i] == 4444) cout << 40 << endl;
    if (arr[i] == 5) cout << 41 << endl;
    if (arr[i] == 55) cout << 43 << endl;
    if (arr[i] == 555) cout << 46 << endl;
    if (arr[i] == 5555) cout << 50 << endl;
    if (arr[i] == 6) cout << 51 << endl;
    if (arr[i] == 66) cout << 53 << endl;
    if (arr[i] == 666) cout << 56 << endl;
    if (arr[i] == 6666) cout << 60 << endl;
    if (arr[i] == 7) cout << 61 << endl;
    if (arr[i] == 77) cout << 63 << endl;
    if (arr[i] == 777) cout << 66 << endl;
    if (arr[i] == 7777) cout << 70 << endl;
    if (arr[i] == 8) cout << 71 << endl;
    if (arr[i] == 88) cout << 73 << endl;
    if (arr[i] == 888) cout << 76 << endl;
    if (arr[i] == 8888) cout << 80 << endl;
    if (arr[i] == 9) cout << 81 << endl;
    if (arr[i] == 99) cout << 83 << endl;
    if (arr[i] == 999) cout << 86 << endl;
    if (arr[i] == 9999) cout << 90 << endl;
  }
}
