{$APPTYPE CONSOLE}
uses
  SysUtils, testlib;

const types: array[1..4] of string = ('segment', 'outray', 'inray', 'line');
const MAXCOORD = 100000;

var
  line: integer;

type obj = record
  t: integer;
  x1, y1, x2, y2: integer;
end;

function signum(v: integer): integer;
begin
  if (v > 0) then
    result := 1
  else if (v < 0) then
    result := -1
  else
    result := 0;
end;

function rel(var o: obj): integer;
begin
  result := 3 * signum(o.x2 - o.x1) + signum(o.y2 - o.y1);
end;

function ori(var o: obj; x3, y3: integer): integer;
var
  x1, y1, x2, y2, area: int64;
begin
  x1 := o.x1;
  y1 := o.y1;
  x2 := o.x2;
  y2 := o.y2;
  area := x1 * y2 - x2 * y1 +
          x2 * y3 - x3 * y2 +
          x3 * y1 - x1 * y3;
  if (area > 0) then
    result := 1
  else if (area < 0) then
    result := -1
  else
    result := 0;
end;

function readCoord(var f: InStream): integer;
begin
  result := f.readLongint;
  if (result > MAXCOORD) or (result < -MAXCOORD) then
    f.quit(_WA, 'Coordinate is too large (' + inttostr(result) + ') in line ' + inttostr(line));
end;

function readObj(var f: InStream): obj;
var
  s: string;
  i: integer;
begin
  s := f.readWord(BLANKS, BLANKS);
  result.t := 0;
  for i := 1 to 4 do
    if (s = types[i]) then
      result.t := i;
  if (result.t = 0) then
    f.quit(_PE, 'Invalid object type "' + s + '" in line ' + inttostr(line));
  result.x1 := readCoord(f);
  result.y1 := readCoord(f);
  result.x2 := readCoord(f);
  result.y2 := readCoord(f);
  if (result.x1 = result.x2) and (result.y1 = result.y2) then
    f.quit(_WA, 'Object given by two identical points in line ' + inttostr(line));
  if (result.t = 3) then
  begin
    i := result.x1; result.x1 := result.x2; result.x2 := i;
    i := result.y1; result.y1 := result.y2; result.y2 := i;
  end;
end;

var
  ja, ca: integer;
  jo, co: obj;

begin
  ca := ouf.readlongint;
  ja := ans.readlongint;
  if (ca <> ja) then
    quit(_WA, 'Wrong number of objects (' + inttostr(ca) + ' instead of ' + inttostr(ja) + ')');

  for line := 1 to ca do
  begin
    co := readObj(ouf);
    jo := readObj(ans);
    if (co.t <> jo.t) then
      quit(_WA, 'Wrong type of object in line ' + inttostr(line) + ' (' + types[co.t] + ' instead of ' + types[jo.t] + ')');
    if (co.t = 1) then
    begin
      if (co.x1 <> jo.x1) or (co.y1 <> jo.y1) or (co.x2 <> jo.x2) or (co.y2 <> jo.y2) then
        quit(_WA, 'Wrong segment in line ' + inttostr(line));
      continue;
    end;
    if (co.t = 4) then
    begin
      if (ori(jo, co.x1, co.y1) <> 0) then
        quit(_WA, 'Wrong point (' + inttostr(co.x1) + ', ' + inttostr(co.y1) + ') in line ' + inttostr(line));
      if (ori(jo, co.x2, co.y2) <> 0) then
        quit(_WA, 'Wrong point (' + inttostr(co.x2) + ', ' + inttostr(co.y2) + ') in line ' + inttostr(line));
      if (rel(jo) <> rel(co)) then
        quit(_WA, 'Wrong direction of straight line in line ' + inttostr(line));
      continue;
    end;
    if (co.x1 <> jo.x1) or (co.y1 <> jo.y1) then
      quit(_WA, 'Wrong beginning of ' + types[co.t] + ' (' + inttostr(co.x1) + ', ' + inttostr(co.y1) + ') in line ' + inttostr(line));
    if (ori(jo, co.x2, co.y2) <> 0) then
      quit(_WA, 'Wrong direction of ' + types[co.t] + ' in line ' + inttostr(line));
    if (rel(jo) <> rel(co)) then
      quit(_WA, 'Wrong (opposite) direction of ' + types[co.t] + ' in line ' + inttostr(line));
  end;
  
  if (ca = 0) then
    quit(_OK, 'Entire plane');
  if (ca = 1) then
    quit(_OK, 'One line');
  quit(_OK, inttostr(ca) + ' objects');
end.
