#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

ll sio(vector<pair<int, char> > a[], int n, int pocetak){
    ll broj = 0;
    bool used[n+1] = {false};
    ll s = 0, i = 0, o = 0;
    int u;
    queue<int> q;
    vector<pair<int, char> >::iterator it;
    q.push(pocetak);
    while(!q.empty()){
        u = q.front();
        q.pop();
        used[u] = true;
        for(it = a[u].begin();it != a[u].end();++it){
            if(!used[it->first]){
                q.push(it->first);
                if(it->second == 'S') s++;
                if(it->second == 'I') i++;
                if(it->second == 'O') o++;
                if(s > 0 && i > 0 && o > 0){
                    broj++;
                    s--;
                    i--;
                    o--;
                }
            }
        }
    }
    return broj;
}

ll prebroj(vector<pair<int, char> > a[], int n){
    //vector<pair<int, int> > parovi;
    ll broj = 0;
    for(int i = 1;i <= n;i++)
        broj += sio(a, n, i);
    return broj;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int u, v;
    char c;
    vector<pair<int, char> > a[n+1];
    for(int i = 0;i < n - 1;i++){
        cin >> u >> v >> c;
        a[u].push_back(make_pair(v, c));
        a[v].push_back(make_pair(u, c));
    }
    cout << prebroj(a, n)/2;
    return 0;
}