p,q,x,y,s; gcd(x,y){return y?gcd(y,x%y):x;} main(){ scanf("%d%d%*d",&p,&q); x=gcd(p+q,p-q);y=gcd(p,q); p=x;q=y; for(;~scanf("%d%d",&x,&y);s+=!((x%q)|(y%q)|((x+y)%p))); s=!printf("%d",s); }