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