using System;

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] s = new char[N];
            string s1 = "";
            int br = 0, i = 0, j = 1, pom1 = 0, pom2 = 0;
            int[] U = new int[N], V = new int[N];
            for (i = 1; i <= N - 1; i++)
            {
                string[] inf = Console.ReadLine().Split();
                U[i] = Int32.Parse(inf[0]);
                V[i] = Int32.Parse(inf[1]);
                s[i] = Char.Parse(inf[2]);
            }
            for (i = 1; i < N; i++)
            {
                j = 1;
                while(j<N)
                {
                    if (s[i] == 'S' && s1 != "S" && s1 != "SI")
                    {
                        pom1 = U[i];
                        pom2 = V[i];
                        s1 += 'S';
                        j++;
                    }
                    else
                    if (s[j] == 'I' && s1 == "S" && s1 != "SI" && (U[j] == pom1 || U[j] == pom2 ||  V[j] == pom1 || V[j] == pom2))
                    {
                        pom1 = U[j];
                        pom2 = V[j];
                        s1 += 'I';
                        j++;
                    }
                    else
                    if (s[j] == 'O' && s1 == "SI" && (U[j] == pom1 || U[j] == pom2 || V[j] == pom1 || V[j] == pom2))
                    {
                        j = 1;
                        br++;
                        s1 += 'O';
                        pom1 = U[j];
                        pom2 = V[j];
                        s1 = "";
                    }
                    else
                    j++;
                }
            }
            Console.WriteLine(br);
        }
    }
}