#include<bits\stdc++.h>

using namespace std;

int sio[10000];
vector<int> g[10000];
bool v[10000]

void f(int x)
{
	v[x] = 1;
	for(int i = 0; i < g[x].size(); i++)
	{
		if(v[x] == 0) f(x);
		sio[x] *= sio[g[x][i]];
	}
}

int main()
{
	int n;
	cin>>n;
	for(int i = 0; i < n - 1; i++)
	{
		char c;
		int k1, k2;
		cin>>c>>c>>k1>>k2;
		switch(c)
		{
			case 'S':
				sio[i] = 2;
			case 'I':
				sio[i] = 3;
			case 'O':
				sio[i] = 5;
			default:
				break;
		}
		g[k1].push_back(k2);
		g[k2].push_back(k1);
	}
	f(0);
}