#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

struct list {
    string handle;
    int    position;
    int    rank;
};

//  文字列を置換する
string Replace( string String1, string String2, string String3 )
{
    string::size_type  Pos( String1.find( String2 ) );

    while( Pos != string::npos )
    {
        String1.replace( Pos, String2.length(), String3 );
        Pos = String1.find( String2, Pos + String3.length() );
    }
    return String1;
}

int main()
{
    int N;

    if (scanf("%d", &N) < 1) return 0;

    char tmp[21];

    vector<list> va;
    vector<list> vz;
    for (int i = 0; i <= N; i++)
    {
        if (scanf("%s", tmp) < 1) return 0;

        string tmpa = Replace(tmp, "?", "a");

        list a = {tmpa, i, 0};
        va.push_back(a);

        string tmpz = Replace(tmp, "?", "z");

        list z = {tmpz, i, 0};
        vz.push_back(z);
    }

    // a置換 handleをキーに昇順でソート
    stable_sort(va.begin(), va.end(),
        [](const list &x, const list &y) { return x.handle < y.handle; });

    for (int i = 0; i < va.size(); i++)
    {
        va[i].rank = i + 1;
    }

    // a置換 positionをキーに昇順でソート
    sort(va.begin(), va.end(),
        [](const list &x, const list &y) { return x.position < y.position; });

    int endrank = va[N].rank;

    // z置換 handleをキーに昇順でソート
    stable_sort(vz.begin(), vz.end(),
        [](const list &x, const list &y) { return x.handle < y.handle; });

    int samerank = -1;
    for (int i = 0; i < vz.size(); i++)
    {
        vz[i].rank = i + 1;
        if (vz[i].position == N)
        {
            string tmphandle = vz[i].handle;
            samerank = vz[i].rank;
            for (int j = i - 1; 0 <= j; j--)
            {
                if (vz[j].handle == tmphandle) samerank = vz[j].rank;
                else break;
            }
        }
    }

    int startrank = samerank > 0 ? samerank : endrank;

    string str = "";
    for (int i = startrank; i <= endrank; i++)
    {
        printf("%s", str.c_str());
        str = " ";
        printf("%d", i);
    }

    printf("\n");
    return 0;
}
