#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

bool comp_a(const string &a, const string &b){
  string tmp_a = a;
  string tmp_b = b;
  replace(tmp_a.begin(), tmp_a.end(), '?', 'a');
  replace(tmp_b.begin(), tmp_b.end(), '?', 'a');
  return tmp_a < tmp_b;
}

bool comp_z(const string &a, const string &b){
  string tmp_a = a;
  string tmp_b = b;
  replace(tmp_a.begin(), tmp_a.end(), '?', 'z');
  replace(tmp_b.begin(), tmp_b.end(), '?', 'z');
  return tmp_a < tmp_b;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<string> vec;
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    vec.pb(s);
  }
  string t;
  cin >> t;
  sort(vec.begin(), vec.end(), comp_a);
  int start_a = lower_bound(vec.begin(), vec.end(), t, comp_a) - vec.begin();
  int end_a = upper_bound(vec.begin(), vec.end(), t, comp_a) - vec.begin();
  sort(vec.begin(), vec.end(), comp_z);
  int start_z = lower_bound(vec.begin(), vec.end(), t, comp_z) - vec.begin();
  int end_z = upper_bound(vec.begin(), vec.end(), t, comp_z) - vec.begin();

  for(int i = start_z; i <= end_a; i++){
    cout << i + 1;
    if(i != end_a)cout << " ";
  }
  cout << endl;
	return 0;
}
