#include <cmath>
#include <queue>
#include <cstdio>
#include <map>
#include <vector>
#include <iostream>
#include <stack>
#include <climits>
#include <assert.h>
#include <set>
#include <queue>
#include <algorithm>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld;


typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
const int N = 100001;
const int MOD = 1e9 + 7;

int main(int argc, const char * argv[]) {
    
    int n;
    cin>>n;
    vector<string> vec1;
    vector<string> vec2;

    for(int i = 0; i < n; i++){
        string a;
        cin>>a;
        vec1.push_back(a);
        vec2.push_back(a);
        
    }
    string t;
    cin>>t;
    /*
    int count = 0;
    int count2 = 0;
    
    for(int i = 0; i < n; i++){
        bool smallerthant = false;
        bool largerthant = false;
        
        for(int j = 0; j < t.size() && j < vec[i].size(); j++){
            if(vec[i][j] < t[j] && vec[i][j] != '?'){
                smallerthant = true;
            }
            if(vec[i][j] > t[j] && vec[i][j] != '?'){
                largerthant = true;
            }
            if(vec[i][j] == '?'){
                if(!largerthant && !smallerthant){
                    
                }
            }
        }
        
        
    }*/
    
    //cout<<count<<" "<<count2<<endl;
    
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < vec1[i].size(); j++){
            if(vec1[i][j] == '?'){
                vec1[i][j] = 'a';
                vec2[i][j] = 'z';
            }
        }
    }
    
    sort(vec1.begin(), vec1.end());
    sort(vec2.begin(), vec2.end());
    
    int lowerbound = -1;
    int upperbound = n;
    for(int i = 1; i <= n; i++){
        
        if(vec1[i-1] > t){
            upperbound = i-1;
            break;
        }
        
        
    }
    
    for(int i = 1; i <= n; i++){
        
        if(vec2[i-1] >= t){
            lowerbound = i-1;
            break;
        }
        
        
    }
    
    

    //cout<<lowerbound<<" "<<upperbound<<endl;
    if(lowerbound == -1){
        cout<<n+1<<endl;
        return 0;
    }
    
    
    for(int i = lowerbound+1; i < upperbound + 1; i++){
        cout<<i<<" ";
    }
    cout<<upperbound+1<<endl;
    
    return 0;
}
