#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; constexpr int inf = 1e9 + 7; constexpr ll longinf = 1LL << 60; constexpr ll mod = 1e9 + 7; struct Xor128 { unsigned x, y, z, w; Xor128(unsigned w_ = 88675123) : x(123456789), y(362436069), z(521288629), w(w_){}; inline unsigned xor128() { unsigned t; t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } int nextInt(int x, int y) { if(x > y) swap(x, y); return xor128() % (y - x) + x; } double nextDouble(double a, double b) { return (double)(xor128() & 0xffff) / 0xffff * (b - a) + a; } }; int dist[200][200]; int N = 3000, T = 400, M = 196; int cost[3030]; int s[3030], t[3030]; int NC = 100000, NH = 22301; int if_update(int v1, int v2) { int res = 0; rep(i, N) { int nc = min(dist[s[i]][t[i]], min(dist[s[i]][v1] + dist[v2][t[i]] + NH, dist[s[i]][v2] + dist[v1][t[i]] + NH)); res += nc % 100; } return res; } void update(int v1, int v2) { dist[v1][v2] = NH; dist[v2][v1] = NH; rep(i, M) rep(j, M) { dist[i][j] = min(dist[i][j], min(dist[i][v1] + dist[v2][j] + NH, dist[i][v2] + dist[v1][j] + NH)); } } void input() { int _; cin >> _ >> _; rep(i, N) { int a, b, c, d; cin >> a >> b >> c >> d; s[i] = a * 14 + b; t[i] = c * 14 + d; } rep(i, 200) rep(j, 200) { dist[i][j] = NC * 50; } rep(i, 14) rep(j, 14) { int x = i * 14 + j; if(j > 0) { dist[x][x - 1] = NC; } if(j < 13) { dist[x][x + 1] = NC; } if(i > 0) { dist[x][x - 14] = NC; } if(i < 13) { dist[x][x + 14] = NC; } dist[x][x] = 0; } rep(i, M) rep(j, M) rep(k, M) { dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); } } void output(int x, int y) { cout << x / 14 + 1 << " " << x % 14 + 1 << " "; cout << y / 14 + 1 << " " << y % 14 + 1 << endl; } auto rng = Xor128(); int cur = 0; void turn(int t) { int u, v; cin >> u >> v; int ma = 0, mx = 0, my = 0; rep(_, 10) { int e = rng.nextInt(0, 2 * 14 * 13); int x, y; if(e < 13 * 14) { x = (e / 13) * 14 + e % 13; y = x + 1; } else { e -= 13 * 14; x = e; y = e + 14; } int res = if_update(x, y); if(res > ma) { res = ma, mx = x, my = y; } } int ben = 60 * (ma - cur) * (T - t); int pay = (int)(10000000 / sqrt(v)); if(ben > pay && pay > u) { output(mx, my); update(mx, my); cur = ma; } else { int npay = (int)(10000000 / sqrt(v + 1)); int dpay = min(20, T - t) * (pay - npay); if(dpay > 50000) { cout << 2 << endl; } else { cout << 3 << endl; } } } int main() { input(); rep(i, T) { turn(i); } return 0; }