import java.util.Map;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashMap;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.StringTokenizer;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class join_petr {
    public static void main(String[] args) {
        InputStream inputStream;
        try {
            inputStream = new FileInputStream("join.in");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        OutputStream outputStream;
        try {
            outputStream = new FileOutputStream("join.out");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Join solver = new Join();
        solver.solve(1, in, out);
        out.close();
    }
}
 
class Join {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] prev = new int[n];
        int[] len = new int[n];
        Map<String, Integer> byHandle = new HashMap<String, Integer>();
        int max = -1;
        for (int i = 0; i < n; ++i) {
            String s = in.nextLine();
            int colon = s.indexOf(':');
            String who = s.substring(0, colon);
            String[] words = s.substring(colon + 1).split(" ", -1);
            prev[i] = -1;
            len[i] = 1;
            for (String word : words) {
                if (!word.equals(who)) {
                    Integer old = byHandle.get(word);
                    if (old != null) {
                        int clen = len[old] + 1;
                        if (clen > len[i]) {
                            len[i] = clen;
                            prev[i] = old;
                        }
                    }
                }
            }
            Integer prevBest = byHandle.get(who);
            if (prevBest == null || len[prevBest] < len[i]) {
                byHandle.put(who, i);
            }
            if (max == -1 || len[max] < len[i]) max = i;
        }
        out.println(len[max]);
        int[] seq = new int[len[max]];
        int ptr = seq.length - 1;
        int at = max;
        while (at >= 0) {
            seq[ptr--] = at + 1;
            at = prev[at];
        }
        if (ptr != -1) throw new RuntimeException();
        for (int i = 0; i < seq.length; ++i) {
            if (i > 0) out.print(" ");
            out.print(seq[i]);
        }
        out.println();
    }
}
 
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
 
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
 
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
 
    public int nextInt() {
        return Integer.parseInt(next());
    }
 
    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
 
    }