#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll>vl1;
vl1 roda(300001);//parent node
vl1 ide(300001);//BFS queue
typedef vector<vl1> vl2;

void radiADJT(vl2& veza, vl2& slovo, ll& n, ll& naso)//no m
{ ll i, a, b, c;
  char ch1;
  naso=0;
  for(i=1;i<n;i++)
    { cin>>a>>b>>ch1;
      if(ch1=='S') c=1;
      else if(ch1=='I') c=2;
           else c=3;
      veza[a][0]++; veza[b][0]++;
      veza[a].push_back(b);
      veza[b].push_back(a);
      slovo[a][0]++; slovo[b][0]++;
      slovo[a].push_back(c);
      slovo[b].push_back(c);

      c=a-b;
      if(c>1 || c<-1) naso=1;
    }
}

void radiBFST(vl2& veza, vl2& slovo, vl2& ima, vl1& ide, vl1& roda, ll& kora, ll& suma)
{ ll i, j, k, tata, r, tmp, val, sl;
  roda[kora]=0;//start V
  ima[kora][1]=0; ima[kora][2]=0; ima[kora][3]=0;
  ide[1]=kora; i=1; k=1;

  while(i<=k)
    { val=ide[i];//radni nod
      tata= roda[val];
      r=veza[val][0];
      for(j=1;j<=r;j++)
       { tmp = veza[val][j];//dete za koje racunam
         if(tmp!=tata)
           { roda[tmp]=val;
             k++;
             ide[k]=tmp;
             sl=slovo[val][j];
             ima[tmp]=ima[val];
             ima[tmp][sl]++;
             if(ima[tmp][1]==ima[tmp][2] && ima[tmp][1]==ima[tmp][3])suma++;
           }
       }
      i++;
    }
}


int main()
{ ll i, j, k, kn, m, n, p, t, r, x, y, z, a, b, c;
  ll val, pos, kora, tmp, suma, maxa, mina, naso, tata, num, sl;
  string str1;
  char ch1;

     cin>>n;
     vl2 veza(n+1, vl1(1));
     vl2 slovo(n+1, vl1(1));
     vl2 ima(n+1, vl1(4));

     radiADJT(veza, slovo, n, naso);
     if(n<3) cout<<"0\n";
     else if(naso==0)// po redu
      { suma=0;
        ima[2][1]=0;ima[2][2]=0;ima[2][3]=0;
        sl=slovo[1][1];
        ima[2][sl]=1;

        for(i=3;i<=n;i++)
         { val=i-1;
           if(veza[val][1]==i) sl=slovo[val][1]; // koja je veza prava
           else sl=slovo[val][2];
           //cout<<"slovo "<<sl<<"\n";

           for(k=2;k<i;k++)
            { //cout<<ima[k][1]<<ima[k][2]<<ima[k][3]<<endl;
              ima[k][sl]++;
              if(ima[k][1]==ima[k][2] && ima[k][1]==ima[k][3]) suma++;
            }
           //ima[i][1]=0; ima[i][2]=0; ima[i][3]=0;
           ima[i][sl]=1;// put do roditelja
        }
       cout<<suma<<endl;

      }

     else
      { suma=0;
        for(i=1;i<=n;i++)
          { kora=i;//start V
            radiBFST(veza, slovo, ima, ide, roda, kora, suma);
          }
        suma>>=1;
        cout<<suma<<endl;
      }

  return 0;
}
/*
6
4 1 S
5 6 O
1 5 I
1 2 S
3 1 S


7
4 3 S
5 6 I
1 2 O
3 2 I
4 5 O
6 7 S

2
2 1 S

*/