#include <bits/stdc++.h>
using namespace std;
int a[10000];
int main() {
  a[1] = 1;
  a[11] = 3;
  a[111] = 6;
  a[1111] = 10;
  a[2] = 11;
  a[22] = 13;
  a[222] = 16;
  a[2222] = 20;
  a[3] = 21;
  a[33] = 23;
  a[333] = 26;
  a[3333] = 30;
  a[4] = 31;
  a[44] = 33;
  a[444] = 36;
  a[4444] = 40;
  a[5] = 41;
  a[55] = 43;
  a[555] = 46;
  a[5555] = 50;
  a[6] = 51;
  a[66] = 53;
  a[666] = 56;
  a[6666] = 60;
  a[7] = 61;
  a[77] = 63;
  a[777] = 66;
  a[7777] = 70;
  a[8] = 71;
  a[88] = 73;
  a[888] = 76;
  a[8888] = 80;
  a[9] = 81;
  a[99] = 83;
  a[999] = 86;
  a[9999] = 90;
  int n;
  scanf("%d", &n);
  while (n--) {
    int b;
    scanf("%d", &b);
    printf("%d\n", a[b]);
  }
}
