#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, m;
  string s;
  while (t--) {
    cin >> s;
    int n = s.length();
    int ans = 0;
    int f = s[0] - '0';
    ans += (f - 1) * 10;
    ans += (n * (n + 1)) / 2;
    cout << ans << "\n";
  }
  return 0;
}
