#include <bits/stdc++.h>
using namespace std;
using namespace std;
const unsigned int M = 1000000007;
int power(long long x, long long p, long long m) {
  if (p == 0) {
    return 1;
  }
  long long res = power(x, p / 2, m);
  if (p % 2 != 0) {
    return (res % m * res % m * x % m) % m;
  } else {
    return (res % m * res % m) % m;
  }
}
int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return (b, a % b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  cin >> t;
  while (t--) {
    int n, m = 0, k = 0;
    cin >> n;
    if (n < 10) {
      k = 1;
      m = n;
    } else {
      while (n != 0) {
        n /= 10;
        ++k;
        if (n < 10 && n != 0) {
          m = n;
        }
      }
    }
    int sum = 0;
    for (int i = 1; i <= m - 1; ++i) {
      for (int j = 1; j <= 4; ++j) {
        sum += j;
      }
    }
    for (int i = 1; i <= k; ++i) {
      sum += i;
    }
    cout << sum << endl;
  }
}
