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

int N;
string S[10005];

bool cmp(string a, string b) {
	for (int i = 0; i < min(a.length(), b.length()); i++) {
		
		if (a[i] == '?' && b[i] > 'a') return 1;
		if (a[i] > 'a' && b[i] == '?') return 0;
		if (a[i] < b[i]) return 1;
		if (a[i] > b[i]) return 0;
	}
	if (a.length() < b.length()) return 1;
	else return 0;
}

bool cmp1(string a, string b) {
	for (int i = 0; i < min(a.length(), b.length()); i++) {
		
		if (a[i] == '?' && b[i] < 'z') return 0;
		if (b[i] == '?' && a[i] < 'z') return 1;
		if (a[i] < b[i]) return 1;
		if (a[i] > b[i]) return 0;
	}
	if (a.length() < b.length()) return 1;
	else return 0;
}

string T;

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N + 1; i++) cin >> S[i];
	T = S[N];
	sort(S, S + N + 1, cmp1);
	int mini = 2000000000;
	for (int i = 0; i < N + 1; i++) if (T == S[i]) mini = min(mini, i + 1);
	sort(S, S + N + 1, cmp);
	int maxi = 0;
	for (int i = 0; i < N + 1; i++) if (T == S[i]) maxi = max(maxi, i + 1);
	for (int i = mini; i <= maxi; i++) {
		if (i != mini) printf(" ");
		printf("%d", i);
	}
	printf("\n");
}
