#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int dig = n % 10;
    int sz = 0, tmp = n;
    while (tmp) {
      tmp /= 10;
      sz++;
    }
    cout << (dig - 1) * 10 + sz * (sz + 1) / 2 << endl;
  }
  return 0;
}
