#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int crs(int x1, int y1, int x2, int y2) {
    return (0 < x1 * y2 - y1 * x2 ? 1 : -1);
}

int main() {
    int n,xp1,yp1,xp2,yp2,xp3,yp3,xk,yk,xs,ys;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin>>xp1>>yp1>>xp2>>yp2>>xp3>>yp3>>xk>>yk>>xs>>ys;
        int t1 = 0;
        t1 += crs(xp2 - xp1, yp2 - yp1, xk - xp1, yk - yp1);
        t1 += crs(xp3 - xp2, yp3 - yp2, xk - xp2, yk - yp2);
        t1 += crs(xp1 - xp3, yp1 - yp3, xk - xp3, yk - yp3);
        int t2 = 0;
        t2 += crs(xp2 - xp1, yp2 - yp1, xs - xp1, ys - yp1);
        t2 += crs(xp3 - xp2, yp3 - yp2, xs - xp2, ys - yp2);
        t2 += crs(xp1 - xp3, yp1 - yp3, xs - xp3, ys - yp3);
        if ((abs(t1) == 3 && abs(t2) != 3) ||
            (abs(t1) != 3 && abs(t2) == 3)) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }
    return 0;
}