using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        struct branch 
        {
            public int x;
            public int y;
            public char c;
        }

        static int solve(branch x,branch y, int j, string s, branch[] all, ref int rez, int f, int c) 
        {
            s += x.c;
            if (j == 2)
            {
                rez++;
                return 0;
            }
            j++;
            if (j == 1)
            {
                for (int i = f; i < c ; i++)
                {
                    if (x.x == all[i].x || x.x == all[i].y || x.y == all[i].x || x.y == all[i].y) solve(all[i],x, j, s, all, ref rez, f, c);
                }
            }
            else 
            {
                for (int i = c; i < all.Length; i++)
                {
                    if ((x.x == y.x || x.x == y.y))
                    {
                        if (x.y == all[i].x || x.y == all[i].y) solve(all[i], x, j, s, all, ref rez, f ,c);
                    }
                    else
                    {
                        if (x.x == all[i].x || x.x == all[i].y) solve(all[i], x, j, s, all, ref rez, f ,c);
                    }
                }
            }
            return 0;
        }


        
        static void Main(string[] args)
        {
            //--------input

            int n = int.Parse(Console.ReadLine());
            string[] s;
            branch[] all = new branch[n - 1];
            for(int i = 0; i < n - 1; i++)
            {
                s = Console.ReadLine().Split();
                all[i].x = int.Parse(s[0]);
                all[i].y = int.Parse(s[1]);
                all[i].c = char.Parse(s[2]);
            }
            int f = 0;
            for (int i = 0; i < n - 1; i++) 
            { 
                if (all[i].c == 'S') 
                { 
                    branch temp = all[f];
                    all[f] = all[i];
                    all[i] = temp;
                    f++;
                }
            }
            int c = f;
            for (int i = c; i < n - 1; i++)
            {
                if (all[i].c == 'I')
                {
                    branch temp = all[c];
                    all[c] = all[i];
                    all[i] = temp;
                    c++;
                }
            }
            //Console.WriteLine("-------");
            //for (int i = 0; i < n - 1; i++)
            //{
            //    Console.WriteLine(all[i].x + " " + all[i].y + " " + all[i].c );
            //}

            //----x---input
            int j = 0;
            int rez = 0;
            string s1 = "";
            for (int i = 0; i < f ;i++)
            {
                solve(all[i],all[i], j, s1, all, ref rez, f, c);
            }
            //solve(all[0], all[0], j, s1, all, ref rez, f, c);
            Console.WriteLine(rez);
            
            Console.ReadKey();

        
        
        }
    }
}