import java.io.*;
import java.util.*;

public class join_md {
	private static String fileName = join_md.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
	private static String inputFileName = fileName + ".in";
	private static String outputFileName = fileName + ".out";
	private static BufferedReader in;
	private static PrintWriter out;

	public void run() throws IOException {
		int n = Integer.parseInt(in.readLine());
		Map<String, List> longest = new HashMap<String, List>();
		for (int i = 1; i <= n; i++) {
			String s = in.readLine();
			int colonIndex = s.indexOf(':');
			String handle = s.substring(0, colonIndex);
			s = s.substring(colonIndex + 2);
			List best = longest.get(handle);
			if (best == null) {
				best = new List(i);
			}
			StringTokenizer st = new StringTokenizer(s);
			while (st.hasMoreTokens()) {
				String mention = st.nextToken();
				if (!mention.startsWith("@") || mention.equals(handle)) {
					continue;
				}
				List cur = longest.get(mention);
				if (cur == null) {
					continue;
				}
				cur = new List(i, cur);
				if (cur.length > best.length) {
					best = cur;
				}
			}
			longest.put(handle, best);
		}
		List best = null;
		for (List list : longest.values()) {
			if (best == null || list.length > best.length) {
				best = list;
			}
		}
		out.println(best.length);
		best.print();
	}
	
	class List {
		int head;
		List tail;
		int length;
		
		public List(int head, List tail) {
			this.head = head;
			this.tail = tail;
			this.length = tail.length + 1;
		}
		
		public List(int head) {
			this.head = head;
			this.length = 1;
		}
		
		void print() {
			if (tail != null) {
				tail.print();
			}
			out.print(" " + head);
		}
	}

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		in = new BufferedReader(new FileReader(inputFileName));
		out = new PrintWriter(outputFileName);
		new join_md().run();
		in.close();
		out.close();
	}
}
