#include <bits/stdc++.h>
using namespace std;
int a[10050];
int main() {
  int t;
  int y;
  for (int i = 1; i <= 9; i++) {
    int x = 0;
    for (int j = 1; j <= 4; j++) {
      x = x * 10 + i;
      a[x] = j;
    }
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &y);
    int ans = 0;
    int flag = 0;
    for (int i = 1; i <= 9; i++) {
      int x = 0;
      for (int j = 1; j <= 4; j++) {
        x = x * 10 + i;
        if (y != x) {
          ans += a[x];
        } else {
          ans += a[y];
          flag = 1;
          break;
        }
      }
      if (flag) {
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
