#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  long long a[t];
  for (long long i = 0; i < t; i++) cin >> a[i];
  for (long long i = 0; i < t; i++) {
    long long y;
    long long sum = 0;
    long long count = 0;
    y = a[i] % 10;
    sum = 10 * (y - 1);
    while (a[i] != 0) {
      a[i] = a[i] / 10;
      count++;
    }
    for (long long i = 0; i < count; i++) sum = sum + (i + 1);
    cout << sum << "\n";
  }
}
