#include <bits/stdc++.h>

using namespace std;

struct edge
{
    int v2;
    string sl;
};

void addEdge(vector<edge> v[],int x,int y,string z)
{
    struct edge ivica1={y,z};
    struct edge ivica2={x,z};
    v[x].push_back(ivica1);
    v[y].push_back(ivica2);
}

void DFS(vector<edge> v[],bool vis[],int x,vector<int> my_stack,int brs,int bri,int bro,int &br)
{
    my_stack.push_back(x);
    if(my_stack[0]<x)
        if((brs==bro)&&(bro==bri))
            br+=1;
    vis[x]=true;
    if(!v[x].empty())
    {
        for(int j=0;j<v[x].size();j++)
        {
            if (vis[v[x][j].v2]==false)
            {
                string string1="S";
                string string2="I";
                if(v[x][j].sl==string1)
                    DFS(v,vis,v[x][j].v2,my_stack,brs+1,bri,bro,br);
                else
                {
                    if(v[x][j].sl==string2)
                        DFS(v,vis,v[x][j].v2,my_stack,brs,bri+1,bro,br);
                    else
                        DFS(v,vis,v[x][j].v2,my_stack,brs,bri,bro+1,br);
                }
            }
        }
    }
    my_stack.pop_back();
}

void DFSCall(int x,vector<edge> v[],int n,vector<int> my_stack,int &br)
{
    bool vis[n+1];
    memset(vis,false,sizeof(vis));
    int brs=0,bri=0,bro=0;
    DFS(v,vis,x,my_stack,brs,bri,bro,br);
}

int main()
{
    int n,q,w,br=0;
    string e;
    cin>>n;
    n+=1;
    vector<edge> v[n];
    vector<int> my_stack;
    for(int i=0;i<n-2;i++)
    {
        cin>>q>>w>>e;
        addEdge(v,q,w,e);
    }
    for(int i=0;i<n-1;i++)
        DFSCall(i+1,v,n,my_stack,br);
    cout<<br<<endl;
    return 0;
}