#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int r = 0, c = 0;
    r = n % 10;
    while (n > 0) {
      n = n / 10;
      c++;
    }
    int ans = (r - 1) * 10;
    ans += (c * (c + 1)) / 2;
    cout << ans << '\n';
  }
  return 0;
}
