#include <bits/stdc++.h>
using namespace std;
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    int m, e = 0, f = 0, x = 0, z = 0;
    cin >> m;
    f = m % 10;
    z = (10 * (f - 1));
    while (m > 0) {
      m /= 10;
      x++;
    }
    if (x == 1) {
      cout << z + 1 << endl;
    } else if (x == 2) {
      cout << z + 3 << endl;
    } else if (x == 3) {
      cout << z + 6 << endl;
    } else if (x == 4) {
      cout << z + 10 << endl;
    } else {
      cout << z + 15 << endl;
    }
  }
  return 0;
}
