uses
  testlib, sysutils;
  
type double = extended;

const EPS = 1e-2;

function isZero(value, eps: double) : boolean;
begin
    result := (-eps <= value) and (value <= eps);
end;

function length(x1, y1, x2, y2: double) : double;
begin
    result := sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
end;

function side(pX, pY, lX1, lY1, lX2, lY2: double) : integer;
var
    vmul: double;
begin
    vmul := (pX - lX1) * (lY2 - lY1) - (pY - lY1) * (lX2 - lX1);
    if isZero(vmul, 1e-9) then begin
        result := 0;
    end else if vmul < 0 then begin
        result := -1;
    end else begin
        result := 1;
    end;
end;

function disbalance(sX1, sY1, sX2, sY2, lX1, lY1, lX2, lY2: double) : double;
var
    signum1, signum2            : integer;
    segmentLength               : double;
    dx1, dy1, dx2, dy2, ax, ay  : double;
    det, t                      : double;
    ix, iy                      : double;
begin
    segmentLength := length(sX1, sY1, sX2, sY2);
    
    signum1 := side(sX1, sY1, lX1, lY1, lX2, lY2);
    signum2 := side(sX2, sY2, lX1, lY1, lX2, lY2);
    if abs(signum1 - signum2) < 2 then begin
    
        { either no intersection with line, 
          or one common point (up to EPS), 
          or segment belongs to line. }
        
        if signum1 + signum2 > 0 then begin
            result := segmentLength;
        end else if signum1 + signum2 < 0 then begin
            result := -segmentLength;
        end else begin
            result := 0;
        end;
    end else begin
        
        { segment and line have intersection. }
        
        dx1 := sX2 - sX1;
        dy1 := sY2 - sY1;
        dx2 := lX1 - lX2;
        dy2 := lY1 - lY2;
        ax  := lX1 - sX1;
        ay  := lY1 - sY1;
        
        det := dx1 * dy2 - dy1 * dx2;
        
        if isZero(det, 1e-9) then begin
            { strange... should almost never happen. }
            result := 0;
        end else begin
            t := (ax * dy2 - ay * dx2) / det;
        
            ix := sX1 + dx1 * t;
            iy := sY1 + dy1 * t;
        
            if signum1 > 0 then begin
                result := length(sX1, sY1, ix, iy) - length(ix, iy, sX2, sY2);
            end else begin
                result := length(sX2, sY2, ix, iy) - length(ix, iy, sX1, sY1);
            end;
        end;
    end;
end;

var
    xs, ys              : array[1 .. 100000] of double;
    pointCount          : longint;
    edgeCount           : longint;
    balance             : double;
    i, src, trg         : longint;
    lX1, lY1, lX2, lY2  : double;

begin
    lX1 := ouf.readReal();
    lY1 := ouf.readReal();
    lX2 := ouf.readReal();
    lY2 := ouf.readReal();

    
    if length(lX1, lY1, lX2, lY2) < 1 - EPS then begin
        quit(_wa, 'Points too close');
    end;

    
    balance := 0;
    
    if (abs(lX1) > 1e3 + EPS) or (abs(lY1) > 1e3 + EPS) or (abs(lX2) > 1e3 + EPS) or (abs(lY2) > 1e3 + EPS) then begin
        quit(_wa, 'Line endpoint coordinate exceeds 1e4');
    end;
    
    pointCount := inf.readLongint();
    edgeCount := inf.readLongint();
    for i := 1 to pointCount do begin
        xs[i] := inf.readLongint();
        ys[i] := inf.readLongint();
    end;
    for i := 1 to edgeCount do begin
        src := inf.readLongint();
        trg := inf.readLongint();
        balance := balance + disbalance(xs[src], ys[src], xs[trg], ys[trg], lX1, lY1, lX2, lY2);
    end;
    
    if isZero(balance, EPS) then begin
        quit(_ok, format('Correct (disbalance = %0.5f)', [balance]));
    end else begin
        quit(_wa, format('Incorrect (disbalance = %0.5f)', [balance]));
    end;
end.
