{David Teng

 Woburn CI

 ACSL Intermediate}

var

  filin, filout: text;

  grid: array[1..10, 1..10] of char;

  nodex, nodey, loop, i, j, a, b, count, x1, x2, y1, y2: longint;

 

procedure check(a, b:integer);

begin

  grid[a, b]:= 'N';

 

  if (a = x2) and (b = y2) then

    inc(count);

 

  if (a <> x2) or (b <> y2) then

  begin

    if grid[a, b + 1] = '*' then

      check(a, b + 1);

    if grid[a, b - 1] = '*' then

      check(a, b - 1);

    if grid[a + 1, b] = '*' then

      check(a + 1, b);

    if grid[a - 1, b] = '*' then

      check(a - 1, b);

  end;

 

  grid[a, b]:= '*';

end;

 

begin

  assign(filin, 'file.in');

  assign(filout, 'file.out');

  reset(filin);

  rewrite(filout);

 

  for i:= 1 to 5 do

    for j:= 1 to 5 do

      grid[i, j]:= 'N';

 

  repeat

    read(filin, nodex, nodey);

    grid[nodex, nodey]:= '*';

  until nodex = 0;

 

  readln(filin);

 

  for loop:= 1 to 5 do

  begin

    count:= 0;

 

    readln(filin, x1, y1, x2, y2);

 

    grid[x1, y1]:= 'N';

 

    if (x1 <> x2) or (y1 <> y2) then

    begin

      if grid[x1, y1 + 1] = '*' then

        check(x1, y1 + 1);

      if grid[x1, y1 - 1] = '*' then

        check(x1, y1 - 1);

      if grid[x1 + 1, y1] = '*' then

        check(x1 + 1, y1);

      if grid[x1 - 1, y1] = '*' then

        check(x1 - 1, y1);

      grid[x1, y1]:= '*';

    end;

 

    if count = 0 then

      writeln(filout,'NONE')

    else

      writeln(filout, count);

  end;

 

  close(filout);

end.