#include <bits/stdc++.h>

using namespace std;

struct Grana
{
    char c;
    int u, v;

    Grana()
    {
        this->c = ' ';
        this->u = 0;
        this->v = 0;

    }

    Grana(int u, int v, char c)
    {
        this->u = u;
        this->v = v;
        this->c = c;
    }
};

char c[] = {'S', 'I', 'O'};
bool grane_cmp(const Grana &g1, const Grana &g2)
{
    int x, y;

    for(int i=0; i < 3; i++)
    {
        if(c[i] == g1.c)
            x = i;
        else if (c[i] == g2.c)
            y = i;
    }

    return x < y;
}

struct Kombinacija
{
    Grana *s, *i, *o;

    Kombinacija()
    {
        this->s = NULL;
        this->i = NULL;
        this->o = NULL;
    }

    Kombinacija(Grana *s, Grana *i, Grana *o)
    {
        this->s = s;
        this->i = i;
        this->o = o;
    }

    bool validna()
    {
        return this->s && this->i && this->o;
    }
};

int ans = 0;

void br_kombinacija(Grana *g, int s, int char_index)
{
    if(char_index == 3)
    {
        ans++;
        return;
    }
    else
    {
        for(int i=0; i < s; i++)
        {
            if (g[i].c == c[char_index])
            {
                br_kombinacija(g, s, char_index+1);
            }
        }
    }
}

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

    int n;
    cin >> n;
    Grana grane[n-1];

    for(int i=0; i < n-1; i++)
    {
        cin >> grane[i].u >> grane[i].v >> grane[i].c;
    }
    //sort(grane, grane+n-1, grane_cmp);

    br_kombinacija(grane, n-1, 0);
    cout << ans;

    return 0;
}