#include <bits/stdc++.h>

using namespace std;

#define FST first
#define SND second

#define EPS (1e-5)

typedef complex<double> P;
typedef pair<P,P> SEG;

double cross(P a, P b) {
  return a.real()*b.imag()-a.imag()*b.real();
}

bool isIntersectSS(SEG a, SEG b) {
  return (cross(a.SND-a.FST, b.FST-a.FST) * cross(a.SND-a.FST, b.SND-a.FST) < EPS)
    && (cross(b.SND-b.FST, a.FST-b.FST) * cross(b.SND-b.FST, a.SND-b.FST) < EPS);
}

int main() {
  
  int N; cin >> N;
  
  while(N--) {
    P Wall[3];
    for(int i=0; i<3; i++) {
      double x, y; cin >> x >> y;
      Wall[i] = P(x, y);
    }
    
    double x, y;
    cin >> x >> y; P enemy(x, y);
    cin >> x >> y; P orihime(x, y);
    SEG seg(enemy, orihime);
    
    int ok = 0;
    for(int i=0; i<3; i++) {
      ok += isIntersectSS(seg, SEG(Wall[i], Wall[(i+1)%3]));
    }
    
    if(ok == 1) {
      cout << "OK" << endl;
    }
    else {
      cout << "NG" << endl;
    }
  }
  
  return 0;
}