//BILL HAMILTON

//SENIOR 3, CONTEST 4, PATHWAYS

//ROCKPORT FULTON HIGH SCHOOL

//ROCKPORT, TEXAS

import java.io.*;

import java.text.*;

import java.util.*;

 

class pos

{         

            private int x,y;

            public pos(int x,int y)

            {

                        this.x=x;

                        this.y=y;

            }

            public boolean equals(pos a)

            {

                        return a.getX()==x&&a.getY()==y;

            }

            public int getX(){return x;}

            public int getY(){return y;}

}

 

class ACSL406

{

            public static boolean[][] mat=new boolean[5][5];

            public static Stack<pos> cpath=new Stack<pos>();

            public static ArrayList<pos> spath=null;

            public static pos dpos=null;

                       

            public static void go(pos a)

            {

                        int cx=a.getX();

                        int cy=a.getY();

                        if(cx>=0&&cy>=0&&cx<mat.length&&cy<mat[cx].length&&mat[cx][cy])

                        {

                                    cpath.push(a);

                                    if(a.equals(dpos)&&(spath==null||cpath.size()<spath.size()))

                                                spath=new ArrayList<pos>(cpath);                              

                                    mat[cx][cy]=false;

                                    go(new pos(cx+1,cy-1));

                                    go(new pos(cx+1,cy));

                                    go(new pos(cx+1,cy+1));

                                    go(new pos(cx,cy-1));

                                    go(new pos(cx,cy+1));

                                    go(new pos(cx-1,cy-1));

                                    go(new pos(cx-1,cy));

                                    go(new pos(cx-1,cy+1));

                                    cpath.pop();

                                    mat[cx][cy]=true;

                        }

            }

           

            public static void main(String [] args)throws IOException

            {

                        Scanner scan=new Scanner(new File("sr.dat"));

                        int n1=scan.nextInt();

                        int n2=scan.nextInt();

                        while(n1!=0||n2!=0)

                        {

                                    mat[n1-1][n2-1]=true;

                                    n1=scan.nextInt();

                                    n2=scan.nextInt();

                        }

                        for(int x=0;x<5;x++)

                        {

                                   

                                    spath=null;

                                    cpath=new Stack<pos>();

                                    pos temp=new pos(scan.nextInt()-1,scan.nextInt()-1);

                                    dpos=new pos(scan.nextInt()-1,scan.nextInt()-1);

                                    try

                                    {

                                    go(temp);

                                    if(spath==null)

                                                System.out.println("NONE");

                                    else

                                                System.out.println(spath.size()-1);

                                    }

                                    catch(Exception e)

                                    {}

                        }

            }

}