#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int no = x % 10;
    int count = (no - 1) * 10;
    int temp = 0;
    while (x > 0) {
      x = x / 10;
      temp++;
    }
    int t = temp;
    while (t > 0) {
      t--;
      temp += t;
    }
    count = count + temp;
    cout << count << endl;
  }
  return 0;
}
