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