#include <bits/stdc++.h>
using namespace std;
void test_case() {
  int n;
  scanf("%d", &n);
  int full = (n % 10) - 1;
  int num = 0;
  while (n) {
    ++num;
    n /= 10;
  }
  printf("%d\n", full * 10 + (num * (num + 1)) / 2);
}
int main(void) {
  int T;
  scanf("%d", &T);
  while (T--) test_case();
  return 0;
}
