#include <bits/stdc++.h>

using namespace std;

struct branch
{
    char s;
    int p,k;
};

struct node
{
    vector<branch> connections;
};

int res = 0;

void DFS(int v, node nodes[], bool visited[], int bS, int bI,  int bO, int p)
{
    visited[v] = true;

    if(bS == bI && bI == bO && bS != 0)
    {
        //cout << "Starting node is " << p+1 << " currently on node " << v+1 << " SIO is " << bS << " " << bI << " " << bO << endl;
        res++;
    }


    for(int i = 0; i<nodes[v].connections.size(); i++)
    {
        if(!visited[nodes[v].connections[i].k])
        {
            switch(nodes[v].connections[i].s)
            {
            case 'S':
                DFS(nodes[v].connections[i].k, nodes, visited,bS+1,bI,bO, p);
                break;
            case 'I':
                DFS(nodes[v].connections[i].k, nodes, visited,bS,bI+1,bO, p);
                break;
            case 'O':
                DFS(nodes[v].connections[i].k, nodes, visited,bS,bI,bO+1, p);
                break;
            }
        }
    }

}

void isSIO(int p,node nodes[], int N)
{
    int S = 0,I = 0,O = 0;

    bool visited[N];
    for (int i = 0; i < N; i++)
        visited[i] = false;
    visited[p] = true;

    DFS(p,nodes,visited,S,I,O,p);
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    /*for(int i = 1;i<=6;i++)
    {
        for(int j = i+1;j<=6;j++)
        {
            cout << i <<" " << j << endl;
        }
    }*/

    int N;
    cin >> N;

    node nodes[N];

    for(int i = 0; i<N-1; i++)
    {
        branch p;
        cin >> p.p >> p.k >> p.s;
        p.p--;
        p.k--;
        nodes[p.p].connections.push_back(p);
        swap(p.p,p.k);
        nodes[p.p].connections.push_back(p);
    }

    /*for(int i = 0; i<N; i++)
    {
        cout << "Node " << i+1 << ":" << endl;
        for(int j = 0; j<nodes[i].connections.size(); j++)
        {
            cout << nodes[i].connections[j].k+1 << " ";
        }
        cout << endl;
    }*/

    for(int i = 0; i<N; i++)
    {
        isSIO(i,nodes,N);
    }

    cout << res/2;


    return 0;
}