#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
map<string, set<string> > memo;
set<string> rec(string name, vector<string>& commands, map<string, int>& id){
  if(memo.count(name)) return memo[name];
  set<string> res;
  if(id.count(name)){
    string s = commands[id[name]];
    REP(i, s.size())if(s[i] == ':'){
      s = s.substr(i + 1);
      break;
    }
    REP(i, s.size())if(s[i] == ',' || s[i] == '.') s[i] = ' ';
    stringstream ss(s);
    string member;
    while(ss>>member){
      set<string> d = rec(member, commands, id);
      FORIT(it, d) res.insert(*it);
    }
  }else{
    res.insert(name);
  }
  return memo[name] = res;
}

int main(){
  int N;
  while(cin>>N && N){
    memo.clear();
    vector<string> commands(N);
    map<string, int> id;
    REP(i, N) cin>>commands[i];
    string first;
    REP(i, N){
      string s = commands[i];
      string group;
      REP(j, s.size())if(s[j] == ':') group = s.substr(0, j);
      id[group] = i;
      if(i == 0) first = group;
    }
    set<string> ans = rec(first, commands, id);
    //FORIT(it, ans) cout<<*it<<endl;
    cout<<ans.size()<<endl;
  }
  return 0;
}