#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t > 0) {
    int x, digits = 0, num = 0, total = 0;
    scanf("%d", &x);
    num = x % 10;
    while (x >= 1) {
      digits++;
      x = x / 10;
    }
    while (digits > 0) {
      total = total + digits;
      digits--;
    }
    total = (num - 1) * 10 + total;
    printf("%d\n", total);
    t--;
  }
  return 0;
}
