#include <bits/stdc++.h>
using namespace std;
map<string, long long int> Mp;
void read_and_solve() {
  long long int k = 9, i, j;
  vector<long long int> v;
  while (k--) {
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
  }
  long long int sum = 0;
  for (i = 0; i < v.size(); i++) {
    sum += v[i];
    v[i] = sum;
  }
  long long int cnt = 0;
  for (i = 1; i <= 9; i++) {
    for (j = 1; j <= 4; j++) {
      long long int k = j;
      string s = "";
      cnt++;
      while (k--) {
        char ch = i + 48;
        s += ch;
      }
      Mp[s] = v[cnt - 1];
    }
  }
  long long int t = ({
    long long int a;
    scanf("%lld", &a);
    a;
  });
  while (t--) {
    string st = ({
      string st;
      cin >> st;
      st;
    });
    cout << Mp[st] << endl;
  }
}
int main() {
  read_and_solve();
  return 0;
}
