#include <cstdio>

using namespace std;

int main(){
	int n; 
	scanf("%d", &n); 
	n--; 
	int a[n][2]; 
	char b[n]; 
	int imati[n], imamSlovo[3];
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < 2 ; j++){
			scanf("%d", &a[i][j]); 
		}
		scanf("%s", &b[i]); 
		imati[i] = 0;
	}
	imamSlovo[0] = 0; 
	imamSlovo[1] = 0; 
	imamSlovo[2] = 0; 
	int br = 0;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < 2; j++){
			imati[i] = a[i][j]; 
			for(int u = 0 ; u < i ; u++){
				for(int s = 0 ; s < 2 ; s++){
					if(imati[u] == a[u][s]){
						switch(b[u]){
							case 'S':
								imamSlovo[0]++; 
								break; 
							case 'I':
								imamSlovo[1]++; 
								break; 
							case 'O':
								imamSlovo[2]++; 
								break; 
						}
					}
				}	
			}
			int mi = imamSlovo[0]; 
			if(imamSlovo[1] < mi) mi = imamSlovo[1]; 
			if(imamSlovo[2] < mi) mi = imamSlovo[2]; 
			br += mi; 
			imamSlovo[0] = 0;
			imamSlovo[1] = 0; 
			imamSlovo[2] = 0; 
		}	
	}
	br--; 
	printf("%d", br); 
	return 0;
}