#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> name(n);
    for(int i=0; i<n; ++i)
        cin >> name[i];

    string x;
    cin >> x;

    int cnt1 = 0;
    int cnt2 = 0;
    for(int i=0; i<n; ++i){
        string s = name[i];
        string t = name[i];
        for(unsigned j=0; j<s.size(); ++j){
            if(s[j] == '?'){
                s[j] = 'a';
                t[j] = 'z';
            }
        }

        if(t < x)
            ++ cnt1;
        else if(s <= x)
            ++ cnt2;
    }

    vector<int> ans;
    for(int i=0; i<=cnt2; ++i)
        ans.push_back(cnt1 + 1 + i);

    cout << ans[0];
    for(unsigned i=1; i<ans.size(); ++i)
        cout << ' ' << ans[i];
    cout << endl;

    return 0;
}
