import java.io.File;
import java.io.PrintWriter;
import java.util.*;

public class join_gk {
    static Scanner in;
    static PrintWriter out;

    void run() {
        int n = in.nextInt();
        in.nextLine();
        int[] prev = new int[n];
        int[] len = new int[n];
        int maxI = 0;
        Map<String, Integer> last = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String[] line = in.nextLine().split(":", 2);
            String author = line[0];
            len[i] = 1;
            prev[i] = -1;
            for (String word : line[1].split(" ")) {
                if (author.equals(word)) continue;
                if (last.containsKey(word)) {
                    int l = last.get(word);
                    if (len[i] < len[l] + 1) {
                        len[i] = len[l] + 1;
                        prev[i] = l;
                    }
                }
            }
            if (len[maxI] < len[i]) {
                maxI = i;
            }
            if (!last.containsKey(author) || len[last.get(author)] < len[i]) {
                last.put(author, i);
            }
        }
        int i = maxI;
        List<Integer> path = new ArrayList<>();
        while (i != -1) {
            path.add(i);
            i = prev[i];
        }
        out.println(len[maxI]);
        Collections.reverse(path);
        for (Integer p : path) {
            out.println(p + 1);
        }
    }


    public static void main(String[] args) throws Exception {
        in = new Scanner(new File("join.in"));
        out = new PrintWriter("join.out");

        new join_gk().run();

        in.close();
        out.close();
    }
}
