import java.io.*;
import java.util.*;
 
public class join_nn {
 
    static void solve() throws IOException {
        int n = Integer.parseInt(br.readLine());
        int[] prev = new int[n];
        Arrays.fill(prev, -1);
        HashMap<String, Integer> z = new HashMap<>();
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            String line = br.readLine();
            int pos = line.indexOf(':');
            String name = line.substring(0, pos);
            String message = line.substring(pos + 1);
            dp[i] = 1;
            for (int j = message.indexOf(" @"); j >= 0; j = message.indexOf(
                    " @", j + 1)) {
                int end = message.indexOf(' ', j + 1);
                if (end < 0) end = message.length();
                String who = message.substring(j + 1, end);
                if (!who.equals(name) && z.containsKey(who)) {
                    int from = z.get(who);
                    int cur = dp[from];
                    if (cur + 1 > dp[i]) {
                        dp[i] = cur + 1;
                        prev[i] = from;
                    }
                }
            }
            if (z.containsKey(name)) {
                int last = dp[z.get(name)];
                if (dp[i] > last) {
                    z.put(name, i);
                }
            } else {
                z.put(name, i);
            }
        }
        int ansI = -1;
        for (int i = 0; i < n; i++) {
            if (ansI < 0 || dp[ansI] < dp[i]) {
                ansI = i;
            }
        }
        int[] ans = new int[n];
        int ac = 0;
        for (int i = ansI; i >= 0; i = prev[i]) {
            ans[ac++] = i;
        }
        out.println(ac);
        for (int i = 0; i < ac; i++) {
            if (i > 0) {
                out.print(' ');
            }
            out.print(ans[ac - i - 1] + 1);
        }
        out.println();
    }
 
    public static void main(String[] args) throws Exception {
        File file = new File("join.in");
        InputStream input = System.in;
        PrintStream output = System.out;
        if (file.exists() && file.canRead()) {
            input = new FileInputStream(file);
            output = new PrintStream("join.out");
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        out.close();
    }
 
    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;
 
    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }
 
    static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
 
    static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
 
    static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}