#include <bits/stdc++.h>
using namespace std;
const int vy[] = {-1, 1, 0, 0}, vx[] = {0, 0, 1, -1};
 
 
map< string, set< string > > names;
set< string > visited;
set< string > rec(string name)
{
  set< string > ret;
  if(visited.find(name) != visited.end()) return(ret);
  visited.insert(name);
  if(names[name].empty()) {
    ret.insert(name);
  } else {
    for(auto p : names[name]) {
      set< string > pp = rec(p);
      if(pp.size() > ret.size()) swap(pp, ret);
      while(!pp.empty()) {
        ret.insert(*pp.begin());
        pp.erase(pp.begin());
      }
    }
  } 
  return(ret);
}
 
int main()
{
  int N;
  while(cin >> N, N) {
    string F = "";
    while(N--) {
      string S;
      cin >> S;
      string C = "";
      vector< string > buff;
      for(int i = 0; i < S.size(); i++) {
        if(isalpha(S[i])) C += S[i];
        else buff.push_back(C), C = "";
      }
      for(int i = 1; i < buff.size(); i++) {
        names[buff[0]].insert(buff[i]);
      }
      if(F.empty()) F = buff[0];
    }
    cout << rec(F).size() << endl;
    visited.clear();
    names.clear();
  }
}