#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int num = n;
    int noofdigit = 0;
    while (num != 0) {
      num = num / 10;
      noofdigit++;
    }
    int digit = n % 10;
    int ans = (digit - 1) * 10;
    int i = 1;
    while (i <= noofdigit) {
      ans = ans + i;
      i++;
    }
    cout << ans << endl;
  }
}
