#include <bits/stdc++.h>
#define int long long
#define moder 1000000007
#define inf 1000000000000000000
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/
int n;
string s,t;
vector<string>sfi,sse;
signed main() {
	cin>>n;
	rep(i,n){
		cin>>s;
		string s1=s,s2=s;
		rep(j,s.size()){
			if(s1[j]=='?'){
				s1[j]='a';
				s2[j]='z';
			}
		}
		sfi.push_back(s1);
		sse.push_back(s2);
	}
	cin>>t;
	sfi.push_back(t);
	sse.push_back(t);
	sort(all(sfi));
	sort(all(sse));
	int ans1=-1,ans2;
	rep(i,sfi.size()){
		if(sfi[i]==t&&ans1==-1)ans1=i;
		if(sse[i]==t)ans2=i;
	}
	for(int i=min(ans1,ans2)+1;i<=max(ans1,ans2);i++){
		cout<<i<<" ";
	}
	cout<<max(ans1,ans2)+1<<endl;
}
