#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define pii pair<int,int>
#define ll long long
const int maxn = 1e5 + 2;
using namespace std;
vector<pii> adj[maxn];
struct pod
{
	int S;
	int I;
	int O;
};
ll dfs1(int v, int i, int o, int d, int e)
{
	if (d == 2) {
		if (i == 1 && o == 1)return 1;
		else return 0;
	}
	ll ans = 0;
	for (auto u : adj[v]) {
		if (u.first == e)continue;
		if (u.second == 1) {
			ans += dfs1(u.first, i + 1, o, d + 1, v);
		}
		else if (u.second == 2){
			ans += dfs1(u.first, i, o + 1, d + 1, v);
		}
	}
	return ans;
}
int dfs2(int v, int s,int i, int o, int e)
{
	int ans = 0;
	if (s == i && i == o && s)ans++;
	for (auto u : adj[v]) {
		if (u.first == e)continue;
		if (u.second == 0) {
			ans += dfs2(u.first, s + 1, i, o, v);
		}
		else if (u.second == 1) {
			ans += dfs2(u.first, s, i + 1, o, v);
		}
		else {
			ans += dfs2(u.first, s, i, o + 1, v);
		}
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cerr.tie(0);
	int n;
	cin >> n;
	vector<int> mot(n + 1, -1);
	int cs = 0, as = 0 , bs = 0;
	bool motka = true;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		char z;
		cin >> u >> v >> z;
		if (z == 'S') {
			adj[u].push_back({ v,0 });
			adj[v].push_back({ u,0 });
			cs++, as = u, bs = v;
			mot[max(u, v)] = 0;
		}
		else if (z == 'I') {
			adj[u].push_back({ v,1 });
			adj[v].push_back({ u,1 });
			mot[max(u, v)] = 1;
		}
		else {
			adj[u].push_back({ v,2 });
			adj[v].push_back({ u,2 });
			mot[max(u, v)] = 2;
		}
		if (abs(u - v) > 1) motka = false;
		
	}
	if (cs == 1) {
		ll r = 1;
		r *= (dfs1(as, 0, 0, 0, 0));
		r *= (dfs1(bs, 0, 0, 0, 0));
		cout << r;
		return 0;
	}
	if (n <= 1000) {
		int r = 0;
		for (int i = 1; i <= n; i++) {
			r += dfs2(i, 0, 0, 0, 0);
		}
		cout << r / 2;
		return 0;
	}
	else if (motka) {
		map<pod, int> ma;
		pod prvi = { 0,0,0 };
		ma[prvi]++;
		int a = 0, b = 0, c = 0;
		for (int i = 2; i <= n; i++) {
			if (mot[i] == 0)a++;
			else if (mot[i] == 1)b++;
			else if (mot[i] == 2)c++;
			pod tr = { 0,b - a,c - a };
			ma[tr]++;
		}
		ll r = 0;
		for (auto u : ma) {
			r += (u.second * (u.second - 1));
		}
		cout << r;
		return 0;
	}
	cout << 0;
	return 0;	
}