#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>

using namespace std;

struct veza
{
    int cvor;
    char c;
};
int n,a,b;
vector<veza> graf[1005];
veza temp;
bool posecen[1005];
int cilj,R;
bool gotovo;

void dfs(int x, bool bs, bool bi, bool bo)
{
    if(x==cilj && bs && bi && bo) {R++; gotovo=true; return;}
    else if(x==cilj) {gotovo=true; return;}
    posecen[x]=true;
    for(int i=0;i<graf[x].size();i++)
    {
        if(posecen[graf[x][i].cvor] == false)
        {
            if(graf[x][i].c == 'S')
                dfs(graf[x][i].cvor, true, bi, bo);
            else if(graf[x][i].c == 'I')
                dfs(graf[x][i].cvor, bs, true, bo);
            else if(graf[x][i].c == 'O')
                dfs(graf[x][i].cvor, bs, bi, true);
            if(gotovo) break;
        }
    }
    posecen[x]=false;
}

int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        temp.cvor=b;
        //cout<<"AAA\n";
        cin>>temp.c;
        graf[a].push_back(temp);
        temp.cvor=a;
        graf[b].push_back(temp);
        //cout<<"BBB\n";
    }
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            cilj=j;
            gotovo=false;
            dfs(i,0,0,0);
        }
    }
    cout<<R<<endl;
    return 0;
}
///  01001o10101001