#include<cstdio>
int main(){for(int n,a,c,r,t;c=0,r=scanf("%d",&n),n;printf("%d\n",r))for(char d[]="123456",s[9];n--;r+=*d-48)scanf("%s",s),*s%6-4?a=(*s-78?*s%5-1:0)+c&3,a+=a/2?2-a%2*2:1,t=*d,*d=d[a],d[a]=d[5],d[5]=d[5-a],d[5-a]=t:c+=*s+3;}