#include<iostream>
#include<algorithm>

using namespace std;

int main(){
	int n;
	cin>>n;
	string* sa=new string[n+1];
	string* sz=new string[n+1];
	for(int i=0;i<n;i++){
		cin>>sa[i];
		sz[i]=sa[i];
		for(int j=0;j<sa[i].size();j++){
			if(sa[i][j]=='?'){
				sa[i][j]='a';
				sz[i][j]='z';	
			}
		}
		
	}

	string t;
	cin>>t;
	
	sa[n]=sz[n]=t;
	sort(sa,sa+n+1);
	sort(sz,sz+n+1);
	int pre=lower_bound(sz,sz+n+1,t)-sz+1;
	int post=upper_bound(sa,sa+n+1,t)-sa;
	for(int i=pre;i<post;i++){
		cout<<i<<" ";
	}
	cout<<post<<endl;
}