#include <bits/stdc++.h>
using namespace std;
void solve(int test) {
  int x;
  cin >> x;
  int no = x % 10;
  int cnt = 0;
  while (x) {
    cnt++;
    x /= 10;
  }
  int ans = (no - 1) * 10;
  while (cnt) {
    ans += cnt;
    cnt--;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(20);
  long long int t = 1, k;
  cin >> t;
  k = t;
  while (t--) {
    solve(k - t);
  }
  cerr << "Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n";
  return 0;
}
