#include <bits/stdc++.h>
#define mod 998244353
#define gcd __gcd
#define ll long long
#define ull unsigned long long
#define inf 1e15
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define pii pair<int,int>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
using namespace std;
#define maxn 3005
int n;
char a[maxn];
char v[maxn][maxn];
int ans = 0;
bool bio[maxn];
void bfs(int x){
    queue<int> q;
    q.push(x);
    fill(bio,bio+n+1,0);
    vector<int> a(maxn);
    a[x] = x;
    while(!q.empty()){
        int u = q.front();
        q.pop();
        if(bio[u]) continue;
        bio[u] = 1;
        for(int i = 1;i<=n;i++){
            if(i==u) continue;
            if(v[u][i]=='w') continue;
            q.push(i);
            if(a[i]==0)a[i] = u;
        }
    }

    int s = 0,i = 0,o = 0;
    /*for(int i = 1;i<=n;i++) cerr<<a[i]<<" ";
    cerr<<endl;*/
    for(int k = 1;k<=n;k++){
        s = 0,i = 0,o = 0;
        int j = k;
        if(k==x) continue;
        while(j!=x){
            if(v[j][a[j]]=='S') s++;
            else if(v[j][a[j]]=='I') i++;
            else o++;
            j = a[j];
        }
        if(s==i&&i==o){
            ans++;
            //cerr<<k<<" "<<x<<"\n";
        }
    }
    return;
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n;
    int a,b;
    char d;
    for(int i = 1;i<=n;i++) fill(v[i]+1,v[i]+n+1,'w');
    for(int i = 0;i<n-1;i++){
        cin >> a >> b >> d;
        v[a][b] = d;
        v[b][a] = d;
    }
    /*for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            cerr<<v[i][j]<< " ";
        }
        cerr<<"\n";
    }*/
    for(int i = 1;i<=n;i++){
        //cerr<<"bfs"<<i<<"\n";
        bfs(i);
    }
    cout<<ans/2;
    return 0;
}