#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 20000000
string word[100];
vector<int> p[100];
int n=0;
int search(string s)
{
        for(int i=0;i<n;i++)
        {
                if(word[i]==s)return i;
        }
        return -1;
}
int main()
{
        while(1)
        {
                string s;
                int page;
                cin >> s >> page;
                if(search(s)!=-1)
                {
                        p[search(s)].pb(page);
                }
                else
                {
                        word[n]=s;
                        p[n].pb(page);
                        n++;
                }

        }
        string str;
        while(cin >> str)
        {
                int num=search(str);
                sort(p[num].begin(),p[num].end());
                for(int i=0;i<p[num].size();i++)
                {
                        cout << p[num][i];
                        if(i==p[num].size()-1)
                        {
                                cout << endl;
                        }
                        else
                        {
                                cout << ' ';
                        }
                }
        }
        return 0;
}