This problem is a Mooshak version of a UVA Online Judge Problem.


[PC019] Census

This year, there have been many problems with population calculations, since in some cities, there are many emigrants, or the population growth is very high. Every year the ACM (for Association for Counting Members) conducts a census in each region. The country is divided into \(n^2\) regions, consisting of an \(n \times n\) grid of regions. Your task is to find the least, and the greatest population in some set of regions. Since in a single year there is no significant change in the populations, the ACM modifies the population counts by some number of inhabitants.

Input

In the first line you will find the integer \(n.\). The following \(n\) lines will each contain the \(n\) integers, representing the initial population of city \(c[y,x]\). In the following line is the number \(q\), followed by \(q\) lines with queries, each one being of one of the following two types::

Output

For each query \(q \, y_1 \, x_1 \, y_2 \, x_2\) print in a single line the greatest and least amount of current population in that region, separated by a single space.

Constraints

Example Input Example Output
5
1 2 3 4 5
0 9 2 1 3
0 2 3 4 1
0 1 2 4 5
8 5 3 1 4
4
q 1 1 2 3
c 2 3 10
q 1 1 5 5
q 1 2 2 2
9 0
10 0
9 2

Competitive Programming (CC3032) 2025/2026
DCC/FCUP - University of Porto