#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, n, temp, c;
  cin >> t;
  while (t--) {
    cin >> n;
    temp = n;
    c = 0;
    while (temp) {
      c++;
      temp = temp / 10;
    }
    n = n % 10;
    cout << (c * (c + 1) / 2) + (n - 1) * 10 << endl;
  }
  return 0;
}
