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

int n;  
bool posecen[100];
vector<pair<int, int> > adj[100]; 
// Print adjacency list representaion ot graph 
void printGraph(vector<pair<int,int> > adj[], int V) 
{ 
    int v, w; 
    for (int u = 0; u < V; u++) 
    { 
        cout << "Node " << u << " makes an edge with \n"; 
        for (int i=0; i<adj[u].size(); i++) 
        { 
            v = adj[u][i].first; 
            w = adj[u][i].second; 
            cout << v << " " << w << "\n"; 
        } 
        cout << "\n"; 
    } 
} 
/*
void DFS(vector<pair<int, int> > adj[], int s) 
{ 
    vector<bool> visited(n, false); 
    for (int i = 0; i < n; i++) {
    	cout<<visited[i]<<" ";
	}
    stack<int> st; 
  	st.push(s); 
  
    while (!st.empty()) 
    { 
        s = st.top(); 
        visited[s]=true;
        st.pop(); 
  		cout<< s <<" "; 
  		for (int i = 0; i <= adj[s].size() ; i++) {
  			if(!visited[adj[s][i].first]){
  				st.push(adj[s][i].first);	
			  }
        	//cout<<adj[s][i].first<<" ";
        }
        for (int i = 0; i < n; i++) {
    	cout<<visited[i]<<" ";
	}
            
    } 
} 
*/
int br=0;
void dfs2(int s, int sled) {

	posecen[s] = true;
	//cout<<" --"<<s<<" "<<"-- ";
    for (int j = 0; j < adj[s].size() ; j++) {
        int 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(int n){
	/**/
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++){
				posecen[j]=false;
			}
			//cout<<endl;
		if(posecen[i]==false){
			 dfs2(i,0);
		}
	}
   
}

int main() 
{ 
    int a,b,c;
    char s;
	cin>>n;
    for(int 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
*/