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

int const l = 300000;
vector<pair<int, char>> adj[l+1];
vector<bool> visited(l+1, false);
int ans = 0;

void dfs(int node, int start_node, int cnt_s, int cnt_i, int cnt_o)
{
    if (visited[node]) return;
    visited[node] = true;

    if (cnt_i == cnt_o && cnt_o == cnt_s && cnt_i != 0) {
        ans += cnt_i;
        cnt_i = 0; cnt_o = 0; cnt_s = 0;
        return;
    }

    for (auto u : adj[node]) {
        if (node == start_node) {cnt_i = 0; cnt_o = 0; cnt_s = 0;}
        if (!visited[u.first]) {
            if (u.second == 'S') cnt_s++;
            else if (u.second == 'I') cnt_i++;
            else cnt_o++;
            dfs(u.first, start_node, cnt_s, cnt_i, cnt_o);
        }
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> start;
    for (int i = 0; i < n-1; i++) {
        int a, b; char c;
        cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
        if (c == 'S') {
            start.push_back(a);
            start.push_back(b);
        }
    }
    for (int i = 0; i < start.size(); i++) {
        fill(visited.begin(), visited.begin() + n + 1, false);
        dfs(start[i], start[i], 0, 0, 0);
    }
    cout << ans << "\n";
    return 0;
}