#include <iostream>
#include <vector>
#include <string>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

struct Point 
{
    double x, y;
    Point(double x=0, double y=0) : x(x), y(y) {}
    
	double distance (const Point &o) const 
	{
        return sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y));
    }

    Point operator+(const Point &o) const 
	{
        return Point(x+o.x, y+o.y);
    }
 
    Point operator-(const Point &o) const 
	{
        return Point(x-o.x, y-o.y);
    }
 	
    Point operator*(const double m) const 
	{
   	   return Point(x*m, y*m);
    }

    Point operator/(const double d) const 
	{
       return Point(x/d, y/d);
    }

    double cross(const Point &o) const 
	{
       return x * o.y - y * o.x;
    }
 
    double dot(const Point &o) const 
	{
        return x * o.x + y * o.y;
    }
 
    double atan() const 
	{
        return atan2(y, x);
    }

    double norm() const 
	{
        return dot(*this);
    }

	double area_abs(const Point &a,const Point &b) const
	{
		double t = (a.x - x) * (b.y - y);
		double t2 = (a.y - y) * (b.x - x);
		double areas = abs(t-t2);
		return areas/2;
	}

	//符号付き面積
	double area(const Point &a,const Point &b)
	{
		return ((a.x - x) * (b.y - y)) + ((b.x - x) * (y - a.y));
	}
	//線分abが自身の含まれているのかどうか判断する
	int between(const Point &a,const Point &b)
	{
		if(area(a,b) != 0) return 0;

		if(a.x != b.x)
		{
			return ((a.x <= x) && (x <= b.x) || (a.x >= x) && (x >= b.x));
		}
		else
		{
			return ((a.y <= y) && (y <= b.y) || (a.y >= y) && (y >= b.y));
		}
	}
};

//交差しているとき１を返す
int intersect(Point a,Point b,Point c,Point d)
{
	if(c.between(a,b) || d.between(a,b) || a.between(c,d) || b.between(c,d))
	{
		return 1;
	}
	else
	{
		return (c.area(a,b) * d.area(a,b) < 0 && a.area(c,d) * b.area(c,d) < 0);
	}
}


int main()
{
	int n;
	cin >> n;
	vector<Point> p;
	Point k,s;

	rep(i,n)
	{	
		p.clear();
		rep(j,3)
		{
			int x,y;
			cin >> x >> y;
			Point temp(x,y);
			p.push_back(temp);
		}

		int kx,ky,sx,sy;
		cin >> kx >> ky >> sx >> sy;

		k = Point(kx,ky);
		s = Point(sx,sy);
		
		int cnt = 0;
		
		if(intersect(k,s,p[0],p[1]))
		{
			cnt++;
		}

		if(intersect(k,s,p[1],p[2]))
		{
			cnt++;
		}

		if(intersect(k,s,p[0],p[2]))
		{
			cnt++;
		}
		
		if(cnt == 1) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}