#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Point
{
public:
    int y, x;
    Point(){
        y = x = 0;
    }
    Point(int y0, int x0){
        y = y0;
        x = x0;
    }
    int dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cosÆ
    }
    int cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sinÆ
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
};

/***************************************************************************************************/
// _ªÊ½p`Ìà(ÓãàÜÞ)É é©²×é
// cp : Ê½p`
// p  : _
/***************************************************************************************************/
bool convexContain(const vector<Point>& cp, const Point& p)
{
    int n = cp.size();
    bool ret1 = true;
    bool ret2 = true;
    for(int i=0; i<n; ++i){
        int a = (cp[(i+1)%n] - cp[i]).cross(p - cp[i]);
        if(a < 0)
            ret1 = false;
        if(a > 0)
            ret2 = false;
    }
    return ret1 || ret2;
}

int main()
{
    int n;
    cin >> n;

    while(--n >= 0){
        vector<Point> cp(3);
        Point a, b;
        for(int i=0; i<3; ++i)
            cin >> cp[i].x >> cp[i].y;
        cin >> a.x >> a.y >> b.x >> b.y;

        if(convexContain(cp, a) ^ convexContain(cp, b))
            cout << "OK" << endl;
        else
            cout << "NG" << endl;
    }
}