#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int i, j, k, x, m = 0;
    char s[100];
    scanf("%s", s);
    j = strlen(s);
    sscanf(s, "%d", &x);
    x = x % 10;
    for (i = 1; i < x; i++) {
      for (k = 1; k <= 4; k++) m = m + k;
    }
    for (i = 1; i <= j; i++) m = m + i;
    printf("%d\n", m);
  }
  return 0;
}
