#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]]++; } vector> cnt=root(g); vector v; rep(i,14*14){ rep(j,14*14){ if(cnt[i][j]==0) continue; v.emplace_back(-cnt[i][j],i,j); } } sort(all(v)); int x=min(50,v.size()); vector score_v(x); rep(r,x){ int c,i,j; tie(c,i,j)=v[r]; for(auto &[to,w]:g[i]){ if(to==j) w=223; } for(auto &[to,w]:g[j]){ if(to==i) w=223; } score_v[r]=score(g); } vector score_sum(x+1,0); rep(i,x) score_sum[i+1]+=score_v[i]; vector>> dp(input.t+1,vector>(input.t+1,vector(x,-INF))); vector>> prev(input.t+1,vector>(input.t+1,vector(x))); dp[0][0][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 c,s,t; tie(c,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(); }