#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, m;
  cin >> n;
  long long int ans = ((n % 10) - 1) * 10;
  m = 1;
  while (n > 0) {
    ans += (m);
    m++;
    n /= 10;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
