#include <bits/stdc++.h>
using namespace std;
long long x, n, t, cnt;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> n;
    x = n;
    while (x) {
      cnt += log10(x) + 1;
      x /= 10;
    }
    cout << 10 * (n % 10 - 1) + cnt << endl;
    cnt = 0;
  }
}
