#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    vector<string> s(n);
    REP(i, n){
        cin >> s[i];
    }
    string t;
    cin >> t;
    
    ll front = 0, back = 0;
    REP(i, n){
        bool f = false, b = false;
        ll j;
        for(j = 0; j < min(s[i].size(), t.size()); j++){
            if(s[i][j] != '?'){
                if(t[j] < s[i][j]){
                    if(!b) back++;
                    break;
                }
                else if(t[j] > s[i][j]){
                    if(!f) front++;
                    break;
                }
            }
            else{
                if(t[j] != 'a' && t[j] != 'z'){
                    break;
                }
            }
        }
        if(j == min(s[i].size(), t.size())){
            if(t.size() < s[i].size()){
                if(!b) back++;
            }
            else if(t.size() > s[i].size()){
                if(!f) front++;
            }
        }
    }
    
    vector<ll> ans;
    for(ll i = front; i <= n - back; i++){
        ans.push_back(i + 1);
    }
    REP(i, ans.size()){
        cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
}
