main()
{
  int n,a,b,c,x,y,f;
  while(1){
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&x);
    if(!n)break;
    for(f=0;n-->0;){
    scanf("%d",&y);
    while(x!=y&&f<10000)
      {
	f++;
	x=(a*x+b)%c;
      }
    }
    if(f==10000)
      f=-1;
    printf("%d\n",f);
  }
}