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