#include<bits/stdc++.h>
using namespace std;
int n,avb='S'+'I'+'O',ans,suma;
const int nmax =3e5;
struct veza{
	int p,v;
	int s;//znak
};

struct nod{
		int id;
		vector<veza> veze;
};
nod CVORI[nmax];
void vezaa(vector<veza> DINO,int ide,int identity,int kre)
{
	for(veza i:DINO){
		suma+=i.s;
		//cout << i.p << " "<<i.v<<" "<<i.s<<" "<<suma <<" " << ide<<endl; 
		if(CVORI[i.v].veze.size()==0 || i.v==ide || i.p>identity){/*cout<<"R"*/;suma-=i.s;continue;}
		if(suma%avb==0 && suma){ans++;suma-=i.s;continue;}
		kre=0;
		vezaa(CVORI[i.v].veze,i.p
		,identity,i.s);
		
	}
	suma-=kre;
}
int main()
{
	cin >> n; 
	//formiranje nodova[]
	for(int i=1;i<n+1;i++){
		nod cvor;
		cvor.id=i;
		CVORI[i]=cvor;
	}
	//formirnaje veza
	for(int i=0;i<n-1;i++)
	{
		char cpg;
		int x,y,s;
		//cin.ignore();
		cin >> x >> y >> cpg;
		s=(int)cpg;
		veza VV;
		VV.p=x;
		VV.v=y;
		VV.s=s;
		CVORI[x].veze.push_back(VV);
		VV.p=y;
		VV.v=x;
		CVORI[y].veze.push_back(VV);
	}
	/*cout << "dalje";
	for(int i=1;i<n+1;i++){
		
		for(veza kkk:CVORI[i].veze)cout<<kkk.p << " "<<kkk.v << " " << kkk.s << endl;
		cout << "G"<<endl;
	}*/
	for(int i=1;i<n+1;i++)
	{
		
		//cout << "E"<<endl;	
		//for(veza kkk:CVORI[i].veze)cout<<kkk.p << " "<<kkk.v << " " << kkk.s << endl;
		//cout << "		NODE:"<<i<<endl;
		suma=0;	
		vezaa(CVORI[i].veze,i,i,0);
	}
	cout <<ans;
	
}