#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<functional>
#include<list>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<string.h>
#include<limits.h>
using namespace std;

string x[10001];
string y[10001];
signed main() {
	int b;
	cin >> b;
	for (int c = 0; c < b; c++) {
		string d; cin >> d;
		string e, f;
		for (char g : d) {
			if (g == '?') {
				e += 'a';
				f += 'z';
			}
			else {
				e += g;
				f += g;
			}
		}
		x[c] = e;
		y[c] = f;
	}
	string S; cin >> S;
	x[b] = y[b] = S;
	sort(x, x + b + 1);
	sort(y, y + b + 1);
	bool K = false;
	vector<int>V;
	for (int i = 0; i <= b; i++) {
		if (y[i] == S) {
			K = true;
		}
		if (K)V.push_back(i + 1);
		if (x[i] == S) {
			K = false;
		}
	}
	for (int i = 0; i< V.size(); i++) {
		if (i)cout << " ";
		cout << V[i];
	}
	puts("");
}