#include <iostream>
#include <vector>
using namespace std;

struct grana{
	int c1;
	int c2;
};

int provera(int cvor, vector<grana> Sgrane){
	int x = 0;
	for(int i=0; i<Sgrane.size(); i++){
		if(cvor==Sgrane[i].c1 || cvor==Sgrane[i].c2){
			x++;
		}
	}
	return x;	
}

int main(){
	int n, k=0;
	cin >> n;
	vector<grana> Sgrane;
	vector<grana> Igrane;
	vector<grana> Ograne;
	
	for(int i=0; i<n-1; i++){
		int x1, x2;
		char s;
		cin >> x1 >> x2 >> s;
		grana g;
		g.c1 = x1;
		g.c2 = x2;
		if(s == 'S')
			Sgrane.push_back(g);
		else if(s == 'I')
			Igrane.push_back(g);
		else
			Ograne.push_back(g);
	}
	
	
	for(int i=0; i<Igrane.size(); i++){
		for(int j=0; j<Ograne.size(); j++){
			if(Igrane[i].c1 == Ograne[j].c1 || Igrane[i].c1 == Ograne[j].c2){
				int odgg = Igrane[i].c2;
				k+=provera(odgg, Sgrane);
			}
			else if(Igrane[i].c2 == Ograne[j].c1 || Igrane[i].c2 == Ograne[j].c2){
				int odgg = Igrane[i].c1;
				k+=provera(odgg, Sgrane);	
			}
		}
	}
	
	cout << k;
}