#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int i, j = 0, c, k = 0, m, n;
    bool s = true;
    cin >> n;
    m = (n % 10) - 1;
    if (m >= 1) {
      k = m * 10;
      while (n > 0) {
        j++;
        n /= 10;
      }
      if (j == 4)
        k += 10;
      else if (j == 3)
        k += 6;
      else if (j == 2)
        k += 3;
      else if (j == 1)
        k += 1;
    } else if (m == 0) {
      while (n > 0) {
        j++;
        n /= 10;
      }
      if (j == 4)
        k += 10;
      else if (j == 3)
        k += 6;
      else if (j == 2)
        k += 3;
      else if (j == 1)
        k += 1;
    }
    cout << k << endl;
  }
  return 0;
}
