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