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

namespace takmicenje1
{
    class Program
    {
        public static int TraziParove(string[,] grane, int N)
        {
            int brojParova = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (grane[i, 0] == "S")
                {
                    for(int j = 0; j < N - 1; j++)
                    {
                        if (grane[j, 0] == "I" && (grane[j, 1] == grane[i, 1] || grane[j, 1] == grane[i, 2] || grane[j, 2] == grane[i, 1] || grane[j, 2] == grane[i, 2]))
                        {
                            for (int k = 0; k < N - 1; k++)
                            {
                                if(grane[k, 0] == "O" && (grane[k, 1] == grane[j, 1] || grane[k, 1] == grane[j, 2] || grane[k, 2] == grane[j, 1] || grane[k, 2] == grane[j, 2]))
                                {
                                    brojParova++;
                                }
                            }
                        }
                        else continue;
                    }
                }
            }

            return brojParova;
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[,] grane = new string[N - 1, 3];
            for (int i = 0; i < N - 1; i++)
            {
                string[] unos = Console.ReadLine().Split();
                string tempBroj = unos[0];
                unos[0] = unos[2];
                unos[2] = tempBroj;
                if (int.Parse(unos[1]) > int.Parse(unos[2]))
                {
                    string temp = unos[1];
                    unos[1] = unos[2];
                    unos[2] = temp;
                }
                for (int j = 0; j < 3; j++)
                {
                    grane[i, j] = unos[j];
                }
            }
            int broj = TraziParove(grane, N);
            Console.WriteLine(broj);
        }
    }
}