import java.util.LinkedList;
import java.util.Scanner;
class NightChess {
static Scanner mycan = new Scanner(System.in);
static LinkedList<Node> king_moves = new LinkedList<Node>();
static King king;
static LinkedList<Night> nights = new LinkedList<Night>();
static boolean checked = true;
static int x, y;
public static void main(String[] args) {
int T, N;
T = mycan.nextInt();
while (T != 0) {
N = mycan.nextInt();
// STORE ALL NIGHTS
for (int i = 0; i < N; i++) {
nights.add(new Night(mycan.nextLong(), mycan.nextLong()));
}
// CREATE THE KING
king = new King(mycan.nextLong(), mycan.nextLong());
//System.out.println("nights size :: "+nights.size());
for (int i = 0; i < nights.size(); i++) {
//System.out.print(distance(nights.get(i).getXY(), king.getXY())+" ");
if (distance(nights.get(i).getXY(), king.getXY()) > 100) {
nights.remove(i);
i--;
}
}
//System.out.println("nights size :: "+nights.size());
// CHECKING IS KING ALREADY CHECKMATE .
if (ngt_king_collide(nights, king.getXY())) {
int ksz = king.getValid_moves().size();
for (int i = 0; i < ksz; i++) {
if (!ngt_king_collide(nights, king.getValid_moves().get(i))) {
System.out.println("NO");
checked = false;
break;
}
}
if (checked) {
System.out.println("YES");
}
}else {
System.out.println("NO");
}
T--;
checked = true;
nights.clear();
}
}
static boolean ngt_king_collide (LinkedList<Night> a, Node b){
int s = a.size();
for (int i = 0; i < s; i++) {
if (a.get(i).isCollide(b)) {
return true;
}
}
return false;
}
static int distance(Node a, Node b){
int aa = (int) Math.sqrt(Math.pow(a.getI()-b.getI(), 2) + Math.pow(a.getJ()-b.getJ(), 2));
return aa;
}
}
class Night {
long x;
long y;
LinkedList nodes = new LinkedList();
public Night(long l, long m) {
// TODO Auto-generated constructor stub
this.x = l; this.y = m;
nodes.add(new Node(l-2, m+1));
nodes.add(new Node(l-2, m-1));
nodes.add(new Node(l+2, m+1));
nodes.add(new Node(l+2, m-1));
nodes.add(new Node(l+1, m+2));
nodes.add(new Node(l-1, m+2));
nodes.add(new Node(l+1, m-2));
nodes.add(new Node(l-1, m-2));
}
public LinkedList<Node> getNodes() {
return nodes;
}
public void display__valid_moves() {
int s = this.nodes.size();
for (int i = 0; i < s; i++) {
System.out.println("x :"+this.nodes.get(i).getI()+" y :"+this.nodes.get(i).getJ());
}
}
public long getX() {
return x;
}
boolean isCollide(Node a){
int s = this.nodes.size();
for (int i = 0; i < s; i++) {
if (this.nodes.get(i).isCollide(a)) {
return true;
}
}
return false;
}
public long getY() {
return y;
}
public void simplify(Node node) {
for (int i = 0; i < nodes.size(); i++) {
Node node2 = this.nodes.get(i);
if (node.getI() - node2.getI() > 3 && node.getI() - node2.getI() < -3 &&
node.getJ() - node2.getJ() > 3 || node.getJ() - node2.getJ() < -3) {
this.nodes.remove(i);
}
}
}
public Node getXY() {
// TODO Auto-generated method stub
return new Node(this.y, this.y);
}
}
class King {
long x;
long y;
LinkedList valid_moves = new LinkedList();
public King(int x, int y) {
// TODO Auto-generated constructor stub
this.x = x; this.y = y;
for (int i = x-1; i <= x+1; i++) {
for (int j = y-1; j <= y+1; j++) {
this.valid_moves.add(new Node(i, j));
}
}
}
public King(long nextLong, long nextLong2) {
// TODO Auto-generated constructor stub
this.x = nextLong; this.y = nextLong2;
for (long i = x-1; i <= x+1; i++) {
for (long j = y-1; j <= y+1; j++) {
this.valid_moves.add(new Node(i, j));
}
}
}
public void display__valid_moves() {
int s = this.valid_moves.size();
for (int i = 0; i < s; i++) {
System.out.println("x :"+this.valid_moves.get(i).getI()+" y :"+this.valid_moves.get(i).getJ());
}
}
public LinkedList<Node> getValid_moves() {
return valid_moves;
}
public long getX() {
return x;
}
public long getY() {
return y;
}
public void setX(int x) {
this.x = x;
}
Node getXY (){
return new Node(this.x, this.y);
}
public void setY(int y) {
this.y = y;
}
}
class Node {
long i;
long j;
public Node(int i, int j) {
this.i = i;
this.j = j;
}
public Node(long l, long m) {
// TODO Auto-generated constructor stub
this.i = l;
this.j = m;
}
public void setI(int i) {
this.i = i;
}
public void setJ(int j) {
this.j = j;
}
public long getI() {
return i;
}
public long getJ() {
return j;
}
boolean isCollide(Node a){
return this.i == a.getI() && this.j == a.getJ();
}
public String toString() {
// TODO Auto-generated method stub
return "i "+i+" j "+j;
}
}
with line 39 to 44 “wrong answer” and without 39 to 44 line “time limit over” please help me to find out where is my problem