#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, num = 0, dig;
  cin >> n;
  dig = n % 10;
  while (n != 0) {
    n /= 10;
    num++;
  }
  int sum = 0;
  for (int i = 1; i <= num; i++) {
    sum += i;
  }
  cout << (dig - 1) * 10 + sum << "\n";
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
