#include <bits/stdc++.h>
using namespace std;
int countLen(int n) {
  int len = 0;
  while (n > 0) {
    n /= 10;
    len++;
  }
  return len;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int len = countLen(n);
    int first = (n % 10) - 1;
    int arr[] = {1, 3, 6, 10};
    cout << first * 10 + arr[len - 1] << '\n';
  }
}
