#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int i = n % 10;
    int dig = 0;
    while (n != 0) {
      dig++;
      n = n / 10;
    }
    int ans = (1 + 2 + 3 + 4) * (i - 1);
    while (dig != 0) {
      ans += dig;
      dig--;
    }
    cout << ans << "\n";
  }
}
