K. Distinctness Queries

Time limit: 2s
Memory limit: 256MB
Input:
Output:

You are given a matrix with nn rows and mm columns. You will have to answer qq queries of the following type:

  • i1 j1 i2 j2 — in the submatrix whose top-left corner is (i1,j1)(i1,j1) and its bottom-right corner is (i2,j2)(i2,j2), are all of the elements distinct?

Input

The first line of input contains two integers nn and mm (1n,m,nm1051 \le n,m,n \cdot m \le 10^5) — the height, and width, of the matrix, respectively.

Each of the next nn lines of input contain mm integers ai,1,ai,2,,ai,ma_{i,1},a_{i,2},\ldots,a_{i,m} (1ai,jnm1 \le a_{i,j} \le n \cdot m) — the elements of the ii-th row of the given matrix.

The next line contains a single integer qq (1q1051 \le q \le 10^5) — the number of queries.

Each of the following qq lines contain 44 integers i1i_1, j1j_1, i2i_2, j2j_2 (1i1i2n1 \le i_1 \le i_2 \le n, 1j1j2m1 \le j_1 \le j_2 \le m) — the submatrix's corner cells' coordinates.

Output

For each query, print YES, if all of the elements of the given submatrix are distinct, or NO, otherwise.

Example 1

stdin

2 2
2 1
3 2
9
1 1 1 1
1 2 1 2
2 1 2 1
2 2 2 2
1 1 1 2
2 1 2 2
1 1 2 1
1 2 2 2
1 1 2 2

stdout

YES
YES
YES
YES
YES
YES
YES
YES
NO

Example 2

stdin

4 6
1 4 7 1 2 3
2 5 8 6 5 4
3 6 9 7 8 9
1 2 3 4 5 6
10
1 1 3 3
1 4 3 6
1 1 4 6
1 2 4 3
2 1 3 4
4 1 4 6
1 4 4 4
2 5 4 5
2 1 2 6
4 6 4 6

stdout

YES
YES
NO
YES
NO
YES
YES
NO
NO
YES

Log in or sign up to be able to send submissions!