#include<bits/stdc++.h>
using namespace std;
bool str(string st){
	unsigned long long brs=0;
	unsigned long long bri=0;
	unsigned long long bro=0;
	unsigned long long n=st.size();
	for(unsigned long long i=0;i<n;i++){
		if(st[i]=='S')brs++;
		if(st[i]=='I')bri++;
		if(st[i]=='O')bro++;
	}
	if(brs==bri&&bri==bro)return true;
	else return false;
}
int br=0;
string s="";
void pg(unsigned long long a[][300000], char b[][300000], bool p[], unsigned long long n,string s1, unsigned long long br1, unsigned long long bv){
	if(br1!=0&&str(s1))br++;
	for(unsigned long long i=0;i<n;i++){
		if(a[bv][i]==1&&!p[i]){
			p[i]=true;
			pg(a,b,p,n,s1+b[bv][i],br1+1,i);
			p[i]=false;
		}
	}
}
int main(){
	unsigned long long n;
	cin>>n;
	unsigned long long a[n][300000];
	char b[n][300000];
	for(unsigned long long i=0;i<n;i++){
		for(unsigned long long j=0;j<n;j++)a[i][j]=0;
	}
	for(unsigned long long i=0;i<n-1;i++){
		unsigned long long apom,bpom;
		char xpom;
		cin>>apom>>bpom>>xpom;
		a[apom-1][bpom-1]=1;
		a[bpom-1][apom-1]=1;
		b[apom-1][bpom-1]=xpom;
		b[bpom-1][apom-1]=xpom;
	}
	bool p[n];
	for(unsigned long long i=0;i<n;i++)p[i]=false;
	for(unsigned long long i=0;i<n;i++){
	    p[i]=true;
		pg(a,b,p,n,"",1,i);	
	}
	br=br/2;
	cout<<br<<endl;
}