public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int n = Integer.parseInt(line.trim());
			if (n == 0)
				break;
			groups = new HashMap<String, String[]>();
			String firstGroup = "";
			for (int i = 0; i < n; i++) {
				String data = in.readLine().trim();
				data = data.substring(0, data.length() - 1);
				String[] d = data.split(":");
				String group = d[0];
				String[] members = d[1].split(",");
				groups.put(group, members);
				if (i == 0)
					firstGroup = group;
			}
			counted = new HashMap<String, Integer>();
			int ans = solve(firstGroup);
			out.append(ans + "\n");
		}
		System.out.print(out);
	}