#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, x, digit_counter, ans = 0, counter = 0;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> x;
    ans = (x % 10 - 1) * 10;
    digit_counter = 0;
    do {
      digit_counter++;
      ans += digit_counter;
      x /= 10;
    } while (x != 0);
    cout << ans << endl;
  }
  return 0;
}
