#include <bits/stdc++.h>
using namespace std;
int t, sums[4] = {1, 3, 6, 10};
string x;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> x;
    int len = x.length();
    if (x[0] == '1') {
      cout << sums[len - 1] << endl;
    } else {
      int temp = (x[0] - '0') - 1;
      cout << sums[3] * temp + sums[len - 1] << endl;
    }
  }
  return 0;
}
