#include <bits/stdc++.h>
using namespace std;
long long md = 1000000007;
long long bexp(long long a, long long b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  long long r = bexp(a, b / 2);
  r = r * r;
  if (b % 2 == 0)
    return r;
  else
    return r * a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test_case = 1;
  cin >> test_case;
  while (test_case--) {
    long long n, i, j, m, k;
    string s;
    cin >> s;
    long long p = s.length();
    long long l = s[0] - '0';
    long long ans = (l - 1) * 10 + (p * (p + 1)) / 2;
    cout << ans << "\n";
  }
  return 0;
}
