Problem:
Problem A: Membership Management

Peter is a senior manager of Agile Change Management (ACM) Inc., where each employee is a member of one or more task groups. Since ACM is agile, task groups are often reorganized and their members frequently change, so membership management is his constant headache.

Peter updates the membership information whenever any changes occur: for instance, the following line written by him means that Carol and Alice are the members of the Design Group.

design:carol,alice.

The name preceding the colon is the group name and the names following it specify its members.

A smaller task group may be included in a larger one. So, a group name can appear as a member of another group, for instance, as follows.

development:alice,bob,design,eve.

Simply unfolding the design above gives the following membership specification, which is equivalent to the original.

development:alice,bob,carol,alice,eve.

In this case, however, alice occurs twice. After removing one of the duplicates, we have the following more concise specification.

development:alice,bob,carol,eve.

Your mission in this problem is to write a program that, given group specifications, identifies group members.

Note that Peter's specifications can include deeply nested groups. In the following, for instance, the group one contains a single member dave.

one:another.
another:yetanother.
yetanother:dave.

Input

The input is a sequence of datasets, each being in the following format.

n

group1:member1,1,...,member1,m1.

.

.

.

groupi:memberi,1,...,memberi,mi.

.

.

.

groupn:membern,1,...,membern,mn.

The first line contains n, which represents the number of groups and is a positive integer no more than 100. Each of the following n lines contains the membership information of a group: groupi (1 ≤ i ≤ n) is the name of the i-th task group and is followed by a colon (:) and then the list of its mi member s that are delimited by a comma (,) and terminated by a period (.).

Those group names are mutually different. Each mi (1 ≤ i ≤ n) is between 1 and 10, inclusive. A member is another group name if it is one of group1, group2,..., or groupn. Otherwise it is an employee name.

There are no circular (or recursive) definitions of group(s). You may assume that mi member names of a group are mutually different.

Each group or employee name is a non-empty character string of length between 1 and 15, inclusive, and consists of lowercase letters.

The end of the input is indicated by a line containing a zero.

Output

For each dataset, output the number of employees included in the first group of the dataset, that is group1, in a line. No extra characters should occur in the output.

Sample Input

2
development:alice,bob,design,eve.
design:carol,alice.
3
one:another.
another:yetanother.
yetanother:dave.
3
friends:alice,bob,bestfriends,carol,fran,badcompany.
bestfriends:eve,alice.
badcompany:dave,carol.
5
a:b,c,d,e.
b:c,d,e,f.
c:d,e,f,g.
d:e,f,g,h.
e:f,g,h,i.
4
aa:bb.
cc:dd,ee.
ff:gg.
bb:cc.
0

Output for the Sample Input

4
1
6
4
2

Solution in JAVA (judge verdict: Wrong Answer)

import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		solve(n);
	    }
	}
    }

    static void solve(int n){
        String[][] group = new String[n][1050];
	int i, j, k=0, g=0;
	String a, p;
	while(g<n){
	    String len = kbd.next();
	    p = "";
	    for(i=0; i<len.length(); i++){
		a = len.substring(i, i+1);
		if(a.equals(":") || a.equals(",") || a.equals(".")){
		    group[g][k++] = p;
		    p = "";
		}
		else {
		    p += a;
		}
	    }
	    k=0;
	    g++;
	}

	int cnt = 0;
	String[] men = new String[1050];
	boolean TF = true;
	boolean[] x = new boolean[n];
	Arrays.fill(x, false);
	x[0] = true;
    

	for(g=0; g<n; g++){
	    for(i=1; group[g][i] != null; i++){
		p = group[g][i];
		//System.out.println(p);

		//テ」ツ?禿」ツ?ョテ」ツつーテ」ツδォテ」ツδシテ」ツδ療」ツ?ッテヲツ閉ーテ」ツ?暗」ツ?ヲティツ可ッテ」ツ??」ツ?凝ッツシツ?
		for(j=0; j<n; j++){
		    if(x[g] && group[j][0].equals(p)){
			//System.out.println(p);
			x[j] = true;
		    }
		}
	    }
	}


	for(g=0; g<n; g++){
	    for(i=1; group[g][i] != null; i++){
		TF = true;
		p = group[g][i];
		//System.out.println(p);

		// テ」ツつーテ」ツδォテ」ツδシテ」ツδ療・ツ青催」ツ?ィテァツュツ嘉」ツ?療」ツ?妥」ツつ古」ツ?ーテゥツ」ツ崚」ツ?ーテ」ツ??
		for(j=0; j<n; j++){
		    if(x[g] && group[j][0].equals(p)){
			//System.out.println(p);
			TF = false;
		    }
		}

		// テヲツ猟「テ」ツ?ォテヲツ閉ーテ」ツ?暗」ツ?淌」ツ?禿」ツ?ィテ」ツ?ョテ」ツ?づ」ツつ凝・ツ青催・ツ可催」ツ??」ツ?」テ」ツ?淌」ツつ嘉ゥツ」ツ崚」ツ?ーテ」ツ??
		for(j=0; men[j]!=null; j++){
		    if(men[j].equals(p)){
			//System.out.println(p);
			TF = false;
		    }
		}

		// テヲツ閉ーテ」ツ?暗」ツ?ヲテ」ツ??」ツ??」ツつーテ」ツδォテ」ツδシテ」ツδ療」ツ?ァテ」ツ??」ツ?凝」ツ?、テゥツ」ツ崚」ツ?ーテ」ツ?陛」ツつ古」ツ?ヲテ」ツ??」ツ?ェテ」ツ?妥」ツつ古」ツ?ー
		if(TF && x[g]){
		    //System.out.println(p);
		    men[cnt] = p;
		    cnt++;
		}
	    }
	}

	System.out.println(cnt);
    }
}