#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x, a, dem = 0, s = 0;
    cin >> x;
    a = x % 10;
    while (x != 0) {
      dem++;
      x /= 10;
    }
    if (a != 1) {
      if (dem == 4) {
        cout << a * 10;
      } else {
        a--;
        if (dem == 3)
          cout << (a * 10) + 6;
        else if (dem == 2)
          cout << (a * 10) + 3;
        else
          cout << (a * 10) + 1;
      }
    } else {
      for (int i = 1; i <= dem; i++) s += i;
      cout << s;
    }
    cout << endl;
  }
  return 0;
}
