#include <bits/stdc++.h>
#define N 100
typedef long long ll;
using namespace std;
string g[N][N] = {"*"};
ll n;
ll br=0;
string s[3]={"S","I","O"};
ll p=0;
void add(ll v,ll u,string c)
{
    g[u][v]=c;
    g[v][u]=c;
}
void topologicalSortUtil(int v, bool mark[])
{
    mark[v] = true;
    if(p%3==0){
        br++;
        return;
    }
    for (ll i = 0; i < n;i++)
        if (!mark[i]&&g[v][i]==s[p%3]){
            p++;
            topologicalSortUtil(i, mark);
        }
}
void topologicalSort()
{
    bool mark[n]={false};
    for (ll i = 0; i < n; i++)
        if (!mark[i])
            topologicalSortUtil(i, mark);
   cout << br/2 << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
     cin >> n;
    ll v,u;
    string c;
    for (ll i = 0; i < n-1; i++)
    {
        cin >> v >> u >> c;
        add(v,u,c);
    }
    topologicalSort();
    return 0;
}