#include <bits/stdc++.h>
#define MAXN 300010
using namespace std;

vector<pair<int, int> > a[MAXN];
bool pos[MAXN];
int res;

void dfs(int s, int x, int y)
{
    pos[s] = true;
    if(x > 1 || y > 1)
    {
        return;
    }
    if(x == 1 && y == 1)
    {
        res++;
        return;
    }
    for(int i = 0; i < a[s].size(); i++)
    {
        int v = a[s][i].first;
        if(!pos[v] && a[s][i].second != 1)
        {
            if(a[s][i].second == 2)
            {
                dfs(v, x + 1, y);
            }
            else
            {
                dfs(v, x, y + 1);
            }
        }
    }
}

int main()
{
    int n;
    cin >> n;
    int idx1, idx2;
    for(int i = 0; i < n - 1; i++)
    {
        int u, v;
        char W;
        cin >> u >> v >> W;
        int w;
        if(W == 'S')
        {
            idx1 = u;
            idx2 = v;
            w = 1;
        }
        else if(W == 'I')
        {
            w = 2;
        }
        else
        {
            w = 3;
        }

        a[u].push_back({v, w});
        a[v].push_back({u, w});
    }

    dfs(idx1, 0, 0);
    dfs(idx2, 0, 0);
    int a1 = 0, b1 = 0, a2 = 0, b2 = 0;
    for(int i = 0; i < a[idx1].size(); i++)
    {
        if(a[idx1][i].second == 2)
        {
            a1++;
        }
        else if(a[idx1][i].second == 3)
        {
            b1++;
        }
    }
    for(int i = 0; i < a[idx2].size(); i++)
    {
        if(a[idx2][i].second == 2)
        {
            a2++;
        }
        else if(a[idx2][i].second == 3)
        {
            b2++;
        }
    }
    cout << res + min(a1, b2) + min(a2, b1) << endl;

    return 0;
}