#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <functional>
#include <chrono>
#include <time.h>
using namespace std;

struct Trie {
	Trie *next[27];
	int cnt[28];

	Trie() {
		fill(next, next + 27, (Trie *)0);
		fill(cnt, cnt + 28, 0);
	}

	void insert(const char *s) {
		if (*s == '\0') {
			cnt[27]++;
			return;
		}
		if (this->next[*s-'a'] == NULL)
			this->next[*s-'a'] = new Trie();
		cnt[*s - 'a']++;
		this->next[*s- 'a']->insert(s + 1);
	}

	bool find(const char *s) {
		if (*s == '\0') return true;
		if (this->next[*s-'a'] == NULL)
			return false;
		return this->next[*s-'a']->find(s + 1);
	}
};

pair<int, int> solve(Trie* trie, const char *t) {
	if (*t == '\0') {
		return make_pair(trie->cnt[27], 0);
	}

	int n = *t - 'a';
	vector<int> res;
	int cnt = 0;
	pair<int, int>pcnt = make_pair(0, 0);
	vector<int>next;
	for (int i = 0; i < 26; i++) {
		if (i < n)cnt += trie->cnt[i];
		else if (i == n) {
			if (trie->cnt[i]) {
				pair<int,int> pi = solve(trie->next[i], t + 1);
				pcnt.first += pi.first;
				pcnt.second += pi.second;
			}
		}
		else break;
	}
	cnt += trie->cnt[27];

	if (trie->cnt[26]) {
		if (n == 0) {
			pair<int, int> pi = solve(trie->next[26], t + 1);
			pcnt.first += pi.first;
			pcnt.second += 0;
		}
		else if (n == 25) {
			pair<int, int> pi = solve(trie->next[26], t + 1);
			pcnt.first += trie->cnt[26];
			pcnt.second += pi.second;
		}
		else {
			pcnt.first += trie->cnt[26];
		}
	}

	return make_pair(cnt + pcnt.first, cnt + pcnt.second);
}

int main()
{
	int n; cin >> n;
	Trie* trie = new Trie();

	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int j = 0; j < s.size(); j++)if (s[j] == '?')s[j] = 'a' + 26;
		trie->insert(s.data());
	}

	string T; cin >> T;
	//trie->insert(T.data());

	pair<int, int>ans = solve(trie, T.data());

	bool first = true;
	for (int i = ans.second; i <= ans.first; i++) {
		if (first==false)cout << " ";
		cout << i + 1;
		first = false;
	}
	cout << endl;

    return 0;
}

