#include <bits/stdc++.h> 
using namespace std; 

long long n;  
bool posecen[100];
vector<pair<long long, long long> > adj[100]; 
long long br=0;
void dfs2(long long s, long long sled) {

	posecen[s] = true;
	//cout<<" --"<<s<<" "<<"-- ";
    for (long long j = 0; j < adj[s].size() ; j++) {
        long long t=adj[s][j].first;
        //cout<<adj[s][j].second<<endl;
		if (!posecen[t] and adj[s][j].second==sled+1){
        	dfs2(t,sled+1);
		}
		if(sled==3){
			br++;
		}
    }
	//cout<<br<<endl;
}

void dfs1(long long n){
	/**/
	for(long long i=1;i<=n;i++) {
		for(long long j=1;j<=n;j++){
				posecen[j]=false;
			}
			//cout<<endl;
		if(posecen[i]==false){
			 dfs2(i,0);
		}
	}
   
}

int main() 
{ 
    long long a,b,c;
    char s;
	cin>>n;
    for(long long i=0;i<n-1;i++){
    	cin>>a>>b>>s;
    	if(s=='S') c=1;
    	if(s=='I') c=2;
    	if(s=='O') c=3;
    	adj[a].push_back(make_pair(b, c)); 
    	adj[b].push_back(make_pair(a, c)); 
	}
	 
    //printGraph(adj, n); 
    dfs1(n);
    cout<<br;
    return 0; 
} 
/*
6
4 1 S
5 6 O
1 5 I
1 2 S
3 1 S
*/