#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    int divisor = 1;
    int digits;
    int ans = 0;
    for (; divisor <= 9; divisor++) {
      if (x / divisor == 1 && x % divisor == 0) {
        digits = 1;
        break;
      } else if (x / divisor == 11 && x % divisor == 0) {
        digits = 2;
        break;
      } else if (x / divisor == 111 && x % divisor == 0) {
        digits = 3;
        break;
      } else if (x / divisor == 1111 && x % divisor == 0) {
        digits = 4;
        break;
      }
    }
    ans = ans + 10 * (divisor - 1);
    ans = ans + ((digits) * (digits + 1)) / 2;
    cout << ans << endl;
  }
}
