q = int(input().strip()) def parallel(m1, m2): return m1[0]*m2[1]==m1[1]*m2[0] def orthogonal(m1, m2): return m1[0]*m2[0]==-m1[1]*m2[1] def line(m, P): return [m, m[1]*P[1]-m[0]*P[0], m[1]] # slope, y-intercept-num, y-intercept-den def onLine(P, L): dx=L[0][1] dy=L[0][0] return dx*P[1]==dy*P[0]+L[1] def onSomeLine(P, lines): l=0 for l in range(4): if onLine(P, lines[l]): return (l+1) return 0 for _ in range(q): checkRect=1 n = int(input().strip()) x=y=[] for _ in range(n): xnum, ynum = input().strip().split() xnum, ynum = [int(xnum), int(ynum)] x.append(xnum) y.append(ynum) if n==3 or len(set(x))<3 or len(set(y))<3: # includes (# pts)<=3 and vertical/horizontal sides checkRect=1 else: # form L1 with first two points # check if xmin = min(x) ix1 = x.index(xmin) A=[x[ix1],y[ix1]] xmax = max(x) ix2=x.index(xmax) C=[x[ix2],y[ix2]] ymin = min(y) iy1=y.index(ymin) B=[x[iy1], y[iy1]] ymax = max(y) iy2=y.index(ymax) D=[x[iy2], y[iy2]] # Calculate Slopes [dy, dx] if A==B or B==C or C==D or D==A: checkRect=0 else: #print(A,B,C,D) m1=[A[1]-D[1], A[0]-D[0]] m2=[A[1]-B[1], A[0]-B[0]] m3=[C[1]-B[1], C[0]-B[0]] m4=[C[1]-D[1], C[0]-D[0]] if orthogonal(m1, m2) and orthogonal(m2, m3) and orthogonal(m3, m4): L1=line(m1, A) L2=line(m2, B) L3=line(m3, C) L4=line(m4, D) for P in [[x[i], y[i]] for i in range(n) if not [x[i], y[i]] in [A, B, C, D]]: P=[x[i], y[i]] # now check that each point belongs to one of the lines lines=[L1, L2, L3, L4] l=onSomeLine(P, lines) if l==0: checkRect=0 break else: # Then check if P is in between pts = [[D, A], [A, B], [B, C], [C, D]] m, b, dx = lines[l-1] S, T = pts[l-1] t = (P[0]-T[0])/float(S[0]-T[0]) #print("t=", t) if t<0 or t>1: checkRect=0 break checkRect=1 else: print("HERE") checkRect=0 if checkRect==0: print("NO") else: print("YES")