#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int now = 0;
    int qtd = 0;
    int num = 1, answer = 0;
    while (now != x) {
      if (now * 10 + num > 10000) {
        now = 0;
        num++;
        qtd = 0;
      }
      now = now * 10 + num;
      qtd++;
      answer += qtd;
    }
    cout << answer << '\n';
  }
  return 0;
}
