#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    long long a = 0;
    long long dig = x % 10;
    while (x) {
      x = x / 10;
      a++;
    }
    cout << (10 * (dig - 1)) + (((a * (a + 1)) / 2)) << endl;
  }
}
