#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, tmp = 0, num = 0, l = 0;
    cin >> n;
    tmp = n % 10;
    while (n > 0) {
      num++;
      l += num;
      n /= 10;
    }
    cout << l + (tmp - 1) * 10 << '\n';
  }
}
