#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;
#include <chrono>
using namespace std::chrono;
#define maxn 3005
int n;
char a[maxn][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++){
        for(int e = k+1;e<=n;e++){
            int j = e;
            int s=0,i=0,o=0;
            while(j!=k){
                if(v[j][a[j]]=='S') s++;
                else if(v[j][a[j]]=='I') i++;
                else o++;
                j = a[j];
            }
            if(s==i&&i==0) ans++;
        }
    }
    return;
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	auto start = high_resolution_clock::now();
    cin >> n;
    int a,b;
    char d;
    for(int i = 1;i<=n;i++) fill(v[i]+1,v[i]+n+1,'w');
    int c = 0;
    vector<char> g(n+1);
    for(int i = 0;i<n-1;i++){
        cin >> a >> b >> d;
        v[a][b] = d;
        v[b][a] = d;
        g[min(a,b)] = d;
        if(abs(a-b)==1) c++;
    }
    if(c==n-1){
        vector<vector<int> >vec(n+1,vector<int>(3,0));
        int s = 0,i = 0,o = 0;
        map<pair<pii,int>,int > mp;
        mp[{{0,0},0}] = 1;
        for(int j = 1;j<=n-1;j++){
            if(g[j]=='S') s++;
            else if(g[j]=='I') i++;
            else o++;
            //cerr<<s<< " "<<i<<" " <<o<<"\n";
            int f = min(s,min(i,o));
            for(int k = f;k>=0;k--){
                 ans+=mp[{{s-k,i-k},o-k}];
            }
            mp[{{s,i},o}]++;
        }
        cout<<ans;
        return 0;
    }
    /*for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            cerr<<v[i][j]<< " ";
        }
        cerr<<"\n";
    }*/
    bfs(1);
    cout<<ans/2;
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    cout << duration.count() << endl;
    return 0;
}
/*
5
1 2 S
2 3 I
3 4 O
4 5 S
*/
/*
7
1 2 S
2 3 I
3 4 O
4 5 S
5 6 O
6 7 I
*/