#include <bits/stdc++.h>
using namespace std;
void read(int &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
void read(long long &sum) {
  sum = 0;
  char c = getchar();
  bool f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  if (f) sum = -sum;
}
void readarr(long long a[], long long n) {
  for (int i = 0; i < n; i++) read(a[i]);
}
void readarr(int a[], int n) {
  for (int i = 0; i < n; i++) read(a[i]);
}
void aout(long long a[], long long n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}
void aout(int a[], int n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
}
const int MAXN = (int)1e6 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (int64_t)1e18;
const long double PI = 3.1415926535897932384626433832795;
const int N = 1e7 + 4;
const int M = 1e7 + 4;
const int mod = 2;
vector<int> v;
void solve() {
  int n;
  read(n);
  int ans = 0;
  for (int i = 0; i < v.size(); i++) {
    int j = v[i];
    while (j) {
      ans++;
      j /= 10;
    }
    if (v[i] == n) {
      break;
    }
  }
  cout << ans << "\n";
}
int main() {
  int t;
  read(t);
  int val = 1, i = 1;
  while (true) {
    val = i;
    while (true) {
      if (val > 10000) {
        break;
      }
      v.push_back(val);
      val *= 10;
      val += i;
    }
    if (i == 9) {
      break;
    }
    i++;
  }
  for (int tt = 1; tt <= t; tt++) {
    solve();
  }
}
