#include <bits/stdc++.h>
using namespace std;
void solve() {
  string s;
  cin >> s;
  long long r = (s[0] - '0') % 10;
  long long ans = (r - 1) * 10;
  ans += ((s.size() + 1) * (s.size())) / 2;
  cout << ans << '\n';
}
signed main() {
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
