// #includes {{{ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; // }}} // pre-written code {{{ #define REP(i,n) for(int i=0;i<(int)(n);++i) #define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i) #define LET(x,a) __typeof(a) x(a) //#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i) #define ALL(c) (c).begin(), (c).end() #define MP make_pair #define EXIST(e,s) ((s).find(e)!=(s).end()) #define RESET(a) memset((a),0,sizeof(a)) #define SET(a) memset((a),-1,sizeof(a)) #define PB push_back #define DEC(it,command) __typeof(command) it=command const int INF=0x3f3f3f3f; typedef long long Int; typedef unsigned long long uInt; #ifdef __MINGW32__ typedef double rn; #else typedef long double rn; #endif typedef pair pii; /* #ifdef MYDEBUG #include"debug.h" #include"print.h" #endif */ // }}} //{{{ gcd and inverse Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; } Int lcm(Int a, Int b) { return a / gcd(a, b) *b; } // a x + b y = gcd(a, b) Int extgcd(Int a, Int b, Int &x, Int &y) { Int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; } Int invMod(Int a, Int m) { Int x, y; if (extgcd(a, m, x, y) == 1) return (x + m) % m; else return 0; // unsolvable } //}}} int Q; int W,H,Mx,My,Hx,Hy,Vx,Vy; Int D; bool vis[100][100]; int main(){ cin>>Q; REP(i,Q){ memset(vis,false,sizeof(vis)); cin>>W>>H>>D>>Mx>>My>>Hx>>Hy>>Vx>>Vy; int g = gcd(abs(Vx),abs(Vy)); D*=g; Vx/=g;Vy/=g; int t=0; int x = Hx, y = Hy; bool hit = false; while(t<=D){ if((x==Mx and y==My) or (x==W*2-Mx and y==My) or (x==Mx and y==H*2-My) or (x==W*2-Mx and y==H*2-My)){ hit = true; break; } x+=Vx;y+=Vy; while(x<0)x+=W*2; while(x>=W*2)x-=W*2; while(y<0)y+=H*2; while(y>=H*2)y-=H*2; assert(0<=x and x