#include <bits/stdc++.h>
using namespace std;
long long int digit(long long int n) {
  long long int count = 0;
  while (n) {
    count++;
    n /= 10;
  }
  return count;
}
int main() {
  vector<long long int> v;
  for (long long int i = 1; i <= 9; i++) {
    long long int x = i;
    long long int k = i;
    while (x <= 10000) {
      v.push_back(x);
      x = x * 10 + k;
    }
  }
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int ans = 0;
    for (long long int i = 0; i < (long long int)v.size(); i++) {
      if (v[i] == n) {
        ans += digit(v[i]);
        break;
      } else {
        ans += digit(v[i]);
      }
    }
    cout << ans << endl;
  }
}
