#include<bits/stdc++.h>
using namespace std;
const int N = 3e5+5;
map<pair<int,int>,char> m;
vector<int> g[N];

int dfs(int s, int p, char c, int dep){
    if(dep==2)return 1;
    int ret=0;
    for(int e:g[s]){
        if(e!=p && m[{s,p}]!=m[{e,s}]){
            ret+=dfs(e,s,m[{e,s}], dep+1);
        }
    } 
    return ret;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,i,v,u,x,rs,rp; cin>>n;
    char c;
    for(i=0;i<n-1;++i){
        cin>>v>>u>>c;
        m[{v,u}]=c;
        m[{u,v}]=c;
        g[u].push_back(v);
        g[v].push_back(u);
        if(c=='S'){
            rs=u;
            rp=v;
        }
    }
    
    cout << dfs(rs,rp,'S',0) + dfs(rp,rs,'S',0) << '\n';
}