#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define int long long
const ll INF = 1e15;

const int N = 1000 * 100 + 1000;
string s[N];
string f[N];
string t;
int n;


void change(char c){
	for(int i = 0; i < n; i++){
		f[i] = "";
		for(int j = 0; j < s[i].size(); j++){
			if(s[i][j] == '?')
				f[i] += c;
			else
				f[i] += s[i][j];
		}
	}
	f[n] = t;
}

int find(bool B){
	sort(f, f + n + 1);
	int Min = 100000,
		Max = -100000;
	for(int i = 0; i < n + 1; i++)
		if(f[i] == t){
			Min = min(Min, i + 1);
			Max = max(Max, i + 1);
		}
	if(B)
		return Max;
	return Min;
}

int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> s[i];
	cin >> t;

	change('a');
	int Max = find(true);
	change('z');
	int Min = find(false);


	for(int i = Min; i <= Max; i++){
		cout << i;
		if(i != Max)
			cout << ' ';
	}
	cout << '\n';

    return 0;
}

// Tu te faufiles
// entre mes lignes
// Tu te faufiles
// entre mes lignes
// Charlotte Cardin - Faufile