ll@T;rep(T){ll@K,@--M,@N,A[N]{},u[K]{},t=0,s,b=M,j=0;rep[A](a,N){if(u[t]+u[s=(t+M)%K]<1)u[a=t]=u[s]=1;else if(b){b=0;while(j