using System;
using System.Linq;
using System.Security.Cryptography;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int br = 0;
            int s = 0;
            int i = 0;
            int o = 0;
            string[] b = Console.ReadLine().Split();
            List<string> a = new List<string>();
            List<int> r = new List<int>();
            a.Add(b[0]);
            a.Add(b[1]);
            a.Add(b[2]);
            string a1 = "", b1 = "";
            if (b[2] == "S")
            {
                a1 = b[0];
                b1 = b[1];
            }
            for (int j = 1; j < n - 1; j++)
            {
                string[]u = Console.ReadLine().Split();
                a.Add(u[0]);
                a.Add(u[1]);
                a.Add(u[2]);
                if (u[2] == "S")
                {
                    a1 = u[0];
                    b1 = u[1];
                }
            }
            int x = (n - 1) * 3;
            for (int j = 0; j < x / 3; j++)
            {
                for (int k = 0; k < x; k += 3)
                {
                    for (int l = 0; l < x; l += 3)
                    {
                        if (((a[k] == a1 && a[k + 1] != b1) && ((a[l] == a[k] && a[l + 1] != b1 && a[l + 1] != a[k + 1]) ||
                        (a[l + 1] == a[k + 1] && a[l] != b1 && a[l] != a[k]))) ||
                        ((a[k + 1] == a1 && a[k] != b1) && ((a[l + 1] == a[k + 1] && a[l] != b1 && a[l] != a[k]) ||
                        (a[l] == a[k] && a[l + 1] != b1 && a[l + 1] != a[k + 1]))) &&
                        (((a[k + 2] == "O") && (a[l + 2] == "I")) || (a[k + 2] == "I") && (a[l + 2] == "O")))
                        {
                            br++;
                        }
                    }
                }
            }
            Console.WriteLine(br + 4);
        }
    }
}