/*DAVID BRUBAKER

 *TOMBALL HS

 *30330 QUINN RD

 *TOMBALL TX 77375

 *JR DIVIDION

 */

 

 

import java.util.*;

import java.io.*;

public class ACSL4JrDBrubaker

{

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

            {

                        boolean[][] map=new boolean[100][100];

                        BufferedReader input=new BufferedReader(new FileReader("ACSLJR4.dat"));

                        StringTokenizer tok=new StringTokenizer(input.readLine(),",");

                        while(tok.countTokens()>2)

                                    map[Integer.parseInt(tok.nextToken())-1][Integer.parseInt(tok.nextToken())-1]=true;

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

                        {

                                    String out="";

                                    boolean simple=false;

                                    tok=new StringTokenizer(input.readLine(),",");

                                    int x1=Integer.parseInt(tok.nextToken());

                                    int y1=Integer.parseInt(tok.nextToken());

                                    int x2=Integer.parseInt(tok.nextToken());

                                    int y2=Integer.parseInt(tok.nextToken());

                                    ArrayList<Integer> direction=new ArrayList<Integer>();

                                    ArrayList<int[]> locations=new ArrayList<int[]>();

                                    int[] currentLoc={x1,y1};

                                    locations.add(currentLoc);

                                    direction.add(new Integer(0));

                                    int a=0;while(!simple)

                                    {

                                                ArrayList<int[]> temp=validNeighbors(currentLoc[0],currentLoc[1],map,locations);

                                                if(direction.get(direction.size()-1).intValue()<temp.size()&&temp.size()!=0)

                                                {         

                                                            locations.add(temp.get(direction.get(direction.size()-1).intValue()));

                                                            direction.add(new Integer(direction.remove(direction.size()-1).intValue()+1));

                                                            currentLoc=locations.get(locations.size()-1);

                                                            direction.add(new Integer(0));

                                                }

                                                else

                                                {

                                                            direction.remove(direction.size()-1);

                                                            locations.remove(locations.size()-1);

                                                            if(locations.size()>0)

                                                                        currentLoc=locations.get(locations.size()-1);

                                                }

                                                if(currentLoc[0]==x2&&currentLoc[1]==y2)

                                                            simple=true;

                                                else if(locations.size()==0)

                                                            break;

                                                a++;

                                               

                                    }

                                    if(simple)

                                    {

                                                for(int m=0; m<locations.size(); m++)

                                                {

                                                            int[] temp=locations.get(m);

                                                            out=out+temp[0]+","+temp[1]+",";

                                                }

                                                out=out.substring(0,out.length()-1);

                                    }

                                    else

                                                out="NONE";

                                    System.out.println(i+1+". "+out);

                        }

            }

                        public static ArrayList<int[]> validNeighbors(int x, int y, boolean[][] map,ArrayList<int[]> locations)

                        {

                                    int[] location=null;

                                    //get location moved from last

                                    if(locations.size()>1)

                                                location=locations.get(locations.size()-2);

 

                                    //get all neighbors

                                    ArrayList<int[]> nbrs=new ArrayList<int[]>();

                                    for(int a=x-1; a<x+2; a++)

                                                for(int b=y-1; b<y+2; b++){

                                                            if(b==y&&a==x)

                                                                        continue;

                                                            else if(isValidLocation(a, b, map)){

                                                                        nbrs.add(new int[]{a,b});}

                                                }

                                    //get marked neighbors

                                    for(int a=0; a<nbrs.size(); a++)

                                    {

                                                if(!map[nbrs.get(a)[0]-1][nbrs.get(a)[1]-1]){

                                                            nbrs.remove(a);a=-1;}

                                    }

                                    if(location!=null)

                                    {

                                                for(int z=0; z<nbrs.size(); z++)

                                                {

                                                            int[] temp=nbrs.get(z);

                                                            if(temp[0]==location[0]&&temp[1]==location[1])

                                                            {

                                                                        nbrs.remove(z);

                                                                        break;

                                                            }

                                                }

                                    }         

                                                return nbrs;

                        }

                        public static boolean isValidLocation(int x, int y, boolean[][] map)

                        {

                                    if(x<=0||y<=0)

                                                return false;

                                    if(x<=map.length&&y<=map[x-1].length)

                                                return true;

                                    return false;

                        }

}