#include <iostream>
#include <iomanip>
#include <cstdio>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cassert>
#include <sstream>
 
using namespace std;
 
const string TASKNAME = "join";
 
map < string, pair <int, int> > mp;
int f[123456], pr[123456];
 
int main() {
  freopen((TASKNAME + ".in").c_str(), "r", stdin);
  freopen((TASKNAME + ".out").c_str(), "w", stdout);
  int n;
  scanf("%d", &n);
  mp.clear();
  char foo[424];
  int ans = 0, km = -1;
  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    name = name.substr(0, name.length() - 1);
    gets(foo);
    stringstream ss;
    ss << foo;
    string bar;
    f[i] = 1;
    while (ss >> bar) {
      if (bar != name) {
        if (mp.find(bar) != mp.end()) {
          int z = mp[bar].first + 1;
          if (z > f[i]) {
            f[i] = z;
            pr[i] = mp[bar].second;
          }
        }
      }
    }
    if (f[i] > mp[name].first) mp[name] = make_pair(f[i], i);
    if (f[i] > ans) {
      ans = f[i];
      km = i;
    }
  }
  vector <int> ret;
  for (int j = 0; j < ans; j++) {
    ret.push_back(km + 1);
    km = pr[km];
  }
  reverse(ret.begin(), ret.end());
  printf("%d\n", ans);
  for (int i = 0; i < ans - 1; i++) printf("%d ", ret[i]);
  printf("%d\n", ret[ans - 1]);
  return 0;
}