#include <set>
#include <string>
#include <map>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
  int n;
  cin >> n;
  map<string, vector<int>> words;

  string word;
  for (int i = 0; i < n; i++)
  {
    int l;
    cin >> l;
    for (int j = 0; j < l; j++)
    {
      cin >> word;
      if (!words[word].size() || words[word].back() != i)
	words[word].push_back(i);
    }
  }

  int m;
  cin >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> word;
    if (words.count(word) == 0)
    {
      cout << endl;
    }
    else
    {
      for (int j = 0; j < words[word].size(); j++)
      {
	cout << words[word][j] + 1;
	if (j != words[word].size() - 1)
	  cout << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
