#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 1000 * 101;
const long long MOD = 1000000007;
long long max(long long a, long long b) {
  if (b <= a)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (b <= a)
    return b;
  else
    return a;
}
long long fact(long long a) {
  long long f = 1;
  for (long long i = 1; i <= a; i++) f = (f * i);
  return f;
}
void FASTIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  int x;
  cin >> x;
  int total = 0;
  for (int i = 1; i <= 9; i++) {
    int sum = 0;
    for (int j = 1; j <= 4; j++) {
      sum = sum * 10 + i;
      total += j;
      if (sum == x) {
        cout << total << "\n";
      }
    }
  }
}
int main() {
  FASTIO();
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
