#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long rem = n % 10;
    long long cnt = 0;
    while (n > 0) {
      n /= 10;
      cnt++;
    }
    long long ans = (rem - 1) * 10;
    if (cnt == 1) {
      ans += 1;
    } else if (cnt == 2) {
      ans += 3;
    } else if (cnt == 3) {
      ans += 6;
    } else {
      ans += 10;
    }
    cout << ans << endl;
  }
}
