#include using namespace std; const int INF=1e9; using pii=pair; using tii=tuple; #define rep(i,n) for (int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a pi={0,1,0,-1},pj={1,0,-1,0}; int to(int i,int j){ return i*14+j; } pii back(int x){ return {x/14,x%14}; } struct input{ int n,t; vector s,g; void input_cin(){ cin >> n >> t; s.resize(n); g.resize(n); rep(i,n){ int a,b,c,d; cin >> a >> b >> c >> d; a--; b--; c--; d--; s[i]=to(a,b); g[i]=to(c,d); } } }input; struct solver{ vector> people; vector> root(vector> &g){ vector> ret(14*14,vector(14*14,0)); rep(i,14*14){ vector dist(14*14,INF); vector prev(14*14); priority_queue pq; dist[i]=0; pq.push({i,i}); while(!pq.empty()){ int x,d; tie(x,d)=pq.top(); pq.pop(); for(auto &[to,w]:g[x]){ if(dist[x]+w> &g){ int ret=0; rep(i,14*14){ vector dist(14*14,INF); vector prev(14*14); priority_queue pq; dist[i]=0; pq.push({i,i}); while(!pq.empty()){ int x,d; tie(x,d)=pq.top(); pq.pop(); for(auto &[to,w]:g[x]){ if(dist[x]+w> g(14*14); rep(i,14){ rep(j,14){ rep(k,4){ int ti=i+pi[k],tj=j+pj[k]; if(ti<0||14<=ti||tj<0||14<=tj) continue; g[to(i,j)].emplace_back(to(ti,tj),1000); } } } people.resize(14*14); rep(i,14*14) people[i].resize(14*14,0); rep(i,input.n){ people[input.s[i]][input.g[i]]++; } int x=70; vector score_sum(x+1,0); vector v(x); vector> built(14*14,vector(14*14,false)); int ns=-1,ng=-1; rep(r,x){ vector> cnt=root(g); int max_cnt=0,ts=-1,tg=-1; rep(i,14*14){ rep(j,14*14){ if(cnt[i][j]==0) continue; if(built[i][j]) continue; if(max_cnt>> dp(input.t+1,vector>(input.t+1,vector(x,-INF))); vector>> prev(input.t+1,vector>(input.t+1,vector(x))); dp[0][1][0]=1e6; rep(i,input.t){ rep(j,input.t+1){ rep(k,x){ if(dp[i][j][k]==-INF) continue; if(0 ans; while(ni!=0){ int ti,tj,tk; tie(ti,tj,tk)=prev[ni][nj][nk]; if(tk!=nk){ ans.push_back(0); }else if(tj!=nj){ ans.push_back(1); }else{ ans.push_back(2); } ni=ti; nj=tj; nk=tk; } reverse(all(ans)); int now=0; rep(i,input.t){ int cin_u,cin_v; cin >> cin_u >> cin_v; if(ans[i]==0){ int s,t; tie(s,t)=v[now]; int o,p,q,r; tie(o,p)=back(s); tie(q,r)=back(t); cout << ans[i]+1 << " " << o+1 << " " << p+1 << " " << q+1 << " " << r+1 << endl; now++; }else{ cout << ans[i]+1 << endl; } } } }solver; int main(){ input.input_cin(); solver.solve(); }