#import<cstdio>
int main(){int a,c=3,r=1;for(char d[]="123546",s[9];a=scanf("%s",s),*s>60;r+=*d&7)*s%6-4?a+=*s%5+*s%2*2+c&3,d[a]=*d,*d=d[a=++a%4+1],d[a]=d[5],d[5]=~*d:c+=*s+3;~-r&&printf("%d\n",r);~a&&main();}