program proj;

var
  c:array[1..3] of char;
  a,b:array[1..100] of integer;
  n,i,p,k,m,j:integer;

begin
  readln(n);
  p:=0;
  for i:=1 to n-1 do
  readln (A[i],B[i],C[i]);
  for j:=1 to n-1 do
  if (c[j]='S') then
    for k:=1 to n-1 do if (A[k]=B[j]) then if (C[k]='I') then
      for m:=1 to n-1 do if (A[m]=B[k]) then if (C[m]='O') then p:=p+1;
  writeln(p);
  readln;
end..