#include <bits/stdc++.h>
using namespace std;
int T;
int main() {
  cin >> T;
  while (T--) {
    string s;
    cin >> s;
    string temp = "";
    temp += s[0];
    int x = atoi(temp.c_str());
    int ans = 0;
    if (s.size() > 1) {
      ans += (x - 1) * 10;
    } else {
      cout << (x - 1) * 10 + 1 << endl;
      continue;
    }
    int y = atoi(s.c_str());
    if (y >= x) {
      ans += 1;
      if (y >= x * 10 + x) {
        ans += 2;
        int xxx = (x * 10 + x) * 10 + x;
        if (y >= xxx) {
          ans += 3;
          int xxxx = ((x * 10 + x) * 10 + x) * 10 + x;
          if (y >= xxxx) {
            ans += 4;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
