#include<iostream>
#include<string.h>
#include<stdio.h>
#include<cstdlib>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<algorithm>
typedef long long ll;
using namespace std;
vector<int> a[100001], dp[100001];
int length[100001];
int n, m, k, l, r;

int main(){
	cin >> n >> m;
	for(int i=0; i<n; i++){
		a[i].resize(m);
		for(int j=0; j<m; j++){
			cin >> a[i][j];
		}
	}

	dp[0].resize(m, 1);
	for(int i=1; i<n; i++){
		dp[i].resize(m, 1);
		for(int j=0; j<m; j++){
			if(a[i][j] >= a[i-1][j])
				dp[i][j] += dp[i-1][j];
		}
	}

	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++)
			length[i] = max(length[i], dp[i][j]);
	}

	cin >> k;
	while(k--){
		cin >> l >> r;
		if(length[r-1] > (r-l)) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}


#include<iostream>
#include<algorithm>   //sort()头文件
#include<string>
using namespace std;

int main()
{
    int n,m,k,l,r;
    cin>>n>>m;
    int a[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    cin>>k;
    int result[k]={0},nresult=0,tk=k;
    while(--k>=0)
    {
        int flag;
        cin>>l>>r;
        for(int i=0;i<m;i++)   //列
        {
            flag=1;
            if(l==r)
                break;
            for(int j=l-1;j<r-1;j++)  //行
            {
                if(a[j][i]<=a[j+1][i])
                    continue;
                else
                    flag=0;
            }
            if(flag)
            {
                result[nresult++]=flag;
                break;
            }
        }
        result[nresult++]=flag;
    }
    for(int i=0;i<tk;i++)
    {
        if(result[i])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
using namespace std ;

int main()
{
    vector<vector<int>> data ;

    int row ;
    int col ;
    cin>>row>>col ;

    for( int i = 0 ; i < row ; ++ i )
        data.push_back(vector<int>()) ;

    for( int i = 0 ; i < row ; ++ i )
        for( int j = 0 ; j < col ; ++ j ){
            int number = 0 ;
            cin>>number ;
            data[i].push_back(number) ;
        }

    int num_time ;
    cin>>num_time ;
    for( int i = 0 ; i < num_time ; ++ i ){
        int top ;
        int bottom ;
        cin>>top>>bottom ;
        -- top ;
        -- bottom ;
        if( top == bottom ){
            cout<<"Yes";
            continue ;
        }

        bool *result = new bool[col] ;
        for( int j = 0 ; j < col ; ++ j )
            result[j] = false ;

        for( int k = 0 ; k < col ; ++ k ){
            int j = top ;
            for( ; j < bottom ; ++ j ){   //ai,j<=ai+1,j
            if( data[j][k] <= data[j+1][k] )
                continue ;
            else break ;
            }
            if( j >= bottom )
                result[k] = true ;
        }

        int count = 0 ;
        for( int j = 0 ; j < col ; ++ j )
            if( result[j] == true )
                ++ count ;
        if( count != 0 )
            cout<<"Yes";
        else cout<<"No";

        delete result ;
    }
    return 0 ;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
const int maxn = 1e5 + 10;
using namespace std;

int r[maxn], c[maxn], num[maxn];

int main(){
    //freopen("in.txt","r",stdin);
    int n, m;
    while( scanf("%d %d", &n, &m ) != EOF ){
        for( int i = 1; i <= m; i++ ){
            scanf("%d",&num[i]);
            c[i] = 1;
        }
        r[1] = 1;
        int t;
        for( int i = 2; i <= n; i++ ){
            r[i] = i;
            for( int j = 1; j <= m; j++ ){
                scanf("%d", &t );
                if( t >= num[j] ){
                    r[i] = min( r[i], c[j] );
                }
                else{
                    c[j] = i;
                }
                num[j] = t;
            }
        }
        int k, u, v ;
        scanf("%d", &k );
        while( k-- ){
            scanf("%d %d", &u, &v );
            if( r[v] <= u ){
                puts("Yes");
            }
            else{
                puts("No");
            }
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
int n,m;
int a[111111];
int maxr[111111];
void upd(int&x,int y){
	if(x == -1 || x < y)x=y;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0; i<n; i++)
		for(int j=0; j<m; j++)
			scanf("%d",&a[i*m+j]);
	memset(maxr,-1,sizeof(maxr));
	for(int j=0; j<m; j++){
		int S = 0, E = 0;
		for(int i=1; i<n; i++){
			if(a[i*m+j] >= a[E*m+j])
				E = i;
			else{
//				printf("%d %d\n",S,E);
				upd(maxr[S], E);
				S = E = i;
			}
		}
//		printf("%d %d\n",S,E);
		upd(maxr[S], E);
	}
	for(int i=1; i<n; i++)
		upd(maxr[i], maxr[i-1]);
	int q;
	for(scanf("%d",&q); q--;){
		int x,y;
		scanf("%d%d",&x,&y);--x;--y;
		puts(maxr[x]>=y?"Yes":"No");
	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int a[1000010],b[1000010],s[1000010];
int main()
{
	int n,m,x;
	scanf("%d%d",&n,&m);
	memset(a,0,sizeof(a));
	memset(s,0,sizeof(s));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			scanf("%d",&x);
			if(x>=a[j])
			s[j]++;
			else
			s[j]=1;
			a[j]=x;
		b[i]=max(b[i],s[j]);
		}
	}
	int k,l,r;
	scanf("%d",&k);
	for(int i=0;i<k;i++)
	{
		scanf("%d%d",&l,&r);
		if(b[r]>=(r-l+1))
		printf("Yes\n");
		else
		printf("No\n");
	}
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<sstream>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
#define INF 1000000007
#define MOD 1000000007
#define INF_LONG 1e18
#define MOD_LONG 1e18
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define mp make_pair
#define all(x) (x).begin(), (x).end()
const int dr[4] = { 0,0,-1,1 }, dc[4] = { -1,1,0,0 };
class Dijkstra {
	int N;
	vector<vector<pair<int, int> > > E;
public:
	Dijkstra(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	vector<int> dijkstra(int start, int end) {
		vector<int> dist(N + 1, INF);
		dist[start] = 0;
		priority_queue<pair<int, int> > pq;
		pq.push(make_pair(0, start));
		while (!pq.empty()) {
			int w = -pq.top().first;
			int u = pq.top().second;
			if (u == end) return dist;
			pq.pop();
			if (dist[u] < w) continue;
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				int w2 = w + E[u][i].second;
				if (dist[v] > w2) {
					dist[v] = w2;
					pq.push(make_pair(-w2, v));
				}
			}
		}
		return dist;
	}
	void g() {
		int i, n, e, s, u, v, w; vector<int> ans;
		scanf("%d%d", &n, &e);
		Dijkstra dk(n);
		scanf("%d", &s);
		for (i = 0; i < e; i++) {
			scanf("%d%d%d", &u, &v, &w);
			dk.insert(u, v, w);
		}
		ans = dk.dijkstra(s, N);
		for (i = 1; i <= n; i++) {
			if (ans[i] >= INF) printf("INF\n");
			else printf("%d\n", ans[i]);
		}
	}
};
class Prim {
	int N;
	vector<vector<pair<int, int> > > E;
public:
	Prim(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	vector<int> execute(ll &cost) {
		int k;
		vector<int> dist(N + 1, INF);
		vector<bool> selected(N + 1, false);
		dist[1] = 0; cost = 0;
		priority_queue<pair<int, int> > pq;
		pq.push(make_pair(0, 1));
		for (k = 0; k < N; k++) {
			int w = -pq.top().first;
			int u = pq.top().second;
			pq.pop();
			if (selected[u] == true) {
				k--; continue;
			}
			cost += w; selected[u] = true;
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				int w2 = E[u][i].second;
				if (selected[v] == true) continue;
				if (dist[v] > w2) {
					dist[v] = w2;
					pq.push(make_pair(-w2, v));
				}
			}
		}
		return dist;
	}
	void g() {
		int i, n, e, s, u, v, w; ll cost; vector<int> ans;
		scanf("%d%d", &n, &e);
		Prim pm(n);
		scanf("%d", &s);
		for (i = 0; i < e; i++) {
			scanf("%d%d%d", &u, &v, &w);
			pm.insert(u, v, w);
		}
		ans = pm.execute(cost);
		printf("%d", cost);
	}
};
class Floyd {
	int N;
	vector<vector<int> > E;
public:
	Floyd(int n) {
		N = n;
		E = vector<vector<int> >(N + 1, vector<int>(N + 1, INF));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	void execute() {
		int i, j, k;
		for (i = 1; i <= N; ++i) E[i][i] = 0;
		for (k = 1; k <= N; ++k) for (i = 1; i <= N; ++i) for (j = 1; j <= N; ++j)
			E[i][j] = min(E[i][j], E[i][k] + E[k][j]);
	}
};
class DFS_Graph {
	vector<vector<pair<int, int> > > E; vector<int> A;
	int N;
public:
	DFS_Graph(int n) {
		N = n;
		E = vector<vector<pair<int, int> > >(N + 1);
		A = vector<int>(N + 1);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
	}
	void insert_fb(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	int dfsAll(int start, int end) {
		vector<bool> visited = vector<bool>(N + 1, false);
		return dfs(start, end, visited);
	}
	int dfs(int start, int end, vector<bool> &visited) {
		if (start == end) return 1;
		visited[start] = true;
		for (int i = 0; i < E[start].size(); i++) {
			int v = E[start][i].first, c = E[start][i].second;
			if (!visited[v]) {
				if (dfs(v, end, visited)) return 1;
			}
		}
		return 0;
	}
	void setA(int a, int b) {
		A[a] = b;
	}
	int dfsAll2() {
		vector<int> visited(N + 1, 0);
		int i, j, seq = 0, ret = 0, a;
		for (i = 1; i <= N; i++) dfs2(i, visited, ++seq);
		for (i = 1; i <= N; i++) {
			for (j = a = 0; j < E[i].size(); j++) {
				a += E[i][j].second;
			}
			if (ret < a) ret = a;
		}
		return ret;
	}
	int dfs2(int start, vector<int> &visited, ll seq) {
		visited[start] = seq;
		int ret = A[start];
		for (int i = 0; i < E[start].size(); i++) {
			int v = E[start][i].first; ll c = E[start][i].second;
			if (visited[v] < seq) {
				if (E[start][i].second == -1) E[start][i].second = dfs2(v, visited, seq);
				if (ret < E[start][i].second) ret = E[start][i].second;
			}

		}
		return ret;
	}
	void g() {
		int i, j, N, m, a, b, c, a2, b2, c2, lo, hi, mid, tmp, start, end;
		scanf("%d%d", &N, &m);
		DFS_Graph dg(N);
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			dg.insert(a, b, 0);
		}
		scanf("%d", &m);
		for (i = 0; i < m; i++) {
			scanf("%d%d", &a, &b);
			if (dg.dfsAll(a, b)) c = -1;
			else if (dg.dfsAll(b, a)) c = 1;
			else c = 0;
			printf("%d\n", c);
		}
	}
};
class DFS_Map {
	vector<vector<int> > E;
	int R, C;
public:
	DFS_Map(int r, int c) {
		R = r; C = c;
		E = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	void dfs(int rr, int cc, vector<vector<bool> > &visited) {
		int i, r, c, v;
		visited[rr][cc] = true;
		for (i = 0; i < 4; i++) {
			r = rr + dr[i]; c = cc + dc[i];
			if (E[r][c] && !visited[r][c]) {
				dfs(r, c, visited);
			}
		}
	}
	void dfsAll() {
		vector<vector<bool> > visited = vector<vector<bool> >(R + 2, vector<bool>(C + 2, 0));
		int r, c;
		for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) if (!visited[r][c]) dfs(r, c, visited);
	}
};
class BFS_Graph {
	vector<vector<pair<int, int> > > E; vector<int> IN;
	int N;
public:
	int is_cycle() { // topologicalSort() 수행후 IN[v]>0인 node가 존재하면 cycle이 존재한다고 볼수있다
		for (int i = 1; i <= N; i++) if (IN[i]>0) return 1;
		return 0;
	}
	BFS_Graph(int n) {
		N = n;
		E.clear(); IN.clear();
		E = vector<vector<pair<int, int> > >(N + 1);
		IN = vector<int>(N + 1, 0);
	}
	void insert(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		IN[v]++;
	}
	void insert_fb(int u, int v, int w) {
		E[u].push_back(make_pair(v, w));
		E[v].push_back(make_pair(u, w));
	}
	vector<ll> bfs(int start, int end, int min_weight) {
		vector<bool> visited = vector<bool>(N + 1, false);
		vector<ll> weight(N + 1, INF_LONG);
		queue<int> Q;
		visited[start] = true; weight[start] = 0;
		Q.push(start);
		while (!Q.empty()) {
			int u = Q.front(), w = weight[u]; if (u == end) break;
			Q.pop();
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first, c = E[u][i].second;
				if (c >= min_weight && !visited[v]) {
					Q.push(v); weight[v] = w + c;
					visited[v] = true;
				}
			}
		}
		return weight;
	}
	vector<int> topologicalSort() {
		vector<int> order;
		queue<int> Q;
		for (int i = 1; i <= N; i++) if (!IN[i]) Q.push(i);
		while (!Q.empty()) {
			int u = Q.front();
			Q.pop(); order.push_back(u);
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				if (IN[v]>0) {
					IN[v]--;
					if (!IN[v]) Q.push(v);
				}
			}
		}
		return order;
	}
	vector<int> topologicalSortPQ() {
		vector<int> order;
		priority_queue<int> pq;
		for (int i = 1; i <= N; i++) if (!IN[i]) pq.push(-i);
		while (!pq.empty()) {
			int u = -pq.top();
			pq.pop(); order.push_back(-u);
			for (int i = 0; i < E[u].size(); i++) {
				int v = E[u][i].first;
				if (IN[v]>0) {
					IN[v]--;
					if (!IN[v]) pq.push(-v);
				}
			}
		}
		return order;
	}
	int f() {
		int v, u, i; vector<int> IN2;
		for (u = 1; u <= N; u++) {
			for (i = 0; i<E[u].size(); i++) {
				v = E[u][i].first;
				if (IN[v] == 1) {
					IN2 = IN;
					IN[v]--;
					topologicalSort();
					if (!is_cycle()) return 1;
					IN = IN2;
				}
			}
		}
		return 0;
	}
	void g() {
		int i, j, N, m, a, b, c, a2, b2, c2, lo, hi, mid, tmp, start, end;
		vector <tuple<int, int, int> > X; vector<ll> y;
		scanf("%d%d", &N, &m);
		BFS_Graph bg(N); X.reserve(m);
		for (i = 0; i < m; i++) {
			scanf("%d%d%d", &a, &b, &c);
			if (a > b) tmp = a, a = b, b = tmp;
			X.push_back(make_tuple(a, b, -c));
		}
		scanf("%d%d", &start, &end);
		sort(X.begin(), X.end());
		bg.insert_fb(get<0>(X[0]), get<1>(X[0]), -get<2>(X[0]));
		for (i = 1; i < m; i++) {
			a = get<0>(X[i - 1]); b = get<1>(X[i - 1]); c = get<2>(X[i - 1]);
			a2 = get<0>(X[i]); b2 = get<1>(X[i]); c2 = get<2>(X[i]);
			if (a == a2 && b == b2) continue;
			bg.insert_fb(a2, b2, -c2);
		}
		lo = 1; hi = INF;
		while (lo < hi) {
			mid = (lo + hi + 1) / 2;
			y = bg.bfs(start, end, mid);
			if (y[end] < INF_LONG) {
				lo = mid;
			}
			else {
				hi = mid - 1;
			}
		}
		printf("%d", lo);
	}
};
class BFSMap {
	vector<vector<int> > E;
	int R, C;
public:
	BFSMap(int r, int c) {
		R = r; C = c;
		E = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
	}
	void setRC(int r, int c, int w) {
		E[r][c] = w;
	}
	int getRC(int r, int c) {
		return E[r][c];
	}
	int bfsAll() {
		int r, c, ret = 0;
		vector<vector<int> > visited = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
		for (r = 1; r <= R; r++) {
			for (c = 1; c <= C; c++) {
				if (E[r][c] && !visited[r][c]) {
					ret++; bfs(r, c, visited);
				}
			}
		}
		return ret;
	}
	int bfsAll(vector<pair<int, int> > &Q) {
		int i, r, c, ret = 0;
		vector<vector<int> > visited = vector<vector<int> >(R + 2, vector<int>(C + 2, 0));
		for (i = 0; i < Q.size(); i++) {
			r = Q[i].first; c = Q[i].second;
			if (!visited[r][c]) {
				ret++; bfs(r, c, visited);
			}
		}
		return ret;
	}
	void bfs(int rr, int cc, vector<vector<int> > &visited) {
		int i, r, c, r2, c2;
		queue<pair<int, int> > Q;
		Q.push(make_pair(rr, cc)); visited[rr][cc] = 1;
		while (!Q.empty()) {
			r = Q.front().first;
			c = Q.front().second;
			Q.pop();
			for (i = 0; i < 4; i++) {
				r2 = r + dr[i]; c2 = c + dc[i];
				if (E[r2][c2] && !visited[r2][c2]) {
					Q.push(make_pair(r2, c2)); visited[r2][c2] = visited[r][c] + 1;
				}
			}
		}
	}
	void g() {
		int i, j, r, c, r2, c2, R, C, a, ans = 0, idx = 0; vector <pair<int, int> > Q[2]; vector<int> X;
		scanf("%d%d", &R, &C);
		BFSMap bm(R, C);
		X.reserve(10004); Q[0].reserve(10004); Q[1].reserve(10004);
		for (r = 1; r <= R; r++) for (c = 1; c <= C; c++) {
			scanf("%d", &a); bm.setRC(r, c, a); if (a) Q[0].push_back(make_pair(r, c));
		}
		while (1) {
			a = bm.bfsAll(Q[idx]);
			if (a > 1) break;
			else if (a == 0) {
				ans = 0; break;
			}
			ans++; X.resize(0); Q[1 - idx].resize(0);
			for (i = 0; i < Q[idx].size(); i++) {
				r = Q[idx][i].first; c = Q[idx][i].second; a = 0;
				for (j = 0; j < 4; j++) {
					r2 = r + dr[j]; c2 = c + dc[j];
					if (bm.getRC(r2, c2) == 0) a++;
				}
				X.push_back(a);
			}
			for (i = 0; i < Q[idx].size(); i++) {
				r = Q[idx][i].first; c = Q[idx][i].second; a = bm.getRC(r, c) - X[i];
				if (a <= 0) {
					a = 0;
				}
				else {
					Q[1 - idx].push_back(make_pair(r, c));
				}
				bm.setRC(r, c, a);
			}
			idx = 1 - idx;
		}
		printf("%d", ans);
	}
};
class Number {
public:
	Number() {

	}
	int getDigitNum(ull xx) {
		ull x; int ret = 0;
		for (x = 1; x <= xx; x *= 10, ret++);
		return ret;
	}
	int getDigitSum(int xx) {
		int x, a = 0;
		for (x = xx; x; x /= 10) a += (x % 10);
		return a;
	}
	int getMSB(ll xx) {
		int i;
		for (i = 0; (1ll << i) <= xx; i++);
		return i - 1;
	}
	ll convertBinaryToBase(ll x, int base) {
		if (x == 0) return 0;
		return base * convertBinaryToBase(x / 2, base) + (x % 2);
	}
	ll findFactor(ll k) {
		for (ll d = 2; d * d <= k; d++) if (k % d == 0) return d;
		return 0;
	}
};
class Palindrome {
public:
	Palindrome() {

	}
	int isPalindrome(ll xx) {
		ll x; int i, n; vector <int> v;
		for (x = xx; x > 0; x /= 10) {
			v.push_back(x % 10);
		}
		n = v.size();
		for (i = 0; i < n / 2; i++) {
			if (v[i] != v[n - i - 1]) return 0;
		}
		return 1;
	}
};
class BigNumber {
public:
	BigNumber() {

	}
	string add(string &s1, string &s2) {
		int i, j, k, n1, n2, a; string s3; vector<int> v;
		n1 = s1.size();
		n2 = s2.size();
		v.reserve(max(n1, n2) + 1);
		for (i = n1 - 1, j = n2 - 1; i >= 0 && j >= 0; i--, j--) {
			a = s1[i] - '0' + s2[j] - '0';
			v.push_back(a);
		}
		while (i >= 0) {
			a = s1[i] - '0';
			v.push_back(a);
			i--;
		}
		while (j >= 0) {
			a = s2[j] - '0';
			v.push_back(a);
			j--;
		}
		for (i = 0, a = 0; i < v.size(); i++) {
			a += v[i];
			if (a >= 10) {
				v[i] = a - 10;
				a = 1;
			}
			else {
				v[i] = a;
				a = 0;
			}
		}
		if (a) v.push_back(a);
		s3.reserve(v.size());
		for (i = v.size() - 1; i >= 0; i--) s3 += (char)(v[i] + '0');
		s3 += '\n';
		return s3;
	}
};
class PrimeNumber {
	int N; vector<int> NP, P;
	ll _powmod(ll a, ll b) {
		if (b == 0) return 1;
		if (b & 1) return a * _powmod(a, b - 1) % MOD;
		return _powmod(a * a % MOD, b / 2);
	}
public:
	PrimeNumber() {

	}
	PrimeNumber(int n) {
		N = n;
		NP.reserve(N + 4);
		P.reserve(N / 4);
		for (int i = 2; i*i <= N; i++) {
			if (NP[i]) continue;
			for (int j = i*i; j <= N; j += i) NP[i] = 1;
		}
		for (int i = 2; i <= N; i++) if (!NP[i]) P.push_back(i);
	}

	ll gcd(ll x, ll y) {
		ll z;
		while (x) {
			z = y%x;
			y = x;
			x = z;
		}
		return y;
	}

	ll powermod(ll p, ll q) {
		ll g = gcd(p, q);
		p /= g; q /= g;
		return p * _powmod(q, MOD - 2) % MOD;
	}

	vector<int> factorization(int x) {
		vector<int> ret; int i;
		if (x == 1) {
			ret.push_back(1);
			return ret;
		}
		ret.push_back(1); ret.push_back(x);
		for (i = 2; i*i < x; i++) {
			if (x%i == 0) {
				ret.push_back(i);
				ret.push_back(x / i);
			}
		}
		if (i*i == x) ret.push_back(i);
		return ret;
	}

	int factorization2(int x) {
		int ret = 0, i;
		if (x == 1) {
			return 1;
		}
		ret = 2;
		for (i = 2; i*i < x; i++) {
			if (x%i == 0) {
				ret += 2;
			}
		}
		if (i*i == x) ret++;
		return ret;
	}
};
class BitOperation {
public:
	BitOperation() {

	}
	int getOneBitNum(int xx) {
		int a = 0, x;
		for (x = xx; x; x = x&(x - 1)) a++;
		return a;
	}
};
class Comb {
	vector<vector<ll> > C; vector<ll> F; int N;
#define MOD_COMB MOD
public:
	Comb() {

	}
	Comb(int n) {
		init(n);
	}
	void init(int n) {
		N = n;
		C.resize(N + 1);
		for (int i = 0; i <= N; i++) C[i].resize(i + 1);
		for (int i = 0; i <= N; i++) C[i][i] = C[i][0] = 1;
		for (int i = 1; i <= N; i++) for (int j = 1; j < i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD_COMB;
		F.resize(N + 1);
		F[0] = F[1] = 1;
		for (int i = 1; i <= n; i++) F[i] = (F[i - 1] * i) % MOD_COMB;
	}
	ll getC(int n, int r) {
		return C[n][r];
	}
	ll getF(int n) {
		return F[n];
	}
	ll get_comb(int n, int r) {
		if (n == r || r == 0) return 1;
		if (n <= 1000) return getC(n, r);
		ll ret = 1; int i;
		if (r > n / 2) r = n - r;
		for (i = n; i > n - r; i--) ret *= i;
		for (i = 2; i <= r; i++) ret /= i;
		return ret;
	}
};
class Sort {
	vector<int> tmp;
	int N;
public:
	Sort(int n) {
		N = n;
		tmp.reserve(n + 4);
	}
	void merge_sort(vector<int> &x, int lo, int hi) {
		if (lo >= hi) return;
		int i, j, k, mid = (lo + hi) / 2;
		merge_sort(x, lo, mid); merge_sort(x, mid + 1, hi);
		for (i = lo, j = mid + 1, k = lo; i <= mid && j <= hi; k++) {
			if (x[i]<x[j]) tmp[k] = x[i++]; else tmp[k] = x[j++];
		}
		if (i <= mid) {
			for (; i <= mid; i++, k++) tmp[k] = x[i];
		}
		if (j <= hi) {
			for (; j <= hi; j++, k++) tmp[k] = x[j];
		}
		for (i = lo; i <= hi; i++) x[i] = tmp[i];
	}
};
class PSum {
	PSum() {

	}
	vector<int> makeSum(const vector<int> &a, int n) {
		vector<int> ret(a.size());
		ret[0] = a[0];
		for (int i = 1; i < a.size(); ++i)
			ret[i] = ret[i - 1] + a[i];
		return ret;
	}
	vector<vector<int> > makeSum(const vector<vector<int> > &a, int n, int m) {
		vector<vector<int> > ret(n, vector<int>(m));
		int i, j;
		for (i = 0; i < n; i++) ret[i][0] = a[i][0];
		for (i = 0; i < n; i++) {
			for (j = 1; j < m; j++) {
				ret[i][j] = ret[i][j - 1] + a[i][j];
			}
		}
	}
	int getSum(const vector<int>& psum, int a, int b) {
		if (a == 0) return psum[b];
		return psum[b] - psum[a - 1];
	}
	int getSum(const vector<vector<int> >&psum, int r1, int c1, int r2, int c2) {
		int ret = psum[r2][c2];
		if (r1 > 0) ret -= psum[r1 - 1][c2];
		if (c1 > 0) ret -= psum[r2][c1 - 1];
		if (r1 > 0 && c1 > 0) ret += psum[r1 - 1][c1 - 1];
		return ret;
	}
};
class DisjointSet {
	int N;
	vector<int> P, R, A;
public:
	DisjointSet(int n) {
		N = n;
		P = vector<int>(n + 1);
		R = vector<int>(n + 1);
		A = vector<int>(n + 1);
		for (int i = 1; i <= n; i++) P[i] = i, R[i] = 0, A[i] = 1;
	}
	int getA(int x) {
		return A[x];
	}
	int find_set(int x) {
		if (P[x] == x) return x;
		int pa = find_set(P[x]);
		return P[x] = pa;
	}
	int union_set(int x, int y) {
		int px, py;
		px = find_set(x); py = find_set(y);
		if (px == py) return px;
		if (R[px]>R[py]) {
			P[py] = px;
			A[px] += A[py];
			return px;
		}
		else {
			P[px] = py;
			A[py] += A[px];
			if (R[px] == R[py]) R[py]++;
			return py;
		}
	}
};
class LIS { // 0-based index
	int N, BI;
public:
	LIS(int n) {
		N = n;
	}
	int execute(vector<int> &A) { // nlogn
		int i, lo, hi, x, vi;
		vector<int> v = vector<int>(N, 0);
		vi = -1;
		v[++vi] = A[0];
		for (i = 1; i < N; i++) {
			if (A[i] > v[vi]) {
				v[++vi] = A[i];
				continue;
			}
			for (lo = 0, hi = vi; lo < hi; ) {
				if (v[(lo + hi) / 2] >= A[i]) hi = (lo + hi) / 2;
				else lo = (lo + hi) / 2 + 1;
			}
			v[hi] = A[i];
		}
		return vi + 1;
	}

	vector<int> execute2(vector<int> &A, int &len) { // nlogn
		vector<int> v, v1, p, ret; int i, j; // 0-based index
		v.push_back(A[0]); v1.push_back(0);
		p = vector<int>(N, -1);
		for (int i = 1; i < A.size(); i++) {
			if (v.back() < A[i]) {
				p[i] = v1.back();
				v.push_back(A[i]);
				v1.push_back(i);
			}
			else {
				vector<int>::iterator itr = lower_bound(v.begin(), v.end(), A[i]);
				*itr = A[i];
				int idx = itr - v.begin();
				if (idx != 0) {
					p[i] = v1[idx - 1];
				}
				v1[idx] = i;
			}
		}
		len = v1.size();
		ret = vector<int>(len);
		for (i = v1.back(), j = len - 1; i != -1; i = p[i], j--) ret[j] = A[i];
		return ret;
	}

	int execute3(vector<int> &A) { // n^2
		int i, j, ret = 0;
		vector<int> v = vector<int>(N, 0);
		for (i = 0; i<A.size(); i++) {
			for (j = 0; j<i; j++) if (A[j]<A[i] && v[i]<v[j]) v[i] = v[j];
			v[i]++;
		}
		for (i = 0; i<v.size(); i++) if (v[i]>ret) ret = v[i];
		return ret;
	}
};
class SegmentTreeSum {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = lv + rv;
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return 0;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return lv + rv;
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = lv + rv;
	}

public:
	SegmentTreeSum(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
class SegmentTreeMin {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = min(lv, rv);
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return INF;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return min(lv, rv);
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = min(lv, rv);
	}

public:
	SegmentTreeMin(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
class SegmentTreeMax {
	vector<ll> ST; vector<int> A; int N;

	ll _init(vector<int>&a, int left, int right, int node) {
		if (left == right) return ST[node] = a[left];
		int mid = (left + right) / 2;
		ll lv = _init(a, left, mid, node * 2), rv = _init(a, mid + 1, right, node * 2 + 1);
		return ST[node] = max(lv, rv);
	}

	ll _query(int left, int right, int node, int nodeLeft, int nodeRight) {
		if (right<nodeLeft || nodeRight<left) return 0;
		if (left <= nodeLeft && nodeRight <= right) return ST[node];
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _query(left, right, node * 2, nodeLeft, mid), rv = _query(left, right, node * 2 + 1, mid + 1, nodeRight);
		return max(lv, rv);
	}

	ll _update(int index, int newValue, int node, int nodeLeft, int nodeRight) {
		if (index<nodeLeft || nodeRight<index) return ST[node];
		if (nodeLeft == nodeRight) return ST[node] = newValue;
		int mid = (nodeLeft + nodeRight) / 2;
		ll lv = _update(index, newValue, node * 2, nodeLeft, mid), rv = _update(index, newValue, node * 2 + 1, mid + 1, nodeRight);
		return ST[node] = max(lv, rv);
	}

public:
	SegmentTreeMax(int n) {
		N = n;
		ST = vector<ll>(n * 4 + 4);
		A = vector<int>(n + 4);
	}

	void setA(int x, int y) {
		A[x] = y;
	}

	void init() {
		_init(A, 1, N, 1);
	}

	ll query(int left, int right) {
		return _query(left, right, 1, 1, N);
	}

	ll update(int index, int newValue) {
		return _update(index, newValue, 1, 1, N);
	}
};
struct Point {
	int x, y, mx;
	Point() {}
	Point(int x, int y, int mx) : x(x), y(y), mx(mx) {}
	bool operator < (const Point& other) const {
		return mx < other.mx;
	}
};
class SegmentTree2D { // 2D Segment Tree node
	vector<vector<int> > P; // container for 2D grid
	int N, M;
	vector<Point> T;

public:
	SegmentTree2D(int n, int m) {
		N = n; M = m;
		P = vector<vector<int> >(n + 1, vector<int>(m + 1));
		T = vector<Point>(n * m * 2);
		init();
		build(1, 1, 1, n, m);
	}
	void init() {
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= M; j++)
				scanf("%d", &P[i][j]);
	}
	// build a 2D segment tree from data [ (a1, b1), (a2, b2) ], O(n logn)
	Point build(int node, int a1, int b1, int a2, int b2) {
		if (a1 > a2 || b1 > b2) // out of range
			return def();

		// if it is only a single index, assign value to node
		if (a1 == a2 && b1 == b2)
			return T[node] = Point(a1, b1, P[a1][b1]);

		// split the tree into four segments
		T[node] = def();
		T[node] = maxNode(T[node], build(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2));
		T[node] = maxNode(T[node], build(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2));
		T[node] = maxNode(T[node], build(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2));
		T[node] = maxNode(T[node], build(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2));
		return T[node];
	}
	// query from range [ (x1, y1), (x2, y2) ], Time: O(logn)
	Point query(int x1, int y1, int x2, int y2) {
		return _query(1, 1, 1, N, M, x1, y1, x2, y2);
	}
	// helper function for query(int, int, int, int);
	Point _query(int node, int a1, int b1, int a2, int b2, int x1, int y1, int x2, int y2) {
		// if we out of range, return dummy
		if (x1 > a2 || y1 > b2 || x2 < a1 || y2 < b1 || a1 > a2 || b1 > b2)
			return def();

		// if it is within range, return the node
		if (x1 <= a1 && y1 <= b1 && a2 <= x2 && b2 <= y2)
			return T[node];

		// split into four segments
		Point mx = def();
		mx = maxNode(mx, _query(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2, x1, y1, x2, y2));
		mx = maxNode(mx, _query(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2, x1, y1, x2, y2));

		// return the maximum value
		return mx;
	}
	// helper function for update(int, int, int);
	Point _update(int node, int a1, int b1, int a2, int b2, int x, int y, int value) {
		if (a1 > a2 || b1 > b2)
			return def();

		if (x > a2 || y > b2 || x < a1 || y < b1)
			return T[node];

		if (x == a1 && y == b1 && x == a2 && y == b2)
			return T[node] = Point(x, y, value);

		Point mx = def();
		mx = maxNode(mx, _update(4 * node - 2, a1, b1, (a1 + a2) / 2, (b1 + b2) / 2, x, y, value));
		mx = maxNode(mx, _update(4 * node - 1, (a1 + a2) / 2 + 1, b1, a2, (b1 + b2) / 2, x, y, value));
		mx = maxNode(mx, _update(4 * node + 0, a1, (b1 + b2) / 2 + 1, (a1 + a2) / 2, b2, x, y, value));
		mx = maxNode(mx, _update(4 * node + 1, (a1 + a2) / 2 + 1, (b1 + b2) / 2 + 1, a2, b2, x, y, value));
		return T[node] = mx;
	}

	// update the value of (x, y) index to 'value', O(logn)
	Point update(int x, int y, int value) {
		return _update(1, 1, 1, N, M, x, y, value);
	}

	// utility functions; these functions are virtual because they will be overridden in child class
	virtual Point maxNode(Point a, Point b) {
		return max(a, b);
	}

	// dummy node
	virtual Point def() {
		return Point(0, 0, -INF);
	}

	void g() {
		int n, m;
		scanf("%d %d", &n, &m);

		SegmentTree2D Tmax(n, m);

		// query
		int x1, y1, x2, y2;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		printf("(%d,%d,%d,%d)=%d\n", x1, y1, x2, y2, Tmax.query(x1, y1, x2, y2).mx);

		// update
		int x, y, v;
		scanf("%d %d %d", &x, &y, &v);
		Tmax.update(x, y, v);

		// query
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		printf("(%d,%d,%d,%d)=%d\n", x1, y1, x2, y2, Tmax.query(x1, y1, x2, y2).mx);
	}
};
class TreeFromExpression {
public:
	TreeFromExpression() {

	}
	// http://codeforces.com/contest/935/problem/E
	// for example, str="((1?(5?7))?((6?2)?7))"
	vector<pair<int, int> > make(char *str, int &root) {
		int i, cur = 1;
		vector<pair<int, int> > E(10000);
		stack<int> S;
		for (i = 0; str[i]; i++) {
			char cc = str[i];
			if (cc >= '1' && cc <= '9') {
				E[cur].first = cc - '0';
				E[cur].second = 0;
				S.push(cur);
				cur++;
			}
			else if (cc == ')') {
				int a, b;
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				E[cur].first = a; E[cur].second = b;
				S.push(cur);
				cur++;
			}
		}
		root = cur - 1;
		return E;
	}
};
int main() {
	int i, j, k, n, m;
	scanf("%d%d", &n, &m); vector<vector<int> > A(n + 1, vector<int>(m + 1));
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			scanf("%d", &A[i][j]);
		}
	}
	vector<vector<int> > D(n + 1, vector<int>(m + 1));
	vector<int> E(n + 1);

	for (j = 1; j <= m; j++) {
		D[n][j] = 1;
		for (i = n - 1; i >= 1; i--) {
			if (A[i][j] <= A[i + 1][j]) D[i][j] = D[i + 1][j] + 1;
			else D[i][j] = 1;
		}
	}
	for (i = 1; i <= n; i++) {
		E[i] = D[i][1];
		for (j = 1; j <= m; j++) if (D[i][j] > E[i]) E[i] = D[i][j];
	}
	int x;
	scanf("%d", &x);
	for (i = 0; i < x; i++) {
		int a, b, c;
		scanf("%d%d", &a, &b);
		c = E[a];
		if (c >= (b-a+1)) printf("Yes\n");
		else printf("No\n");
	}
}


#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<string>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define N 120000
int n, m;

int a[2][N];
int dp[N];
int w[N];
void input()
{
	int i, j;
	for (i = 0; i < m; i++) {
		a[1][i] = 0;
		dp[i] = 0;
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf(" %d", &a[(i % 2)][j]);
			if (a[i%2][j] < a[(i+1)%2][j]) {
				dp[j] = i;
			}
		}
		w[i] = i;
		for (j = 0; j < m; j++) {
	//		printf("%d ", dp[j]);
			if (dp[j] < w[i]) {
				w[i] = dp[j];
			}
		}
	//	printf("\nw=%d\n", w[i]);
	}
}
void solve()
{
	int i, q, x, y;
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d %d", &x, &y);
		x--;
		y--;
		int z = w[y];
		if (z <= x) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
}

int main() {
	//	freopen("d:/out.txt", "w", stdout);
	//	freopen("d:/in.txt", "r", stdin);
	while (scanf("%d %d", &n, &m) != EOF) {
		input();
		//updateAC(0);
		solve();
	}
	return 0;
}


#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<string>
#include<queue>
#include<vector>
#include<map>
using namespace std;
#define N 120000
int n, m;

int a[2][N];
int dp[N];
int w[N];
void input()
{
	int i, j;
	for (i = 0; i < m; i++) {
		a[i][1] = 0;
		dp[i] = 0;
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf(" %d", &a[(i % 2)][j]);
			if (a[i%2][j] < a[(i+1)%2][j]) {
				dp[j] = i;
			}
		}
		w[i] = i;
		for (j = 0; j < m; j++) {
	//		printf("%d ", dp[j]);
			if (dp[j] < w[i]) {
				w[i] = dp[j];
			}
		}
	//	printf("\nw=%d\n", w[i]);
	}
}
void solve()
{
	int i, q, x, y;
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d %d", &x, &y);
		x--;
		y--;
		int z = w[y];
		if (z <= x) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}
}

int main() {
	//	freopen("d:/out.txt", "w", stdout);
	//	freopen("d:/in.txt", "r", stdin);
	while (scanf("%d %d", &n, &m) != EOF) {
		input();
		//updateAC(0);
		solve();
	}
	return 0;
}


#include <cmath>
#include <iostream>
#include<stdio.h>
#include<stack>
#include <string>
#include <algorithm>
#include<vector>
#include <ctime>
#include<queue>
#include<map>
#include<math.h>
#include <fstream>
#include<set>
#include<bitset>
#include<math.h>
#include <iomanip>
#include<random>
#include<tuple>
#include<istream>
using namespace std;

int bin_to_dec(string str) {
	int ans = 0;
	reverse(str.begin(), str.end());
	for (int i = 0; i < str.length(); i++) {
		ans += (str[i] - '0') * pow(double(2), i);
	}
	return ans;
}

string dec_to_bin(int a) {
	string ans = "";
	if (a == 0) ans = "0";
	while (a != 0) {
		ans += (a % 2) +'0';
		a /= 2;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

bool isPower(float a, float b)
{
	float num = log(a) / log(b);
	if (num - int(num) < 0.0000001) {
		int i_a = int(a);
		int i_b = int(b);
		while (i_a % i_b == 0) {
			i_a /= i_b;
			if (i_a == 1) {
				return true;
			}
		}
		return false;
	}
	return false;

}

/*
int l = 1, r = 1e9 + 5;
while (l<r)
{
int mid = (l + r) / 2;
if (can(mid))
r = mid;
else
l = mid + 1;
}
*/

bool check1(long long num) {
	num /= 1000000000;
	int sum = 0;
	for (int i = 0; i < 5; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 5 == 0) {
		return true;
	}
	return false;
}

bool check2(long long num) {
	int sum = 0;
	num /= 10000;
	for (int i = 0; i < 10; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 10 == 0) {
		return true;
	}
	return false;
}

bool check3(long long num) {
	int sum = 0;
	for (int i = 0; i < 14; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 20 == 0) {
		return true;
	}
	return false;
}

int main() {

	int i_size, j_size;
	cin >> i_size >> j_size;
	vector<vector<int>> arr(i_size, vector<int>(j_size));
	vector<vector<int>> up(i_size, vector<int>(j_size));
	for (int i = 0; i < i_size; i++) {
		for (int j = 0; j < j_size; j++) {
			cin >> arr[i][j];
		}
	}
	vector<int> best(i_size, 1);
	for (int j = 0; j < j_size; j++) {
		up[i_size - 1][j] = 1;
	}
	for (int j = 0; j < j_size; j++) {
		for (int i = i_size - 2; i >= 0; i--) {
			if (arr[i][j] <= arr[i + 1][j]) {
				up[i][j] = up[i + 1][j]+1;
				if (up[i][j] > best[i])
					best[i] = up[i][j];
			}
			else up[i][j] = 1;
		}
	}

	int k;
	cin >> k;
	int l, r;
	for (int i = 0; i < k; i++) {
		cin >> l >> r;
		l--; r--;
		if (best[l] >= r - l + 1)
			cout << "YES"<<endl;
		else
			cout << "NO"<<endl;
	}

	return 0;
}


#include <cmath>
#include <iostream>
#include<stdio.h>
#include<stack>
#include <string>
#include <algorithm>
#include<vector>
#include <ctime>
#include<queue>
#include<map>
#include<math.h>
#include <fstream>
#include<set>
#include<bitset>
#include<math.h>
#include <iomanip>
#include<random>
#include<tuple>
#include<istream>
using namespace std;

int bin_to_dec(string str) {
	int ans = 0;
	reverse(str.begin(), str.end());
	for (int i = 0; i < str.length(); i++) {
		ans += (str[i] - '0') * pow(double(2), i);
	}
	return ans;
}

string dec_to_bin(int a) {
	string ans = "";
	if (a == 0) ans = "0";
	while (a != 0) {
		ans += (a % 2) +'0';
		a /= 2;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

bool isPower(float a, float b)
{
	float num = log(a) / log(b);
	if (num - int(num) < 0.0000001) {
		int i_a = int(a);
		int i_b = int(b);
		while (i_a % i_b == 0) {
			i_a /= i_b;
			if (i_a == 1) {
				return true;
			}
		}
		return false;
	}
	return false;

}

/*
int l = 1, r = 1e9 + 5;
while (l<r)
{
int mid = (l + r) / 2;
if (can(mid))
r = mid;
else
l = mid + 1;
}
*/

bool check1(long long num) {
	num /= 1000000000;
	int sum = 0;
	for (int i = 0; i < 5; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 5 == 0) {
		return true;
	}
	return false;
}

bool check2(long long num) {
	int sum = 0;
	num /= 10000;
	for (int i = 0; i < 10; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 10 == 0) {
		return true;
	}
	return false;
}

bool check3(long long num) {
	int sum = 0;
	for (int i = 0; i < 14; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 20 == 0) {
		return true;
	}
	return false;
}

int main() {

	int i_size, j_size;
	cin >> i_size >> j_size;
	vector<vector<int>> arr(i_size, vector<int>(j_size));
	vector<vector<int>> up(i_size, vector<int>(j_size));
	for (int i = 0; i < i_size; i++) {
		for (int j = 0; j < j_size; j++) {
			cin >> arr[i][j];
		}
	}
	vector<int> best(i_size, 1);
	for (int j = 0; j < j_size; j++) {
		up[i_size - 1][j] = 1;
	}
	for (int j = 0; j < j_size; j++) {
		for (int i = i_size - 2; i >= 0; i--) {
			if (arr[i][j] <= arr[i + 1][j]) {
				up[i][j] = up[i + 1][j]+1;
				if (up[i][j] > best[i])
					best[i] = up[i][j];
			}
			else up[i][j] = 1;
		}
	}

	int k;
	cin >> k;
	int l, r;
	for (int i = 0; i < k; i++) {
		cin >> l >> r;
		l--; r--;
		if (best[l] >= r - l + 1)
			cout << "Yes"<<endl;
		else
			cout << "No"<<endl;
	}

	return 0;
}


#include <cmath>
#include <iostream>
#include<stdio.h>
#include<stack>
#include <string>
#include <algorithm>
#include<vector>
#include <ctime>
#include<queue>
#include<map>
#include<math.h>
#include <fstream>
#include<set>
#include<bitset>
#include<math.h>
#include <iomanip>
#include<random>
#include<tuple>
#include<istream>
using namespace std;

int bin_to_dec(string str) {
	int ans = 0;
	reverse(str.begin(), str.end());
	for (int i = 0; i < str.length(); i++) {
		ans += (str[i] - '0') * pow(double(2), i);
	}
	return ans;
}

string dec_to_bin(int a) {
	string ans = "";
	if (a == 0) ans = "0";
	while (a != 0) {
		ans += (a % 2) +'0';
		a /= 2;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

bool isPower(float a, float b)
{
	float num = log(a) / log(b);
	if (num - int(num) < 0.0000001) {
		int i_a = int(a);
		int i_b = int(b);
		while (i_a % i_b == 0) {
			i_a /= i_b;
			if (i_a == 1) {
				return true;
			}
		}
		return false;
	}
	return false;

}

/*
int l = 1, r = 1e9 + 5;
while (l<r)
{
int mid = (l + r) / 2;
if (can(mid))
r = mid;
else
l = mid + 1;
}
*/

bool check1(long long num) {
	num /= 1000000000;
	int sum = 0;
	for (int i = 0; i < 5; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 5 == 0) {
		return true;
	}
	return false;
}

bool check2(long long num) {
	int sum = 0;
	num /= 10000;
	for (int i = 0; i < 10; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 10 == 0) {
		return true;
	}
	return false;
}

bool check3(long long num) {
	int sum = 0;
	for (int i = 0; i < 14; i++) {
		sum += num % 10;
		num /= 10;
	}
	if (sum % 20 == 0) {
		return true;
	}
	return false;
}

int main() {

	int i_size, j_size;
	cin >> i_size >> j_size;
	vector<vector<int>> arr(i_size, vector<int>(j_size));
	vector<vector<int>> up(i_size, vector<int>(j_size));
	for (int i = 0; i < i_size; i++) {
		for (int j = 0; j < j_size; j++) {
			cin >> arr[i][j];
		}
	}
	vector<int> best(i_size, 1);
	for (int j = 0; j < j_size; j++) {
		up[i_size - 1][j] = 1;
	}
	for (int j = 0; j < j_size; j++) {
		for (int i = i_size - 2; i >= 0; i--) {
			if (arr[i][j] <= arr[i + 1][j]) {
				up[i][j] = up[i + 1][j]+1;
				if (up[i][j] > best[i])
					best[i] = up[i][j];
			}
			else up[i][j] = 1;
		}
	}

	int k;
	cin >> k;
	int l, r;
	for (int i = 0; i < k; i++) {
		cin >> l >> r;
		l--; r--;
		if (best[l] >= r - l + 1)
			cout << "YES";
		else
			cout << "NO";
	}

	return 0;
}


//http://codeforces.com/contest/777/problem/C

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef vector <int> vi;
typedef long long ll;

#define endl "\n"
#define mp make_pair

int n, m, k;
vector <vi> a, d;
int p[100005];

int main()
{
	int ii, jj;
	int l, r, st;
	bool flag;

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	a.resize(n);
	d.resize(n);

	for (ii = 0; ii < n; ii++)
	{
		a[ii].resize(m);
		d[ii].resize(m);

		for (jj = 0; jj < m; jj++)
			cin >> a[ii][jj];
	}

	for (ii = 0; ii < m; ii++)
		d[0][ii] = 1;

	for (ii = 1; ii < n; ii++)
	{
		for (jj = 0; jj < m; jj++)
		{
			if (a[ii][jj] >= a[ii - 1][jj])
				d[ii][jj] = d[ii - 1][jj];
			else
				d[ii][jj] = d[ii - 1][jj] + 1;
		}
	}

	for (ii = 0; ii < 100003; ii++)
		p[ii] = 1;

	for (ii = 0; ii < m; ii++)
	{
		st = 0;

		for (jj = 1; jj < n; jj++)
		{
			if (d[jj][ii] != d[jj - 1][ii])
				st = jj;

			p[st] = max(p[st], jj);
		}
	}

	cin >> k;

	for (ii = 0; ii < k; ii++)
	{
		cin >> l >> r;

		l--;
		r--;

		flag = p[l] >= r;

		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	cout << endl << endl;

	return 0;
}


//http://codeforces.com/contest/777/problem/C

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef vector <int> vi;
typedef long long ll;

#define endl "\n"
#define mp make_pair

int n, m, k;
vector <vi> a, d;
int p[100005];

int main()
{
	int ii, jj;
	int l, r, st;
	bool flag;

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	a.resize(n);
	d.resize(n);

	for (ii = 0; ii < n; ii++)
	{
		a[ii].resize(m);
		d[ii].resize(m);

		for (jj = 0; jj < m; jj++)
			cin >> a[ii][jj];
	}

	for (ii = 0; ii < m; ii++)
		d[0][ii] = 1;

	for (ii = 1; ii < n; ii++)
	{
		for (jj = 0; jj < m; jj++)
		{
			if (a[ii][jj] >= a[ii - 1][jj])
				d[ii][jj] = d[ii - 1][jj];
			else
				d[ii][jj] = d[ii - 1][jj] + 1;
		}
	}

	for (ii = 0; ii < 100003; ii++)
		p[ii] = ii;

	for (ii = 0; ii < m; ii++)
	{
		st = 0;

		for (jj = 1; jj < n; jj++)
		{
			if (d[jj][ii] != d[jj - 1][ii])
				st = jj;

			p[jj] = min(p[jj], st);
		}
	}

	cin >> k;

	for (ii = 0; ii < k; ii++)
	{
		cin >> l >> r;

		l--;
		r--;

		flag = p[r] <= l;

		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	cout << endl << endl;

	return 0;
}


//http://codeforces.com/contest/777/problem/C

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef vector <int> vi;
typedef long long ll;

#define endl "\n"
#define mp make_pair

int n, m, k;
vector <vi> a, d;
int p[100005];

int main()
{
	int ii, jj;
	int l, r, st;
	bool flag;

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	a.resize(n);
	d.resize(n);

	for (ii = 0; ii < n; ii++)
	{
		a[ii].resize(m);
		d[ii].resize(m);

		for (jj = 0; jj < m; jj++)
			cin >> a[ii][jj];
	}

	for (ii = 0; ii < m; ii++)
		d[0][ii] = 1;

	for (ii = 1; ii < n; ii++)
	{
		for (jj = 0; jj < m; jj++)
		{
			if (a[ii][jj] >= a[ii - 1][jj])
				d[ii][jj] = d[ii - 1][jj];
			else
				d[ii][jj] = d[ii - 1][jj] + 1;
		}
	}

	for (ii = 0; ii < 100003; ii++)
		p[ii] = ii;

	for (ii = 0; ii < m; ii++)
	{
		st = 0;

		for (jj = 1; jj < n; jj++)
		{
			if (d[jj][ii] != d[jj - 1][ii])
				st = jj;

			p[st] = max(p[st], jj);
		}
	}

	cin >> k;

	for (ii = 0; ii < k; ii++)
	{
		cin >> l >> r;

		l--;
		r--;

		flag = p[l] >= r;

		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	cout << endl << endl;

	return 0;
}


//http://codeforces.com/contest/777/problem/C

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

typedef pair <int, int> pii;
typedef pair <long long, long long> pll;
typedef vector <int> vi;
typedef long long ll;

#define endl "\n"
#define mp make_pair

int n, m, k;
vector <vi> a, d;
map <pii, bool> lr;

int main()
{
	int ii, jj;
	int l, r, st;
	bool flag;

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n >> m;

	a.resize(n);
	d.resize(n);

	for (ii = 0; ii < n; ii++)
	{
		a[ii].resize(m);
		d[ii].resize(m);

		for (jj = 0; jj < m; jj++)
			cin >> a[ii][jj];
	}

	for (ii = 0; ii < m; ii++)
		d[0][ii] = 1;

	for (ii = 1; ii < n; ii++)
	{
		for (jj = 0; jj < m; jj++)
		{
			if (a[ii][jj] >= a[ii - 1][jj])
				d[ii][jj] = d[ii - 1][jj];
			else
				d[ii][jj] = d[ii - 1][jj] + 1;
		}
	}

	lr[mp(0, 0)] = 1;

	for (ii = 0; ii < m; ii++)
	{
		st = 0;

		for (jj = 1; jj < n; jj++)
		{
			if (d[jj][ii] != d[jj - 1][ii])
				st = jj;

			lr[mp(st, jj)] = 1;
		}
	}

	cin >> k;

	for (ii = 0; ii < k; ii++)
	{
		cin >> l >> r;

		l--;
		r--;

		flag = lr[mp(l, r)];

		if (flag)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	cout << endl << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int a[100001],n,m,b[100001],c[100001],g[100001];
int main()
{
    int s,k;
    cin>>n>>m;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            scanf("%d",&s);
            if(b[j]>s)
                a[j]=1;
            else
                a[j]++;
            b[j]=s;
            if(c[i]<a[j])
                c[i]=a[j];
        }
    }
    cin>>k;
    int l,r;
    for(int i=1; i<=k; i++)
    {
        scanf("%d %d",&l,&r);
        if(c[r]-1>=r-l)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m, k, l, r, t[100005], ans[100005];
	cin >> n >> m;
	vector<vector<int>>num(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> num[i][j];

	for (int i = 0; i < 100005; i++)
		t[i] = 1;
	for (int i = 0; i < 100005; i++)
		ans[i] = 1e9;
	ans[0] = 1;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (num[i][j] < num[i - 1][j])
				t[j] = i + 1;
			ans[i] = min(ans[i], t[j]);
		}
	}

	cin >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r;
		if (ans[r - 1] <= l)
			cout << "Yes" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, m, j, l, r, num[100005] = {};
	cin >> n >> m;
	vector<vector<int>> v(n, vector<int>(m));
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int k = 0; k < m; k++)
			cin >> v[i][k];

	memset(num, 2, sizeof(num));
	num[0] = 1;
	for (int i = 0; i < m; i++)
		a[0][i] = 1;
	for (int i = 0; i < m; i++)
	{
		for (int k = 1; k < n; k++)
		{
			if (v[k][i] >= v[k - 1][i])
				a[k][i] = a[k - 1][i];
			else
				a[k][i] = k + 1;
			if (i >= 1)
				num[k] = min(num[k], a[k][i - 1]);
		}
	}
	cin >> j;
	for (int i = 0; i < j; i++)
	{
		cin >> l >> r;
		if (num[r - 1] <= l)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m, k, l, r, t[100005], ans[100005];
	cin >> n >> m;
	vector<vector<int>>num(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> num[i][j];

	for (int i = 0; i < 100005; i++)
		t[i] = 1;
	for (int i = 0; i < 100005; i++)
		ans[i] = 1e9;
	ans[0] = 1;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (num[i][j] < num[i - 1][j])
				t[j] = i + 1;
			ans[i] = min(ans[i], t[j]);
		}
	}

	cin >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r;
		if (ans[r - 1] <= l)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m, k, l, r, t[100005], ans[100005];
	cin >> n >> m;
	vector<vector<int>>num(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> num[i][j];

	for (int i = 0; i < 100005; i++)
		t[i] = 1;
	for (int i = 0; i < 100005; i++)
		ans[i] = 1e9;
	ans[0] = 1;
	cout << endl;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			if (num[i][j] < num[i - 1][j])
				t[j] = i + 1;
			ans[i] = min(ans[i], t[j]);
		}
	}

	cin >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r;
		if (ans[r - 1] <= l)
			cout << "Yes" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, m, j, l, r, num[100005] = {};
	cin >> n >> m;
	vector<vector<int>> v(n, vector<int>(m));
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; i++)
		for (int k = 0; k < m; k++)
			cin >> v[i][k];

	memset(num, 2, sizeof(num));
	num[0] = 1;
	for (int i = 0; i < m; i++)
		a[0][i] = 1;
	for (int i = 0; i < m; i++)
	{
		for (int k = 1; k < n; k++)
		{
			if (v[k][i] >= v[k - 1][i])
				a[k][i] = a[k - 1][i];
			else
				a[k][i] = k + 1;
			if (i >= 1)
				num[k] = min(num[k], a[k][i - 1]);
		}
	}
	cin >> j;
	for (int i = 0; i < j; i++)
	{
		cin >> l >> r;
		if (num[r - 1] <= l)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <fstream>
#include <stdio.h>
#include <time.h>

using namespace std;

#define flu fflush(stdout)
#define gg return 0

//long long mod = 1e9+7;
int inf = 1e9;

int main()
{
	int n, m;
	cin >> n >> m;
	vector <vector<int>> a(n);
	vector<vector<int>> mx(n);
	vector <int> dp(n, inf);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int t;
			cin >> t;
			a[i].push_back(t);
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			mx[i].push_back(i);
			if (i > 0 && a[i][j] >= a[i - 1][j])
			{
				mx[i][j] = mx[i - 1][j];
				if (dp[i] > mx[i][j])
				{
					dp[i] = mx[i][j];
				}
			}
		}
	}
	dp[0] = 0;
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		int a, b;
		cin >> a >> b;
		bool c = 0;
		if (dp[b - 1] <= a - 1)
		{
			cout << "Yes" << endl;
		}
		else
			cout << "No" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <fstream>
#include <stdio.h>
#include <time.h>

using namespace std;

#define flu fflush(stdout)
#define gg return 0

//long long mod = 1e9+7;
int inf = 1e9;

int main()
{
	int n, m;
	cin >> n >> m;
	vector <vector<int>> a(n);
	vector<vector<int>> mx(n);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int t;
			cin >> t;
			a[i].push_back(t);
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			mx[i].push_back(i);
			if (i > 0 && a[i][j] >= a[i - 1][j])
			{
				mx[i][j] = mx[i - 1][j];
			}
		}
	}

	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		int a, b;
		cin >> a >> b;
		bool c = 0;
		for (int j = 0; j < m; j++)
		{
			if (mx[b-1][j] <= a - 1)
			{
				cout << "Yes" << endl;
				c = 1;
				break;
			}
		}
		if (!c)
			cout << "No" << endl;
	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <fstream>
#include <stdio.h>
#include <time.h>

using namespace std;

#define flu fflush(stdout)
#define gg return 0

//long long mod = 1e9+7;
int inf = 1e9;

int main()
{
	int n, m;
	cin >> n >> m;
	vector <vector<int>> a(n);
	vector<vector<int>> mx(n);
	vector <int> dp(n);
	for (int i = 0; i < n; i++)
	{
		dp[i] = i;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int t;
			cin >> t;
			a[i].push_back(t);
		}
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			mx[i].push_back(i);
			if (i > 0 && a[i][j] >= a[i - 1][j])
			{
				mx[i][j] = mx[i - 1][j];
				dp[i] = min(dp[i], mx[i - 1][j]);
			}
		}
	}
	int k;
	cin >> k;
	for (int i = 0; i < k; i++)
	{
		int a, b;
		cin >> a >> b;
		bool c = 0;
		if (dp[b - 1] <= a - 1)
		{
			cout << "Yes" << endl;
		}
		else
			cout << "No" << endl;
	}

	return 0;
}


n,m=[int(x) for x in input().split()]
arr=[[int(x) for x in input().split()]for i in range(0,n)]
v=[[1]*m for i in range(0,n)]#a 2d array of size [n][m]
for i in range(0,m):
     for j in range(1,n):
          if(arr[j][i]>=arr[j-1][i]):
               v[j][i]=v[j-1][i]+1#if in increasing order increase value by 1

best=[max(i) for i in v]#to store largest value in row
ans=""
t=int(input())
for i in range(0,t):
     x,y=[int(s) for s in input().split()]
     if(best[y-1]>=y-x+1):#compare that largest value
          ans+="Yes\n"
     else :
          ans+="No\n"

print(ans)


m,n=[int(x) for x in input().split()]
l=[]
for i in range(m):
                l.append(list(map(int,input().split())))
o=int(input())
ans=""
for i in range(o):
                x,y=[int(x) for x in input().split()]
                if x==y:
                                ans+="Yes\n"
                                continue
                for k in range(0,n-1):
                                for j in range(x-1,y-1):
                                                if l[j][k]>l[j+1][k]:break
                                else:
                                                ans+="Yes\n"
                                                break
                else:ans+="No\n"
print(ans)


n,m=[int(x) for x in input().split()]
arr=[[int(x) for x in input().split()]for i in range(0,n)]
v=[[1]*m for i in range(0,n)]#a 2d array of size [n][m]
for i in range(0,m):
     for j in range(1,n):
          if(arr[j][i]>=arr[j-1][i]):
               v[j][i]=v[j-1][i]+1#if in increasing order increase value by 1

best=[max(i) for i in v]#to store largest value in row

t=int(input())
for i in range(0,t):
     x,y=[int(s) for s in input().split()]
     if(best[y-1]>=y-x+1):#compare that largest value
          print("Yes")
     else :
          print("No")


from collections import defaultdict

n,m = map(int,input().split())
l = []
ans = []
for i in range(n):
    k = list(map(int,input().split()))
    l.append(k)
    c = [1]*(len(k))
    ans.append(c)
hash = defaultdict(set)
for j in range(m):
    count = 0
    for i in range(1,n):
        if l[i][j]>=l[i-1][j]:
            ans[i][j]=ans[i-1][j]
        else:
            ans[i][j] = i+1
# print(ans)
bo = []
q = int(input())
for i in range(n):
    mini = 10**18
    for j in range(m):
        mini = min(ans[i][j],mini)

    bo.append(mini)

# print(bo)

for i in range(q):
    a,b = map(int,input().split())
    if a == b:
        print('Yes')
    else:
        if bo[b-1]<=a:
            print('Yes')
        else:
            print('No')


n,m = map(int,input().split())
l = []
ans = []
for i in range(n):
    k = list(map(int,input().split()))
    l.append(k)
    c = [1]*(len(k))
    ans.append(c)
hash = {}
for j in range(m):
    count = 0
    for i in range(1,n):
        if l[i][j]>=l[i-1][j]:
            ans[i][j]=ans[i-1][j]
        else:
            ans[i][j] = i+1
# print(ans)
bo = []
q = int(input())
for i in range(n):
    mini = 10**18
    for j in range(m):
        mini = min(ans[i][j],mini)

    bo.append(mini)

# print(bo)
lo = []
for i in range(q):
    a,b = map(int,input().split())
    try:
        hash[(a,b)]
    except:

     if a == b:
        lo.append('Yes')
        hash[(a,b)] = 'Yes'

     else:
        if bo[b-1]<=a:
            lo.append('Yes')
            hash[(a,b)] = 'Yes'
        else:
            lo.append('No')
            hash[(a,b)] = 'No'
    else:
        lo.append(hash[(a,b)])

print(*lo)


from sys import stdin, stdout

def main():
    n, m = map(int, stdin.readline().split())
    k = []
    for i in range(n):
        k.append(list(map(int, stdin.readline().split())))
    ans = []
    BASE = [1 for i in range(m)]
    ans.append(list(BASE))
    for i in range(1, n):
        ans.append(list(BASE))
        for j in range(m):
            if k[i][j] >= k[i - 1][j]:
                ans[i][j] = ans[i - 1][j] + 1
            else:
                ans[i][j] = 1

    max_ans = [0 for i in range(n)]
    for i in range(n):
        max_ans[i] = max(ans[i])

    k = int(stdin.readline())
    answer = []
    for i in range(k):
        l, r = map(int, stdin.readline().split())
        if (max_ans[r - 1] >= (r - l + 1)):
            answer.append("Yes\n")
        else:
            answer.append("No\n")
    stdout.write(''.join(ans))

main()


n, m = map(int, input().split())
k = []
for i in range(n):
    k.append(list(map(int, input().split())))
ans = []
BASE = [1 for i in range(m)]
ans.append(list(BASE))
for i in range(1, n):
    ans.append(list(BASE))
    for j in range(m):
        if k[i][j] >= k[i - 1][j]:
            ans[i][j] = ans[i - 1][j] + 1
        else:
            ans[i][j] = 1

max_ans = [0 for i in range(n)]
for i in range(n):
    max_ans[i] = max(ans[i])

k = int(input())
for i in range(k):
    l, r = map(int, input().split())
    if (max_ans[r - 1] >= (r - l + 1)):
        print("Yes")
    else:
        print("No")


from sys import stdin, stdout

int main():
    n, m = map(int, stdin.readline().split())
    k = []
    for i in range(n):
        k.append(list(map(int, stdin.readline().split())))
    ans = []
    BASE = [1 for i in range(m)]
    ans.append(list(BASE))
    for i in range(1, n):
        ans.append(list(BASE))
        for j in range(m):
            if k[i][j] >= k[i - 1][j]:
                ans[i][j] = ans[i - 1][j] + 1
            else:
                ans[i][j] = 1

    max_ans = [0 for i in range(n)]
    for i in range(n):
        max_ans[i] = max(ans[i])

    k = int(stdin.readline())
    answer = []
    for i in range(k):
        l, r = map(int, stdin.readline().split())
        if (max_ans[r - 1] >= (r - l + 1)):
            answer.append("Yes\n")
        else:
            answer.append("No\n")
    stdout.write(''.join(ans))

main()


from sys import stdin, stdout

def main():
    n, m = map(int, stdin.readline().split())
    k = []
    for i in range(n):
        k.append(list(map(int, stdin.readline().split())))
    ans = []
    BASE = [1 for i in range(m)]
    ans.append(list(BASE))
    for i in range(1, n):
        ans.append(list(BASE))
        for j in range(m):
            if k[i][j] >= k[i - 1][j]:
                ans[i][j] = ans[i - 1][j] + 1
            else:
                ans[i][j] = 1

    max_ans = [0 for i in range(n)]
    for i in range(n):
        max_ans[i] = max(ans[i])

    k = int(stdin.readline())
    answer = []
    for i in range(k):
        l, r = map(int, stdin.readline().split())
        if (max_ans[r - 1] >= (r - l + 1)):
            answer.append("Yes\n")
        else:
            answer.append("No\n")
    stdout.write(''.join(answer))

main()


#---------------EL FUTURO ES INCIERTO--------------#
n,m=[int(x) for x in input().split()]
arr=[[int(x) for x in input().split()]for i in range(0,n)]
p = [ i for i in range(0,n+1)]

for j in range(0,m):
	cur = 0
	for i in range(1,n):
		if(arr[i][j] <= arr[i-1][j]):
			a = 1 #nothing
		else:
			p[i] = min(p[i],cur)
			cur = i
	#end for
	if cur != n-1:
		p[n-1] = min(cur,p[n-1])
#end for

q = int(input())

for _ in range(0,q):
	a,b = [int(x) for x in input().split()]
	b-=1
	a-=1
	if(p[b] <= a):
		print("Yes")
	else:
		print("No")
#end for


#---------------EL FUTURO ES INCIERTO--------------#

import sys
from sys import stdin, stdout

n, m = map(int, stdin.readline().rstrip().split())
arr = [map(int,stdin.readline().rstrip().split()) for i in range(0,n)]

p = [ i for i in range(0,n+1)]

for j in range(0,m):
	cur = 0
	for i in range(1,n):
		if(arr[i][j] <= arr[i-1][j]):
			a = 1 #nothing
		else:
			p[i] = min(p[i],cur)
			cur = i
	#end for
	if cur != n-1:
		p[n-1] = min(cur,p[n-1])
#end for

q = int(input())

for _ in range(0,q):
	a,b = map(int, stdin.readline().rstrip().split())
	b-=1
	a-=1
	if(p[b] <= a):
		stdout.write("Yes\n")
	else:
		stdout.write("No\n")
#end for


#---------------EL FUTURO ES INCIERTO--------------#
n,m=[int(x) for x in input().split()]
arr=[[int(x) for x in input().split()]for i in range(0,n)]
p = [ i for i in range(0,n+1)]

for j in range(0,m):
	cur = 0
	for i in range(0,n-1):
		if(arr[i][j] <= arr[i+1][j]):
			p[i+1] = min(cur,p[i+1])
		else:
			cur = i+1
	#end for
#end for

q = int(input())
res =""
for _ in range(0,q):
	a,b = [int(x) for x in input().split()]
	b-=1
	a-=1
	if(p[b] <= a):
		res+="Yes"
	else:
		res+="No"
	if _!=q-1:
	    res+="\n"
#end for

print (res)


#---------------EL FUTURO ES INCIERTO--------------#
n,m=[int(x) for x in input().split()]
arr=[[int(x) for x in input().split()]for i in range(0,n)]
p = [ i for i in range(0,n+1)]

for j in range(0,m):
	cur = 0
	for i in range(1,n):
		if(arr[i][j] <= arr[i-1][j]):
			a = 1 #nothing
		else:
			p[i] = min(p[i],cur)
			cur = i
	#end for
	if cur != n-1:
		p[n-1] = min(cur,p[n-1])
#end for

q = int(input())
res =""
for _ in range(0,q):
	a,b = [int(x) for x in input().split()]
	b-=1
	a-=1
	if(p[b] <= a):
		res+="Yes"
	else:
		res+="No"
	if _!=q-1:
	    res+="\n"
#end for

print (res)


n,m = list(map(int,input().split()))
matrix = []
for _ in range(n):
	row = list(map(int,input().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

# print(A)

# second-level table
rows = [0] * n
for i in range(n):
	lst = [A[i][j] for j in range(m)]
	rows[i] = max(lst)

# print(rows)
def process(l,r):
	if rows[l-1] >= (r-l) + 1:
		print("YES")
	else:
		print("NO")

k = int(input())
for _ in range(k):
	l,r = list(map(int,input().split()))
	process(l,r)


import sys
n,m = map(int,sys.stdin.readline().rstrip().split())
matrix = []
for _ in range(n):
	row = list(map(int,sys.stdin.readline().rstrip().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

# rows = [0] * n
# for i in range(n):
# 	lst = [A[i][j] for j in range(m)]
# 	rows[i] = max(lst)
rows = [max(row) for row in A]

ans = ""
k = int(sys.stdin.readline().rstrip())
for _ in range(k):
	l,r = map(int,sys.stdin.readline().rstrip().split())
	if rows[l-1] >= (r - l + 1):
		ans += "Yes\n"
	else:
		ans += "No\n"
sys.stdout.write(ans)


import sys
n,m = list(map(int,sys.stdin.readline().split()))
matrix = []
for _ in range(n):
	row = list(map(int,input().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

# print(A)

# second-level table
rows = [0] * n
for i in range(n):
	lst = [A[i][j] for j in range(m)]
	rows[i] = max(lst)

ans = ""
# print(rows)
def process(l,r):
	global ans
	if rows[l-1] >= (r-l) + 1:
		ans += "Yes\n"
	else:
		ans += "No\n"

k = int(input())
for _ in range(k):
	l,r = list(map(int,input().split()))
	process(l,r)
sys.stdout.write(ans)


n,m = list(map(int,input().split()))
matrix = []
for _ in range(n):
	row = list(map(int,input().split()))
	matrix.append(row)

def process(l,r):
	sub = matrix[l-1:r]
	exists = False
	for j in range(m):
		flag = True
		for i in range(len(sub)-1):
			if sub[i][j] > sub[i+1][j]:
				flag = False
				break
		if flag:
			exists = True
			break
	if exists:
		print("Yes")
	else:
		print("No")

k = int(input())
for _ in range(k):
	l,r = list(map(int,input().split()))
	process(l,r)


n,m = list(map(int,input().split()))
matrix = []
for _ in range(n):
	row = list(map(int,input().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

print(A)

# second-level table
rows = [0] * n
for i in range(n):
	lst = [A[i][j] for j in range(m)]
	rows[i] = max(lst)

print(rows)
def process(l,r):
	if rows[l-1] >= (r-l) + 1:
		print("YES")
	else:
		print("NO")

k = int(input())
for _ in range(k):
	l,r = list(map(int,input().split()))
	process(l,r)


import sys
n,m = map(int,sys.stdin.readline().split())
matrix = []
for _ in range(n):
	row = list(map(int,sys.stdin.readline().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

# print(A)

# second-level table
rows = [0] * n
for i in range(n):
	lst = [A[i][j] for j in range(m)]
	rows[i] = max(lst)

ans = ""
# print(rows)
def process(l,r):
	global ans
	if rows[l-1] >= (r-l) + 1:
		ans += "Yes\n"
	else:
		ans += "No\n"

k = int(input())
for _ in range(k):
	l,r = map(int,sys.stdin.readline().split())
	process(l,r)
sys.stdout.write(ans)


n,m = list(map(int,input().split()))
matrix = []
for _ in range(n):
	row = list(map(int,input().split()))
	matrix.append(row)

# initialize table
A = [[1 for _ in range(m)] for _ in range(n)]
for i in range(n-2,-1,-1):
	for j in range(m):
		if matrix[i][j] <= matrix[i+1][j]:
			A[i][j] = A[i+1][j] + 1

# print(A)

# second-level table
rows = [0] * n
for i in range(n):
	lst = [A[i][j] for j in range(m)]
	rows[i] = max(lst)

# print(rows)
def process(l,r):
	if rows[l-1] >= (r-l) + 1:
		print("Yes")
	else:
		print("No")

k = int(input())
for _ in range(k):
	l,r = list(map(int,input().split()))
	process(l,r)


n,m = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
depth = [[1]*m for i in range(n)]
for col in range(m):
    for row in range(1,n):
        if M[row][col]>=M[row-1][col]:
            depth[row][col] = depth[row-1][col]+1
max_depth = [max(row) for row in depth]
k = int(input())
for i in range(k):
    l,r = map(int,input().split())
    if max_depth[r-1] >= r-l+1:
        print("Yes")
    else:
        print("No")


from sys import stdin,stdout
n,m = map(int,stdin.readline().split())
M = [list(map(int,stdin.readline().split())) for i in range(n)]
depth = [[1]*m for i in range(n)]
for col in range(m):
    for row in range(1,n):
        if M[row][col]>=M[row-1][col]:
            depth[row][col] = depth[row-1][col]+1
max_depth = [max(row) for row in depth]
ans = ""
k = int(input())
for i in range(k):
    l,r = map(int,stdin.readline().split())
    if max_depth[r-1] >= r-l+1:
        ans+="Yes\n"
    else:
        ans+="No\n"
stdout.write(ans)


n,m = map(int,input().split())
M = [list(map(int,input().split())) for i in range(n)]
depth = [[1]*m for i in range(n)]
for col in range(m):
    for row in range(1,n):
        if M[row][col]>=M[row-1][col]:
            depth[row][col] = depth[row-1][col]+1
max_depth = [max(row) for row in depth]
ans = ""
k = int(input())
for i in range(k):
    l,r = map(int,input().split())
    if max_depth[r-1] >= r-l+1:
        ans+="Yes\n"
    else:
        ans+="No\n"
print(ans)


import sys
N, M = map( int, input().split() )
G = [ list( map( int, input().split() ) ) for i in range( N ) ]

rmaxv = [ 0 for i in range( N ) ]
for i in range( M ):
  reach = [ 0 for j in range( N ) ]
  for j in range( N - 1, -1, -1 ):
    if j + 1 == N or not ( G[ j ][ i ] <= G[ j + 1 ][ i ] ):
      reach[ j ] = 1
    else:
      reach[ j ] = reach[ j + 1 ] + 1
    rmaxv[ j ] = max( rmaxv[ j ], reach[ j ] )

Q = int( input() )
ans = []
for qi in range( Q ):
  L, R = map( int, input().split() )
  if rmaxv[ L - 1 ] >= R - L + 1:
    ans.append( "Yes\n" )
  else:
    ans.append( "No\n" )
sys.stdout.write( ''.join( ans ) )


N, M = map( int, input().split() )
G = [ list( map( int, input().split() ) ) for i in range( N ) ]

rmaxv = [ 0 for i in range( N ) ]
for i in range( M ):
  reach = [ 0 for j in range( N ) ]
  for j in range( N - 1, -1, -1 ):
    if j + 1 == N or not ( G[ j ][ i ] <= G[ j + 1 ][ i ] ):
      reach[ j ] = 1
    else:
      reach[ j ] = reach[ j + 1 ] + 1
    rmaxv[ j ] = max( rmaxv[ j ], reach[ j ] )

Q = int( input() )
for qi in range( Q ):
  L, R = map( int, input().split() )
  if rmaxv[ L - 1 ] >= R - L + 1:
    print( "Yes" )
  else:
    print( "No" )


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)] + [[-1]*m]
    rr = list(range(n))
    for j in range(m):
        l = 0
        for r in range(1,n+1):
            if a[r][j] < a[r-1][j]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    else:
                        l = r
                        break
                    l += 1

    #print(rr)
    k = II()
    ans = []
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            ans.append('Yes')
        else:
            ans.append('No')

    print('\n'.join(ans))

main()


from sys import stdin,stdout
n,m = map(int,stdin.readline().split())
ans = [float('infinity')] * n
cou = [0] * m
A = [0] *n
A[0] = list(map(int,stdin.readline().split()))
ans[0]=0
for j in range(1,n):
    A[j] = list(map(int,stdin.readline().split()))
    for i in range(m):
        if A[j][i] < A[j-1][i]:
            cou[i] = j
        ans[j] = min(ans[j],cou[i])
k=int(stdin.readline())
for j in range(k):
    per1,per2 = map(int,stdin.readline().split())
    if ans[per2-1] +1<=per1:
        stdout.write('Yes')

    else:
        stdout.write('No')
    stdout.write('\n')


from sys import stdin,stdout
n,m = map(int,stdin.readline().split())
ans = [float('infinity')] * n
cou = [0] * m
A = [0] *n
A[0] = list(map(int,stdin.readline().split()))
ans[0]=0
for j in range(1,n):
    A[j] = list(map(int,stdin.readline().split()))
    for i in range(m):
        if A[j][i] < A[j-1][i]:
            cou[i] = j
        ans[j] = min(ans[j],cou[i])
k=int(stdin.readline())
for j in range(k):
    per1,per2 = map(int,stdin.readline().split())
    if ans[per2-1] +1<=per1:
        stdout.write('YES')

    else:
        stdout.write('NO')
    stdout.write('\n')


n, m = map(int, input().split())
M = [list(map(int, input().split())) for r in range(n)]

depth = [[1] * m for r in range(n)]

for c in range(m):
    for r in range(1, n):
        if M[r][c] >= M[r - 1][c]:
            depth[r][c] = depth[r - 1][c] + 1

max_depth = [max(col) for col in depth]

ans = ""
k = int(input())
for i in range(k):
    l, r = map(int, input().split())
    if max_depth[r - 1] >= r - l + 1:
        ans += "Yes\n"
    else:
        ans += "No\n"

print(ans)


n, m = map(int, input().split())
M = [list(map(int, input().split())) for r in range(n)]

depth = [[1] * m for r in range(n)]

for c in range(m):
    for r in range(1, n):
        if M[r][c] >= M[r - 1][c]:
            depth[r][c] = depth[r - 1][c] + 1

max_depth = [max(col) for col in depth]

k = int(input())
for i in range(k):
    l, r = map(int, input().split())
    if max_depth[r - 1] >= r - l + 1:
        print("Yes")
    else:
        print("No")


n,m = [int(x) for x in input().split()]
arr = [[int(x) for x in input().split()] for i in range(n)]

val = [ [1]*m for i in range(n)]
for i in range(m):
	for j in range(n-2,-1,-1):
		if arr[j][i]<=arr[j+1][i]:
			val[j][i] = val[j+1][i] + 1

best = [max(i) for i in val]

ans = ""
t = int(input())
for i in range(t):
	c,d = [int(x) for x in input().split()]
	if best[c-1]>=d-c+1:
		ans += "Yes\n"
	else:
		ans += "No\n"
print(ans)

# Made By Mostafa_Khaled


import sys
input = sys.stdin.readline
n, m = map(int,input().split())
arr=[]
for i in range(n):
    arr.append(list(map(int,input().split())))
mp = []
for i in range(n):
    mp.append(i+1)
for i in range(m):
    pre=-1
    st=0
    for j in range(n):
        if arr[j][i]<pre :
            pre=arr[j][i]
            st=j
            mp[j]=min(mp[j],st)
        else :
            mp[j]=min(mp[j],st)
            pre=arr[j][i]
m=int(input())
for i in range(m):
    a,b=map(int,input().split())
    if mp[b-1]<=a-1 :
        print("Yes")
    else :
        print("No")


import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    n, m = map(int, sys.stdin.readline().split())
    A = [[int(i) for i in sys.stdin.readline().split()] for j in range(n)]
    q = int(sys.stdin.readline().rstrip())
    querys = [tuple(map(int, sys.stdin.readline().split())) for i in range(q)]

    f = [i for i in range(n)]

    for j in range(m):
        s = 0
        for i in range(n):
            if i == n - 1 or A[i][j] > A[i + 1][j]:
                for k in range(s, i + 1):
                    f[k] = max(f[k], i)
                s = i + 1

    ans = []

    for l, r in querys:
        if r-1 <= f[l-1]:
            ans.append('Yes')
        else:
            ans.append('No')

    print(*ans, sep='\n')

if __name__ == '__main__':
    solve()


import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    n, m = map(int, input().split())
    A = [[int(i) for i in input().split()] for j in range(n)]

    #debug

    f = [i for i in range(n)]

    for j in range(m):
        s = 0
        for i in range(n):
            # print(i)
            if i == n - 1 or A[i][j] > A[i + 1][j]:
                for k in range(s, i + 1):
                    f[k] = max(f[k], i)
                s = i + 1
                # print(f)

    # debug(f, locals())

    q = int(input())

    for query in range(q):
        l, r = map(int, input().split())
        l, r = l-1, r-1
        if f[l] >= r:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    solve()


#!/usr/bin/env python3
def ri():
    return map(int, input().split())

n, m = ri()
a = []
for i in range(n):
    a.append(list(ri()))

t = [[0 for i in range(m)] for j in range(n)]

for i in range(m):
    for j in range(n-1):
        if a[j][i] > a[j+1][i]:
            t[j+1][i] = t[j][i]
        else:
            t[j+1][i] = t[j][i] + 1

k = int(input())
for i in range(k):
    l, r = ri()
    l = l-1
    r = r-1
    for j in range(m):
        if t[r][j] - t[l][j] == r-l:
            print("YES")
            break
    else:
        print("NO")


#!/usr/bin/env python3
def ri():
    return map(int, input().split())

n, m = ri()
a = []
for i in range(n):
    a.append(list(ri()))

t = [[0 for i in range(m)] for j in range(n)]
T = [0 for i in range(n)]

for i in range(m):
    for j in range(n-1):
        if a[j][i] > a[j+1][i]:
            t[j+1][i] = 0
        else:
            t[j+1][i] = t[j][i] + 1
for i in range(n):
    T[i] = max(t[i])

k = int(input())
for i in range(k):
    l, r = ri()
    l = l-1
    r = r-1
    if T[r] >= r-l:
        print("Yes")
    else:
        print("No")


#!/usr/bin/env python3
def ri():
    return map(int, input().split())

n, m = ri()
a = []
for i in range(n):
    a.append(list(ri()))

t = [[0 for i in range(m)] for j in range(n)]

for i in range(m):
    for j in range(n-1):
        if a[j][i] > a[j+1][i]:
            t[j+1][i] = t[j][i]
        else:
            t[j+1][i] = t[j][i] + 1

k = int(input())
for i in range(k):
    l, r = ri()
    l = l-1
    r = r-1
    for j in range(m):
        if t[r][j] - t[l][j] == r-l:
            print("Yes")
            break
    else:
        print("No")


#!/usr/bin/env python3
def ri():
    return map(int, input().split())

n, m = ri()
a = []
for i in range(n):
    a.append(list(ri()))

t = [[0 for i in range(m)] for j in range(n)]
T = [0 for i in range(n)]

for i in range(m):
    for j in range(n-1):
        if a[j][i] > a[j+1][i]:
            t[j+1][i] = 0
        else:
            t[j+1][i] = t[j][i] + 1
for i in range(n):
    T[i] = max(t[i])

k = int(input())
ans = []
for i in range(k):
    l, r = ri()
    l = l-1
    r = r-1
    if T[r] >= r-l:
        ans.append("Yes")
    else:
        ans.append("No")

print('\n'.join(ans))


from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
if n == 1:
    print("Yes")
    exit()

data = []
for i in range(0, n):
    data.append(list(map(int, stdin.readline().rstrip().split())))

sorted_data = []
for col in range(0, m):
    mark_r = 0
    cur_r = 1
    st = []
    while cur_r < n:
        if data[cur_r][col] < data[cur_r - 1][col]:
            st.extend([cur_r - 1] * (cur_r - mark_r))
            mark_r = cur_r
        cur_r += 1
    st.extend([cur_r - 1] * (cur_r - mark_r))
    sorted_data.append(st)

q_count = int(stdin.readline().rstrip())
for _ in range(0, q_count):
    l, r = map(lambda x: int(x) - 1, stdin.readline().rstrip().split())
    for col in range(0, m):
        if sorted_data[col][l] >= r:
            print("Yes")
            break
    else:
        print("No")


from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())

data = []
for i in range(0, n):
    data.append(list(map(int, stdin.readline().rstrip().split())))

sorted_data = [0] * n
for col in range(0, m):
    mark_r = 0
    cur_r = 1
    st = []
    while cur_r < n:
        if data[cur_r][col] < data[cur_r - 1][col]:
            st.extend([cur_r - 1] * (cur_r - mark_r))
            mark_r = cur_r
        cur_r += 1
    st.extend([cur_r - 1] * (cur_r - mark_r))
    for index, item in enumerate(st):
        if sorted_data[index] < st[index]:
            sorted_data[index] = st[index]

q_count = int(stdin.readline().rstrip())
for _ in range(0, q_count):
    l, r = map(lambda x: int(x) - 1, stdin.readline().rstrip().split())
    if sorted_data[l] >= r:
        print("Yes")
    else:
        print("No")


from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
if n == 1:
    print("Yes")
    exit()

data = []
for i in range(0, n):
    data.append(list(map(int, stdin.readline().rstrip().split())))

sorted_data = [0] * n
for col in range(0, m):
    mark_r = 0
    cur_r = 1
    st = []
    while cur_r < n:
        if data[cur_r][col] < data[cur_r - 1][col]:
            st.extend([cur_r - 1] * (cur_r - mark_r))
            mark_r = cur_r
        cur_r += 1
    st.extend([cur_r - 1] * (cur_r - mark_r))
    for index, item in enumerate(st):
        if sorted_data[index] < st[index]:
            sorted_data[index] = st[index]

q_count = int(stdin.readline().rstrip())
for _ in range(0, q_count):
    l, r = map(lambda x: int(x) - 1, stdin.readline().rstrip().split())
    if sorted_data[l] >= r:
        print("Yes")
    else:
        print("No")


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    rr = list(range(n))
    for j in range(m):
        b = [a[i][j] for i in range(n)] + [-1]
        l = 0
        for r in range(1,m+2):
            if b[r] < b[r-1]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    l += 1

    #print(rr)
    k = II()
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            print('Yes')
        else:
            print('No')

main()


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)] + [[-1]*m]
    rr = list(range(n))
    for j in range(m):
        l = 0
        for r in range(1,n+1):
            if a[r][j] < a[r-1][j]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    else:
                        l = r
                        break
                    l += 1

    #print(rr)
    k = II()
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            print('Yes')
        else:
            print('No')

main()


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)] + [[-1]*m]
    rr = list(range(n))
    for j in range(m):
        l = 0
        for r in range(1,n+1):
            if a[r][j] < a[r-1][j]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    else:
                        l = r
                        break
                    l += 1

    #print(rr)
    k = II()
    t = []
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            t.append('Yes')
        else:
            t.append('No')

    return '\n'.join(t)

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    rr = list(range(n))
    for j in range(m):
        b = [a[i][j] for i in range(n)] + [-1]
        l = 0
        for r in range(1,n+1):
            if b[r] < b[r-1]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    else:
                        l = r
                        break
                    l += 1

    #print(rr)
    k = II()
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            print('Yes')
        else:
            print('No')

main()


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)] + [[-1]*m]
    rr = list(range(n))
    for j in range(m):
        l = 0
        for r in range(1,n+1):
            if a[r][j] < a[r-1][j]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    else:
                        l = r
                        break
                    l += 1

    #print(rr)
    k = II()
    l,r = LI()
    t = ''
    if rr[l-1] >= r-1:
        t='Yes'
    else:
        t='No'
    for _ in range(k-1):
        l,r = LI()
        if rr[l-1] >= r-1:
            t+='\nYes'
        else:
            t+='\nNo'

    return t

print(main())


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
    n,m = LI()
    a = [LI() for _ in range(n)]
    rr = list(range(n))
    for j in range(m):
        b = [a[i][j] for i in range(n)] + [-1]
        l = 0
        for r in range(1,n+1):
            if b[r] < b[r-1]:
                while l < r:
                    if rr[l] < r-1:
                        rr[l] = r-1
                    l += 1

    #print(rr)
    k = II()
    for _ in range(k):
        l,r = LI()
        if rr[l-1] >= r-1:
            print('Yes')
        else:
            print('No')

main()


n,x=map(int,raw_input().split())
num=[0 for i in range(10**5)]
a=map(int,raw_input().split())
done=0
for i in range(n):
    num[a[i]-1]+=1
if x!=0:
    for i in range(n):
        comp=a[i]^x
        done+=num[comp-1]
    print done/2
else:
    for i in range(n):
        comp=a[i]
        done+=((num[comp-1]-1)*(num[comp-1]))/2
        num[comp-1]=0
    print done


#include <iostream>
using namespace std;
int m=100000;
int size=0;
int main() {
    // your code goes here
    int n,x;
    cin>>n;
    cin>>x;
    int a[m],pair[m];
    int done=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        int comp=a[i]^x;
        for (int j=0;j<size;j++){
            if (pair[j]==a[i]){
                done++;
            }}
        pair[size]=comp;
        size++;

    }
    cout<<done;
}


n,x=map(int,raw_input().split())
num=dict()
a=map(int,raw_input().split())
done=0
for i in range(n):
    if a[i] not in num:
        num[a[i]]=1
    else:
        num[a[i]]+=1
for i in range(n):
    comp=a[i]^x
    if x !=0 and comp in num:
        done+=num[comp]
    elif x==0:
        done+=(num[comp]-1)*(num[comp])
        num[comp]=0
print done/2


n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
pair=[]
done=0
d=[]
for i in range(n):
    comp=a[i]^x
    if a[i] in pair:
        done+=1
    pair.append(comp)
print done


n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
pair=[]
done=0
for i in range(n):
    comp=a[i]^x
    flag=False
    for j in pair:
        if j[0]==a[i]:
            flag=True
            j[2]+=1
        if j[1]==a[i]:
            done+=j[2]
    if not flag:
        pair.append([a[i],comp,1])
print done


import random
#n,x=[random.randint(1,15),random.randint(1,10)]
#a=[random.randint(0,10) for i in range(n)]

n,x=map(int,raw_input().split())
a = map(int,raw_input().split())
def brute():
	ct=0
	for i in range(n):
		for j in range(i+1,n):
			if a[i]^a[j] == x:
				ct+=1

	return  ct

def opt():
	ct = 0
	checkArr = [0 for i in range(10**5)]
	length = max(a)+1
	for i in range(n):
		if checkArr[a[i]]==1:
			#print "checky",a[i],a[i]^x
			ct+=1
		newNum = a[i] ^ x
		while length <= newNum:
			checkArr.append(0)
			length+=1
		checkArr[newNum] = 1

	return ct

def opt1():
	ct = 0
	maxyNum = 0
	for i in range(n):
		if a[i]^x > maxyNum:
			maxyNum = a[i]^x
	checkArr = [0 for i in range(maxyNum+1)]
	length = max(a)+1
	for i in range(n):
		if a[i] <= maxyNum and checkArr[a[i]]>=1:
			#print "checky",a[i],a[i]^x
			ct+=checkArr[a[i]]
		newNum = a[i] ^ x
		'''
		while length <= newNum:
			checkArr.append(0)
			length+=1
		'''
		checkArr[newNum] += 1

	return ct
'''
while True:
	if brute()!=opt1():
		print n,x
		print a
		print brute()
		print opt1()
		break
	else:
		print "correct"
'''
print opt1()


n,x=map(int,raw_input().split())
a=map(int,raw_input().split())

'''
ct=0
for i in range(n):
	for j in range(i+1,n):
		if a[i]^a[j] == x:
			ct+=1

print ct
'''
ct = 0
checkArr = [0 for i in range(max(a)+1)]
for i in range(n):
	if checkArr[a[i]]==1:
		#print "checky",a[i],a[i]^x
		ct+=1
	newNum = a[i] ^ x
	checkArr[newNum] = 1

print ct


import random
#n,x=[random.randint(1,15),random.randint(1,10)]
#a=[random.randint(0,10) for i in range(n)]

n,x=map(int,raw_input().split())
a = map(int,raw_input().split())
def brute():
	ct=0
	for i in range(n):
		for j in range(i+1,n):
			if a[i]^a[j] == x:
				ct+=1

	return  ct

def opt():
	ct = 0
	checkArr = [0 for i in range(10**5)]
	length = max(a)+1
	for i in range(n):
		if checkArr[a[i]]==1:
			#print "checky",a[i],a[i]^x
			ct+=1
		newNum = a[i] ^ x
		while length <= newNum:
			checkArr.append(0)
			length+=1
		checkArr[newNum] = 1

	return ct

def opt1():
	ct = 0
	maxyNum = 0
	for i in range(n):
		if a[i]^x > maxyNum:
			maxyNum = a[i]^x
	checkArr = [0 for i in range(maxyNum+1)]
	length = max(a)+1
	for i in range(n):
		if checkArr[a[i]]>=1:
			#print "checky",a[i],a[i]^x
			ct+=checkArr[a[i]]
		newNum = a[i] ^ x
		'''
		while length <= newNum:
			checkArr.append(0)
			length+=1
		'''
		checkArr[newNum] += 1

	return ct
'''
while True:
	if brute()!=opt1():
		print n,x
		print a
		print brute()
		print opt1()
		break
	else:
		print "correct"
'''
print opt1()


n,x = map(int, raw_input().split())
r = 0
a = []
b = []
for k in map(int, raw_input().split()):
	a.append(k)
	b.append(x^k)

for number in a:
	if number in b:
		r+=1

print r/2


n,x = map(int, raw_input().split())
r = 0
a = 200005*[0]

for k in map(int, raw_input().split()):
	r+=a[x^k]
	a[k]+=1
print r


N, X = (int (k) for k in raw_input().split(" "))
L = sorted(int (k) for k in raw_input().split(" "))
c=0
for i in L:
    a=X^i
    if a in L:
        c+=1
    elif i+X in L and (i+X)^i==X:
        c+=1

print c/2


N, X = (int (k) for k in raw_input().split(" "))
L = sorted(int (k) for k in raw_input().split(" "))
c=0
for i in L:
    a=X^i
    if a in L:
        c+=1
    elif a==X+i and a-i in L:
        c+=1
    elif i+X in L and (i+X)^i==X:
        c+=1

print c/2


N, X = (int (k) for k in raw_input().split(" "))
L = (int (k) for k in raw_input().split(" "))

d,R={},0

for e in L:
	aj = X^e

	if aj in d:
		R+=d[aj]

	if e in d: d[e]+=1
	else: d[e]=1
print R


from collections import defaultdict
n, x = map(int, raw_input().strip().split())
arr = map(int, raw_input().strip().split())
counts = defaultdict(int)
for a in arr:
	counts[a] += 1
total = 0
if x == 0:
	for a, c in counts.items():
		total += c * (c-1)/2
else:
	for a, c in counts.items():
		total += c * counts[x ^ a]
	total /= 2
print total


#coding=utf-8

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
for i in range(n-1):
	try:
		temp=a[i+1:].count(x^a[i])
		ans+=temp
	except:
		continue
print ans


#coding=utf-8

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
temp={}
for i in range(n):
	if a[i] in temp:
		ans+=temp[a[i]]
	if a[i]^x in temp:
		temp[a[i]^x]+=1
	else:
		temp[a[i]^x]=1
print ans


#coding=utf-8

n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=0
for i in range(n-1):
	try:
		a.index(x^a[i],i+1)
		ans+=1
	except:
		continue
print ans


n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
d={}
for i in a:
	if i not in d:
		d[i]=1
	else:
		d[i]+=1
ans=0
for i in a:
	aim=x^i
	if aim==i:
		ans+=d[aim]-1
	else:
		ans+=d.get(aim,0)

print ans>>1


import bisect
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())
B = [0]*(10**5+7)
for a in A:
    B[a] += 1
ans = 0
for a in xrange(1, 10**5+1):
    if a < a^x <= 10**5:
        ans += B[a]*B[a^x]
    elif a == a^x:
        ans += B[a]*(B[a]-1)/2
print ans


import bisect
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())

S = set(A)
ans = 0
for a in A:
    if a < a^x:
        continue
    if a^x in S:
        ans += 1
print ans


import bisect
n, x = map(int, raw_input().split())
A = map(int, raw_input().split())
B = [0]*(10**5+7)
for a in A:
    B[a] += 1
ans = 0
for a in xrange(1, 10**5+1):
    if a < a^x:
        ans += B[a]*B[a^x]
    elif a == a^x:
        ans += B[a]*(B[a]-1)/2
print ans


#!/usr/bin/python

import unittest

def find_num_pairs_with_xor_equals_x(n, x, arr):

    num_dict = {}
    num_pairs = 0

    # Iterate over the keys instead of array as array will have
    # duplicates
    for num in arr:
        # ai ^ aj = x ==> ai ^ x = aj.
        # Thus we check if xor of x with current number matches with
        val = num^x
        num_pairs += num_dict.get(val, 0)
        num_dict[num] = num_dict.get(num, 0) + 1

    return num_pairs

def find_num_pairs_with_xor_equals_x_timeout(n, x, arr):

    arr.sort()
    num_pairs = 0

    for index, num in enumerate(arr):
        val = num^x
        # Find if the value is in the array
        for ii, nn in enumerate(arr):
            # If current number is greater than val then we early out
            # there is no point iterating over remaining numbers
            if nn > val:
                break

            # if xor equals the current number then we have a pair
            # given it is not the same number
            if val == nn and index != ii:
                num_pairs += 1

    # Divide into half as we have to return the number of pairs
    #print num_pairs/2
    return num_pairs/2

class TestSamples(unittest.TestCase):

    def test_sample_1(self):
        x = 3
        arr = [1, 2]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 1)

    def test_sample_2(self):
        x = 1
        arr = [5, 1, 2, 3, 4, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 2)

    def test_sample_3(self):
        x = 0
        arr = [1, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 1)

    def test_sample_4(self):
        x = 0
        arr = [1, 1, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 3)

    def test_sample_5(self):
        x = 0
        arr = [1, 1, 1, 2]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 3)

    def test_sample_6(self):
        x = 0
        arr = [1, 2, 3, 4]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 0)

if __name__ == "__main__":
    n, x = map(int, raw_input().split(' '))
    arr = map(int, raw_input().split(' '))

    print find_num_pairs_with_xor_equals_x(n, x, arr)

    #unittest.main()


#!/usr/bin/python

import os

def find_num_pairs_with_xor_equals_x(n, x, arr):

    num_dict = {}
    # Set the count of numbers in dict
    for num in arr:
        count = num_dict.get(num)
        if count:
            num_dict[num] += 1
        else:
            num_dict[num] = 1

    num_pairs = 0
    for num in arr:
        val = num^x
        if num_dict.get(val):
            num_pairs += num_dict.get(val)

    return num_pairs

if __name__ == "__main__":
    n, x = map(int, raw_input().split(' '))
    arr = map(int, raw_input().split(' '))

    print find_num_pairs_with_xor_equals_x(n, x, arr)