#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
void solve() {
  long long int n;
  cin >> n;
  long long int dig = 0, x;
  while (n > 0) {
    x = n % 10;
    dig++;
    n /= 10;
  }
  long long int ans = (x - 1) * (10);
  if (dig == 1)
    ans += 1;
  else if (dig == 2)
    ans += 3;
  else if (dig == 3)
    ans += 6;
  else
    ans += 10;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
