#include <iostream>

using namespace std;

struct node
{
    char linfo, rinfo;
    int left = 0, right = 0;
};

node drvo[300001];
bool used[300001];

int single_check( int start, int scnt, int icnt, int ocnt, int cnt )
{
    if(cnt == 0)
    {
        if( scnt == icnt == ocnt == 1 )
            return 1;
        return 0;
    }
    return single_check( drvo[start].left, scnt+(drvo[start].linfo == 'S'), icnt+(drvo[start].linfo == 'I'), ocnt+(drvo[start].linfo == 'O'), (cnt-1) );
    return single_check( drvo[start].right, scnt+(drvo[start].rinfo == 'S'), icnt+(drvo[start].rinfo == 'I'), ocnt+(drvo[start].rinfo == 'O'), (cnt-1) );
}

int special_check( int start )
{
    if( drvo[start].linfo != drvo[start].rinfo && drvo[start].left != 0 && drvo[start].right != 0 )
    {
        return (drvo[drvo[start].left].left!=0 && drvo[drvo[start].left].linfo!=drvo[start].linfo &&
                drvo[drvo[start].left].linfo!=drvo[start].rinfo) + (drvo[drvo[start].left].left!=0 &&
                drvo[drvo[start].left].rinfo!=drvo[start].linfo && drvo[drvo[start].left].rinfo!=drvo[start].rinfo) +
                (drvo[drvo[start].right].left!=0 && drvo[drvo[start].right].linfo!=drvo[start].linfo &&
                drvo[drvo[start].right].linfo!=drvo[start].rinfo) + (drvo[drvo[start].right].left!=0 &&
                drvo[drvo[start].right].rinfo!=drvo[start].linfo && drvo[drvo[start].right].rinfo!=drvo[start].rinfo);
    }
    return 0;
}

int check( int start, int scnt, int icnt, int ocnt, int cnt )
{
    if(start == 0)
        return 0;
    if(cnt == 0)
    {
        if( scnt == icnt == ocnt == 1 )
            return 1 + check(start, 0, 0, 0, 2);
        return 0;
    }
    return check( drvo[start].left, scnt+(drvo[start].linfo == 'S'), icnt+(drvo[start].linfo == 'I'), ocnt+(drvo[start].linfo == 'O'), (cnt-1) );
    return check( drvo[start].right, scnt+(drvo[start].rinfo == 'S'), icnt+(drvo[start].rinfo == 'I'), ocnt+(drvo[start].rinfo == 'O'), (cnt-1) );
}

int solve(int head)
{
    if(head == 0)
        return 0;
    return check(head, 0, 0, 0, 2) + special_check(head) + solve(drvo[head].left) + solve(drvo[head].right);
}

int main(void)
{
    int n, u, v;
    char c;

    cin >> n;
    for( int i = 0; i < n-1; i++ )
    {
        cin >> u >> v >> c;
        if( drvo[u].left != 0 )
        {
            drvo[u].right = v;
            drvo[u].rinfo = c;
        }
        else
        {
            drvo[u].left = v;
            drvo[u].linfo = c;
        }
        used[v] = 1;
    }

    int head = 1, extra = 0;
    while(used[head] != 0)
        head++;
    int head1 = head+1;
    while(head1<n)
    {
        extra += single_check(head1, 0, 0, 0, 2);
        head1++;
    }

    cout << solve(head)+extra;

    return 0;
}