#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    if (n == 1) {
      cout << 1 << endl;
      continue;
    }
    int dig = n % 10;
    int num = log10(n);
    if (num != log10(n)) num++;
    int ans = 0;
    ans += (dig - 1) * 10;
    ans += (num * (num + 1)) / 2;
    cout << ans << endl;
  }
}
