#include #include using namespace std; using namespace atcoder; int IDX(int i, int j, int W) { return i*W+j; } int main() { int H, W, Q; cin >> H >> W; vector> A(H, vector(W)); for (int i=0; i> A[i][j]; } } cin >> Q; vector> query(Q, vector(4)); for (int i=0; i> query[i][j]; } } vector> edge; for (int i=0; i left(Q, 0); vector right(Q, edge.size()); vector> mid(edge.size()+1); for (int i=0; i(edge[i]), get<2>(edge[i])); } } } for (int i=0; i(edge[left[i]]) << endl; } }