#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  while (n--) {
    int k;
    cin >> k;
    int f = k % 10;
    int count = 0;
    while (k > 0) {
      k = k / 10;
      count++;
    }
    if (count == 1) {
      cout << ((f * 10) - 10) + 1 << endl;
    } else if (count == 2) {
      cout << ((f * 10) - 10) + 3 << endl;
    }
    if (count == 3) {
      cout << ((f * 10) - 10) + 6 << endl;
    }
    if (count == 4) {
      cout << ((f * 10) - 10) + 10 << endl;
    }
  }
}
