#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
using mint = modint998244353;
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define rrep(i, a, b) for(ll i = a; i >= b; i--)
constexpr ll inf = 4e18;
struct RandomNumberGenerator {
    mt19937_64 mt;
    RandomNumberGenerator()
        : mt(chrono::steady_clock::now().time_since_epoch().count()) {}
    ll operator()(ll l, ll r) {
        uniform_int_distribution<ll> dist(l, r);
        return dist(mt);
    }
} rng;
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(0);
    const vector<int> dx = {1, 0, -1, 0};
    const vector<int> dy = {0, 1, 0, -1};
    int n, t;
    cin >> n >> t;
    vector<int> a(n), b(n), c(n), d(n);
    rep(i, 0, n) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
        c[i]--;
        d[i]--;
    }
    ll u;
    int v;
    rep(day, 0, t) {
        cin >> u >> v;
        int ty = 0, x = -1, y = -1, z = -1, w = -1;
        if(v < 25) {
            ty = 2;
        } else {
            if(u >= 2000000 and day < t - 10) {
                ty = 1;
                x = rng(0, 13);
                y = rng(0, 13);
                while(!(0 <= z and z < 14 and 0 <= w and w < 14)) {
                    int dir = rng(0, 3);
                    z = x + dx[dir];
                    w = y + dy[dir];
                }
            } else {
                ty = 3;
            }
        }
        if(ty == 1) {
            cout << ty << ' ' << x + 1 << ' ' << y + 1 << ' ' << z + 1 << ' ' << w + 1 << endl;
        } else {
            cout << ty << endl;
        }
    }
}