#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
int before, after;
string S[10500];
string T;
void g(string tmp) {
    for(int i = 0; i < tmp.size(); i++) {
        if(tmp[i] == '?') tmp[i] = 'z';
    }
    //cerr << tmp << endl;
    if(tmp >= T) after++;
}

void f(string tmp) {
    for(int i = 0; i < tmp.size(); i++) {
        if(tmp[i] == '?') tmp[i] = 'a';
    }
    //cerr << tmp << endl;
    if(tmp <= T) before++;
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> S[i];
    cin >> T;
    for(int i = 1; i <= N; i++) {
        f(S[i]);
        g(S[i]);
    }
    cerr << before << " " << after << endl;
    for(int i = N - after + 1; i <= before; i++) {
        cout << i << " ";
    }
    cout << before + 1 << endl;
    return 0;
}
