#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<string> S( N );
	for( int i = 0; i < N; i++ ) {
		cin >> S[i];
	}
	string T;
	cin >> T;

	vector<string> Sa( N );
	for( int i = 0; i < N; i++ ) {
		Sa[i] = S[i];
		if( Sa[i] == T ) Sa[i] = string( T.size(), '?' );
		replace( Sa[i].begin(), Sa[i].end(), '?', 'a'  );
	}
	Sa.push_back( T );
	sort( Sa.begin(), Sa.end() );
	vector<string> Sz( N );
	for( int i = 0; i < N; i++ ) {
		Sz[i] = S[i];
		if( Sz[i] == T ) Sz[i] = string( T.size(), '?' );
		replace( Sz[i].begin(), Sz[i].end(), '?', 'z'  );
	}
	Sz.push_back( T );
	sort( Sz.begin(), Sz.end() );
	int f = find( Sa.begin(), Sa.end(), T ) - Sa.begin();
	int e = find( Sz.begin(), Sz.end(), T ) - Sz.begin();
	vector<int> ans;
	for( int i = e; i <= f; i++ ) {
		ans.push_back( i + 1 );
	}


	for( int i = 0; i < ans.size(); i++ ) {
		if( i ) cout << " ";
		cout << ans[i];
	}
	cout << endl;
}
