#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, l = 0, r = 0, a, b, c0, c1, h, ans = 0, k;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    l = int(s[0]) - 48;
    for (int i = 1; i <= l - 1; i++) ans += 10;
    for (int i = 1; i <= s.size(); i++) ans += i;
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}
