#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int i, n, sum, x, last;
  while (t--) {
    cin >> x;
    last = x % 10;
    sum = 10 * (last - 1);
    if (x == last)
      sum += 1;
    else if (x == 10 * last + last)
      sum += 3;
    else if (x == 100 * last + 10 * last + last)
      sum += 6;
    else
      sum += 10;
    cout << sum << endl;
  }
  return 0;
}
