#define NOFOOTER

#include "testlib.h"

#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <vector>

typedef long long i64;

struct point_2
{
    i64 x, y;
    
    point_2() : x(0), y(0) {}
    point_2(i64 x, i64 y) : x(x), y(y) {}
    point_2(point_2 const &src) : x(src.x), y(src.y) {}
    
    bool operator < (point_2 const &that) const
    {
        return x == that.x ? y < that.y : x < that.x;
    }
};

struct fleet
{
    std::vector<point_2> ships;
    point_2 dir;
    int t;
    
    fleet(fleet const &src) : ships(src.ships), dir(src.dir), t(src.t) {}
    
    fleet(InStream &in)
    {
        int n = in.readInt();
        t = in.readInt();
        dir.x = in.readInt();
        dir.y = in.readInt();
        for (int i = 0; i < n; ++i)
        {
            ships.push_back(point_2());
            ships.back().x = in.readInt();
            ships.back().y = in.readInt();
        }
    }
};

struct disposition
{
    std::vector<fleet> fleets;
    i64 time;
    
    disposition(InStream &in) : time(0)
    {
        int n = 2;
        for (int i = 0; i < n; ++i)
        {
            fleets.push_back(fleet(in));
        }
    }
    
    disposition(disposition const &src) : fleets(src.fleets), time(src.time) {}
    
    void set_time(i64 new_time)
    {
        for (int i = 0; i < fleets.size(); ++i)
        {
            fleet &f = fleets[i];
            i64 before = (time + f.t - 1) / f.t;
            i64 after = (new_time + f.t - 1) / f.t;
            i64 ddx = (after - before) * f.dir.x;
            i64 ddy = (after - before) * f.dir.y;
            for (int j = 0; j < f.ships.size(); ++j)
            {
                f.ships[j].x += ddx;
                f.ships[j].y += ddy;
            }
        }
    }
    
    bool has_battle() const
    {
        std::set<point_2> pts;
        
        int total = 0;
        
        for (int i = 0; i < fleets.size(); ++i)
        {
            fleet const &f = fleets[i];
            for (int j = 0; j < f.ships.size(); ++j)
            {
                pts.insert(f.ships[j]);
                ++total;
            }
        }
        
        return pts.size() < total;
    }
};

int main(int argc, char *argv[])
{
    registerTestlibCmd(argc, argv);
    
    disposition initial(inf);
    
    i64 jury = ans.readLong();
    i64 cont = ouf.readLong();
    
    if (jury < -1)
    {
        quitf(_fail, "Jury < -1");
    }
    if (cont < -1)
    {
        quitf(_wa, "Contestant < -1");
    }
    if (jury != -1)
    {
        disposition d(initial);
        d.set_time(jury);
        if (!d.has_battle())
        {
            quitf(_fail, "Jury's answer doesn't correspond to a battle");
        }
    }
    if (cont != -1)
    {
        disposition d(initial);
        d.set_time(cont);
        if (!d.has_battle())
        {
            quitf(_wa, "Contestant's answer doesn't correspond to a battle");
        }
    }
    if (jury == -1 && cont != -1)
    {
        quitf(_fail, "Jury didn't find an answer while contestant did");
    }
    if (jury != -1 && cont == -1)
    {
        quitf(_wa, "Contestant didn't find an answer");
    }
    if (jury > cont)
    {
        quitf(_fail, "Contestant found a better answer");
    }
    if (jury < cont)
    {
        quitf(_wa, "Contestant's answer is not minimal possible");
    }

    if (jury == -1)
    {
        quitf(_ok, "Ok (Impossible)");
    }
    else
    {
        //did this because no cross-compiler printf formatters for i64 exist.
        std::ostringstream oss;
        oss << "Ok (" << jury << ")";
        //do not attempt to inline this call:
        //oss.str().c_str() will always result in bad pointer
        //because immediate std::string will be killed.
        std::string s = oss.str();
        quitf(_ok, s.c_str());
    }
}
