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

int broj_cvorova(int ic, int jc, int br, vector<vector<char>>& cvorovi, int broj_grana[]) {
	for (int i = ic; i < cvorovi.size(); i++) {
		for (int j = jc; j < cvorovi[i].size(); j++) {
			if (cvorovi[i][j] != '/') {
				if (cvorovi[i][j] == 'S')broj_grana[0]++;
				else if (cvorovi[i][j] == 'I')broj_grana[1]++;
				else broj_grana[2]++;
				if (i == cvorovi.size() - 1 && i == j) {
					if (broj_grana[0] == broj_grana[1] && broj_grana[1] == broj_grana[2])return br++;
					else return br;
				}
				else broj_cvorova(i + 1, j + 1, br, cvorovi, broj_grana);
			}
		}
	}
}

int main() {
	int n, u, v, broj_grana[3], br;	//[0]=S; [1]=I; [2]=0
	char c;
	cin >> n;
	vector<vector<char>>cvorovi(n, vector<char>(n, '/'));
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v >> c;
		cvorovi[u - 1][v - 1] = c;
		cvorovi[v - 1][u - 1] = c;
	}
	br = broj_cvorova(0, 0, 0, cvorovi, broj_grana) / 2;
	cout << br;
	return 0;
}