#include<iostream>
#include<map>
#include<utility>
#include<string>
#include<set>
using namespace std;
int s=0;
void stablo(int i, map<int,set<int>>sus_cvorovi, map<pair<int,int>,char>grane, int brS, int brI, int brO, set<int>vec_bio)
{
  
  vec_bio.insert(i);
  for (set<int>::iterator j=sus_cvorovi[i].begin(); j!=sus_cvorovi[i].end(); j++)
  {
    if (vec_bio.count(*j)!=0) break;
    int a=i;
    int b=*j;
    bool x=false;
    if (a<b) swap(a,b);
    if (grane[pair{a,b}]=='S') 
    {
      brS++;
      x=true;
    }
    if (grane[pair{a,b}]=='I')
    {
      brI++;
      x=true;
    }
    if (grane[pair{a,b}]=='O') 
    {
      brO++;
      x=true;
    }
    if (x && brS==brI && brI==brO && brS>0) s++;
    stablo(*j, sus_cvorovi, grane, brS, brI, brO, vec_bio);
  }
}
int main()
{
    int n;
    cin >> n;
    map<pair<int,int>,char>grane;
    map<int,set<int>>sus_cvorovi;
    for (int i=0; i<n-1; i++)
    {
        int a,b;
        char c;
        cin >> a >> b >> c;
        if (a<b) swap(a,b);
        grane[pair{a,b}]=c;
        sus_cvorovi[a].insert(b);
        sus_cvorovi[b].insert(a);
    }
    set<int>vec_bio;
    for (int i=1; i<=n; i++)
    {
      vec_bio.clear();
      int brS=0, brI=0, brO=0;
      stablo(i, sus_cvorovi, grane, brS, brI, brO, vec_bio);
    }
    cout << s;
    return 0;
}