import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { long euclid(long x,long y,long a,long b) { return a==0?y:euclid(y-b/a*x,x,b%a,a); } long inv(long a,long m) { if (a%m==0) return 0; long v=euclid(1, 0, (a%m+m)%m, m); return v<0?v+m:v; } long gcd(long a,long b) { return a==0?Math.abs(b):gcd(b%a,a); } long lcm(long a,long b) { return a/gcd(a,b)*b; } long pow(long a,long n,long p) { return n!=0?(pow(a,n/2,p)*(n%2==1?a:1)):1; } void pre(long[] a,long[] m) { int n=a.length; for (int i=0;i1) { m[j]/=g; a[j]%=m[j]; } else { m[i]/=g; a[i]%=m[i]; } } } } long mul(long a,long b,long m) { a=(a%m+m)%m;b=(b%m+m)%m; if (a==0) return 0; if (a==1) return b%m; if (a%2==1) return (mul(a-1,b,m)+b)%m; return 2*mul(a/2,b,m)%m; } long garner(long[] a,long[] m) { pre(a,m); long ret=0,prd=1; for (int i=0;iD_*denominator) break; long sign_x=(vx_/denominator%(2*W_)*T%(2*W_)+sx_)%(2*W_); long sign_y=(vy_/denominator%(2*H_)*T%(2*H_)+sy_)%(2*H_); if (sign_x<0) sign_x-=W_; if (sign_y<0) sign_y-=H_; if (Math.abs(sign_x)/W_%2!=i) continue; if (Math.abs(sign_y)/H_%2!=j) continue; ans|=true; } } } return ans; } void run() { FastScanner sc=new FastScanner(); PrintWriter pw=new PrintWriter(System.out); int Q=sc.nextInt(); for (int q=0;q