#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
string test[345678];
signed main() {
	int n; string s, t; cin >> n;
	int mi = n + 1, ma = 1;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
	}
	cin >> t;
	//miの場合
	for (int h = 0; h < n; h++) {
		for (int i = 0; i <= min(test[h].size(), t.size()); i++) {
			if (i == t.size()) { mi--; break; }
			if (i == test[h].size()) { break; }
			if (test[h][i] == '?') { 
				if (t[i] != 'z') { mi--; break; }
			}
			else if (test[h][i] > t[i]) { mi--; break; }
			else if (test[h][i] != t[i]) { break; }
		}
	}
	//maの場合
	for (int h = 0; h < n; h++) {
		for (int i = 0; i <= min(test[h].size(), t.size()); i++) {
			if (i == test[h].size()) { ma++; break; }
			if (i == t.size()) { break; }
			if (test[h][i] == '?') {
				if (t[i] != 'a') { ma++; break; }
			}
			else if (test[h][i] < t[i]) { ma++; break; }
			else if (test[h][i] != t[i]) { break; }
		}
	}
	for (int h = mi; h <= ma; h++) {
		if (h == mi) { cout << h; }
		else { cout << ' ' << h; }
	}
	cout << endl;
	return 0;
}