题目描述
Read problems statements in Mandarin Chinese and Russian.
This time Chef does not want to bother you with long story, so the problem description will be as short as possible. You are given a square matrix A, which has N rows and N columns. Chef wants you to answer following queries: given a rectangular submatrix with upper-left corner in (X_{1}, Y_{1}) and lower-right corner in (X_{2}, Y_{2}), and you are to count number of disctinct elements in this submarix, i.e count number of such distinct A_{i, j} that (X_{1} ≤ i ≤ X_{2}) and (Y_{1} ≤ j ≤ Y_{2}). [You may assume that i is looping through the rows and j through columns]
------ Input ------
The first line of the input file will contain single integer N. Then N lines with N numbers in each follow - description of the matrix. The rows are indexed from top to bottom that is top row has index 1, and columns are indexed from left to right that is left column has index 1. There is a single integer Q that follows on the next line right after the matrix description - number of Chef's queries. Then Q queries follow. Each query is described by four integers - X_{1}, Y_{1}, X_{2}, and Y_{2}.
------ Output ------
Output Q integers, each in a separate line - answers for the queries.
------ Constraints ------
$1≤N≤300$
$1≤Q≤10^{5}$
$1≤A_{i, j}≤10$
$1≤X_{1}≤X_{2}≤N$
$1≤Y_{1}≤Y_{2}≤N$
----- Sample Input 1 ------
3
1 2 3
3 2 1
5 6 3
3
1 1 2 3
2 2 2 2
1 1 3 3
----- Sample Output 1 ------
3
1
5
输入格式
见题面
输出格式
见题面