#include<bits/stdc++.h>
using namespace std;

int maincounter = 0;
char cvorovi[3000][3000];
int main()
{
	int n;
	cin >> n;
	string slova = "";
	for (int i=0;i<(n-1);i++)
	{
		int u;
		int v;
		char type;
		cin >> u;
		cin >> v;
		cin >> type;
		cvorovi[u-1][v-1] = type;
		//cvorovi[v][u] = type;
	}
	for (int i=1;i<(n);i++)
	{
		for (int j=0;j<(n);j++)
		{
			if (cvorovi[j][i] != 0)
			{
				slova = slova + cvorovi[j][i];
				//slova += '\0';
			}
		}
	}
	for (int i=0;i<slova.length();i++)
	{
		char first = 'S';
		char second = slova[0];
		int counter = 0;
		int secondcounter = 0;
		int thirdcounter = 0;
		if (slova[i] == first and secondcounter == 0)
		{	
			for (int i=0;i<slova.length();i++)
			{
				char first = 'O';
				char second = slova[0];
				int counter = 0;
				int secondcounter = 0;
				int thirdcounter = 0;
				if (slova[i] == first and secondcounter == 0)
				{	
					for (int i=0;i<slova.length();i++)
					{
						char first = 'S';
						char second = slova[0];
						int counter = 0;
						int secondcounter = 0;
						int thirdcounter = 0;
						if (slova[i] == first and secondcounter == 0)
						{
							if (counter==secondcounter and secondcounter==thirdcounter)
							{
								maincounter++;
							}
							else
							{
								counter = 0;
								secondcounter = 0;
								thirdcounter = 0;
							}
							counter++;
						}
						else if (slova[i] != first and secondcounter == 0)
						{
							second = slova[i];
							secondcounter++;
						}
						else if (slova[i] == second and secondcounter != 0)
						{
							secondcounter++;
						}
						else if (slova[i] != second and secondcounter != 0)
						{
							thirdcounter++;
						}
					}
					if (counter==secondcounter and secondcounter==thirdcounter)
					{
						maincounter++;
					}
					else
					{
						counter = 0;
						secondcounter = 0;
						thirdcounter = 0;
					}
					counter++;
				}
				else if (slova[i] != first and secondcounter == 0)
				{
					second = slova[i];
					secondcounter++;
				}
				else if (slova[i] == second and secondcounter != 0)
				{
					secondcounter++;
				}
				else if (slova[i] != second and secondcounter != 0)
				{
					thirdcounter++;
				}
			}
			if (counter==secondcounter and secondcounter==thirdcounter)
			{
				maincounter++;
			}
			else
			{
				counter = 0;
				secondcounter = 0;
				thirdcounter = 0;
			}
			counter++;
		}
		else if (slova[i] != first and secondcounter == 0)
		{
			second = slova[i];
			secondcounter++;
		}
		else if (slova[i] == second and secondcounter != 0)
		{
			secondcounter++;
		}
		else if (slova[i] != second and secondcounter != 0)
		{
			thirdcounter++;
		}
	}
	cout << maincounter << endl;
}