#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Grana
{
private:
    long long unsigned int u,v;
    char SIO;
public:
    Grana(long long unsigned int U, long long unsigned int V, char sio)
    {
        u=U;
        v=V;
        SIO=sio;
    }
    char GetC()
    {
        return SIO;
    }
    long long unsigned int  getU(){return u;}
    long long unsigned int  getV(){return v;}
};
class Graf
{
private:
    long long unsigned int N;
    vector<Grana> adj;
public:
    Graf(long long unsigned int n)
    {
        N=n;
    }
    void add_Edge(Grana g)
    {
        adj.push_back(g);
    }
    vector<Grana> getGrane()
    {
        return adj;
    }
};
int main(int argc, const char * argv[]) {
    long long unsigned int N,a,b;
    char c;
    cin>>N;
    N--;
    Graf G(N);
    for (long long unsigned int i =0 ; i < N; i ++)
    {
        cin>>a>>b>>c;
        Grana g(a,b,c),g1(b,a,c);
        G.add_Edge(g);
        
    }
    vector <Grana>S,I,O;
    for (long long unsigned int i=0; i < N; i++)
    {
        if (G.getGrane()[i].GetC()=='S')
        {
            S.push_back(G.getGrane()[i]);
        }
        if (G.getGrane()[i].GetC()=='I')
        {
            I.push_back(G.getGrane()[i]);
        }
        if (G.getGrane()[i].GetC()=='O')
        {
            O.push_back(G.getGrane()[i]);
        }
    }
    
    long long unsigned int brojac=0;
    for (auto j = I.begin(); j != I.end(); j ++)
    {
        for (auto z = O.begin(); z < O.end(); z ++)
        {
            if ((*j).getU()==(*z).getU()||(*j).getV()==(*z).getU()||(*j).getU()==(*z).getV()||(*j).getV()==(*z).getV())
            {
                
            }
            else
            {
                I.erase(j);
                O.erase(z);
            }
        }
    }
    for ( auto i = 0; i <S.size(); i ++)
    {
        for (auto j = 0; j <I.size(); j ++)
        {
            if (S[i].getU()==I[j].getU()||S[i].getV()==I[j].getU()||S[i].getU()==I[j].getV()||S[i].getV()==I[j].getV())
            {
                brojac++;
            }
        }
    }
    cout<<brojac;
    return 0;
}