/*
AizuOnline A1103
Board Arrangements for Concentration Games
*/
#include <stdio.h>

char  tehai[45];
int haiti[]={1,2,3,4,11,12,13,14,21,22,23,24,31,32,33,34};

int rel_pos[]={10,21,22,33};
int cnt;
char dummy;

void showhand(char mark)
{
  /*
  int i,j,k;

  printf("%c",mark);
  for(i=0;i<4;i++)
    {
      for(j=0;j<=4;j++)
        if(tehai[k=i*10+j])
          printf("%d",k);
      printf("/");
    }
  printf("\n");
  */
  /*
    scanf("%c",&dummy);
  */
}

void isagari()
{ int i,j;

  showhand('B');

  for(i=0;i<45;i++)
    if(tehai[i])
      goto NEXT;
  cnt++;
  return;

 NEXT:
  for(i=0;i<45;i++)
    {  
      if(tehai[i]==0)
	continue;
      for(j=0;j<4;j++)
	{
	  if( tehai[i+rel_pos[j]])
	    {  tehai[i]--;
	      tehai[i+rel_pos[j]]--;
	      isagari();
	      tehai[i]++;
	      tehai[i+rel_pos[j]]++;
	    }
	}
      break;
    }
    return;
}

int main()
{
  
  int  i;
  int ret;
  int c;
  int a1,a2,a3,a4,a5,a6,a7,a8;
  char buf[256];

  while(NULL != fgets(buf,200,stdin))
    {
      sscanf(buf,"%d %d %d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8);
    
      if(a1 > 4)break;

      rel_pos[0]=a1+a2*10;
      rel_pos[1]=a3+a4*10;
      rel_pos[2]=a5+a6*10;
      rel_pos[3]=a7+a8*10;
      /*      printf("%d\n",rel_pos[0]); */
      for(i=0;i<45;i++)
	tehai[i]=0;
 
      for(i=0;i<16;i++)
	tehai[haiti[i]]=1;

      cnt = 0;
  /*  showhand('A'); */ 
      
      isagari();  
      printf("%d\n",cnt);
    }
  return(0);
}