#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    vector<string>A(N);
    vector<string>B(N);
    for(int i = 0; i < N; i++) {
        string S;
        cin >> S;
        string T = "",R = "";
        for(int j = 0; j < S.size(); j++) {
            if(S[j] == '?') {
                T+='a';
                R+='z';
            }
            else {
                T+=S[j];
                R+=S[j];
            }
        }
        A[i] = T;
        B[i] = R;
    }
    string T;
    cin >> T;
    A.push_back(T);
    B.push_back(T);
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    int cnt1 = 0,cnt2 = 0;
    for(int i = 0; i < N+1; i++) {
        if(A[i] == T) {
            cnt1 = i+1;
            break;
        }
    }
    for(int i = N; i >= 0; i--) {
        if(B[i] == T) {
            cnt2 = i+1;
            break;
        }
    }
    for(int i = min(cnt1,cnt2); i <= max(cnt1,cnt2); i++) {
        cout << i << ((i == max(cnt1,cnt2))?"":" ");
    }
    cout << endl;
}
