#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<string>
#define N 50010
using namespace std;
string str[10010], t, s[10010];
int main()
{
    ios::sync_with_stdio(false);
    int i, j, n, l, r;
    cin >> n;
    for(i = 1; i <= n; ++i)
    {
        cin >> str[i];
    }
    cin >> t;
    for(i = 1; i <= n; ++i)
    {
        s[i] = str[i];
        for(j = 0; s[i][j]; ++j)
            if(s[i][j] == '?') s[i][j] = 'a';
    }
    s[n + 1] = t;
    sort(s + 1, s + 2 + n);
    for(i = n + 1; i >= 1; --i)
    {
        if(s[i] == t)
        {
            r = i;
            break;
        }
    }
    for(i = 1; i <= n; ++i)
    {
        s[i] = str[i];
        for(j = 0; s[i][j]; ++j)
            if(s[i][j] == '?') s[i][j] = 'z';
    }
    s[n + 1] = t;
    sort(s + 1, s + 2 + n);
    for(i = 1; i <= n + 1; ++i)
    {
        if(s[i] == t)
        {
            l = i;
            break;
        }
    }
    for(i = l; i <= r; ++i)
    {
        cout << i;
        if(i != r)
            cout << " ";
        else
            cout << "\n";
    }
    return 0;
}
/*
1
?
a
*/
