#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  for (int i = 0; i < x; i++) {
    int a, w;
    cin >> a;
    w = a % 10;
    int n = w - 1, e = 0, z = 0;
    n *= 10;
    while (a != 0) {
      a /= 10;
      e++;
    }
    for (int r = 1; r <= e; r++) {
      z += r;
    }
    cout << z + n << "\n";
  }
}
