import java.io.BufferedReader;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.*;
 
/**
 * Created with IntelliJ IDEA.
 * User: poromov
 * Date: 27.11.13
 * Time: 13:56
 * To change this template use File | Settings | File Templates.
 */
public class join_bgp {
    public void solve() throws Exception {
        int n = nextInt();
        HashMap<String, Integer> map = new HashMap<String, Integer>();
        int[] prev = new int[n];
        int[] value = new int[n];
        int best = 0;
 
        for (int i = 0; i < n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            String name = st.nextToken();
            name = name.substring(0, name.length() - 1);
 
            int max = 1;
            int p = -1;
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                if (!token.equals(name) && map.containsKey(token)) {
                    int id = map.get(token);
                    if (value[id] + 1 > max) {
                        max = value[id] + 1;
                        p = id;
                    }
                }
            }
 
            value[i] = max;
            if (max > value[best]) {
                best = i;
            }
            prev[i] = p;
            if (map.containsKey(name)) {
                int other = map.get(name);
                if (value[i] > value[other]) {
                    map.put(name, i);
                }
            } else {
                map.put(name, i);
            }
        }
 
        out.println(value[best]);
        ArrayList<Integer> list = new ArrayList<Integer>();
        while (best != -1) {
            list.add(best + 1);
            best = prev[best];
        }
        Collections.reverse(list);
        for (int x : list) {
            out.print(x + " ");
        }
        out.println();
    }
 
    int nextInt() {
        return Integer.parseInt(nextToken());
    }
 
    String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine()) ;
            } catch (Exception e) {
                eof = true;
                return "0";
            }
        }
        return st.nextToken();
    }
 
    public static void main(String[] args) {
        new join_bgp().run();
    }
 
    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;
    boolean eof;
 
    public void run() {
        try {
            br = new BufferedReader(new FileReader("join.in"));
            out = new PrintWriter("join.out");
            solve();
        } catch (Throwable t) {
            t.printStackTrace();
            System.exit(-1);
        } finally {
           out.close();
        }
    }
 
}