#include <bits/stdc++.h>
using namespace std;
int t, x, suma, c;
int main() {
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> x;
    suma = 10 * ((x % 10) - 1);
    c = 0;
    while (x) {
      c++;
      suma += c;
      x /= 10;
    }
    if (i != t) {
      cout << suma << endl;
    } else {
      cout << suma;
    }
  }
  return 0;
}
