#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
string S[10000];
string T;

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> S[i];
  cin >> T;
  int b = 0, free = 0;
  rep(i, N) {
    string z = "", a = "";
    for (char c : S[i]) {
      if (c == '?') z += 'z';
      else z += c;
    }
    for (char c : S[i]) {
      if (c == '?') a += 'a';
      else a += c;
    }
    if (T >= a) {
      if (T <= z) free++;
      else b++;
    }
  }
  for (int i=b; i<=b+free; i++) {
    cout << i+1;
    if (i < b+free) cout << " ";
  }
  cout << "\n";
  return 0;
}
