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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int k = 0;
            // int[] putevi = new int[n];
            int ss = 0;
            int ii = 0;
            int oo = 0;
            int res = 0;
            string[] s;
            int i = 0;
            int j = 0;
            string[,] put = new string[n + 1, n + 1];
            while (k < n - 1)
            {
                s = Console.ReadLine().Split();
                i = int.Parse(s[0]);
                j = int.Parse(s[1]);
                put[i, j] = s[2];
                put[j, i] = s[2];
                k++;

            }
            k = 1;
            int k1 = 1;
            int p = 1;
            while (k < n+1) 
            {
                p = k + 1;
                k1 = k;
                while (p < n+1)
                {
                    if (put[k1, p] == "S")
                    {
                        ss++;
                        put[k1, p] = "";
                        k1 = p;
                        p = 1;
                    }
                    else if (put[k1, p] == "I")
                    {
                        ii++;
                        put[k1, p] = "";
                        k1 = p;
                        p = 1;
                    }
                    else if (put[k1, p] == "O")
                    {
                        oo++;
                        put[k1, p] = "";
                        k1 = p;
                        p = 1;
                    }
                    else
                    {
                        p++;
                    }
                    if (ss == ii && ss == oo)
                    {
                        res++;
                    }
                   
                }
                ss = 0;
                ii = 0;
                oo = 0;
                k++;
            }
          Console.WriteLine(res/3);
            //Console.ReadLine();
        }
    }
}