Напомена: ово је незванична копија задатака. Као таква, не гарантује се да ће овај сајт бити одржаван, и немојте се изненадити ако са њега задаци одједном нестану.

Janko is preparing for the final match of the World Cup 2022. However, there is a large traffic jam in Doha, since all fans are going to the match. To make matters worse, Janko’s hotel is in a different part of the city from the stadium.

It is known that Doha looks like a matrix of dimensions \(N \times M\). With field \((i,j)\) we denote a field in the \(i\)-th row and \(j\)-th column. Janko’s hotel is on the field \((1,1)\), while the stadium is on the field \((N, M)\). On each field of the matrix (including \((1,1)\) and \((N, M)\)), there is a group of fans - on the field \((i,j)\) there are exactly \(a_{i,j}\) fans.

Janko can move from field \((i,j)\) either to field \((i+1,j)\) or \((i,j+1)\) (if the corresponding destination is within the matrix boundaries). Since Janko doesn’t like crowds, he decided to plan his path in such a way as to meet as few fans as possible (where the number of fans he meets is the sum of all \(a_{i,j}\) over the fields he visited on his path to the stadium).

As soon as he made his plan, on the news he heard that exactly one field will be blocked for the public, and therefore he won’t be able to go through that field on his path to the stadium. Unfortunately, Janko isn’t certain which field will be blocked and he asks you to answer \(Q\) different queries. In the \(i\)-th query, Janko wants to know how many fans will he need to meet if field \((x_i,y_i)\) is blocked.

Input format

The first line of standard input contains two integers, \(N\) and \(M\), representing the dimensions of Doha.

Line \(i\) of the following \(N\) lines contains \(M\) integers, \(j^{th}\) of them is \(a_{i,j}\) - number of fans on field \((i,j)\).

The following line contains one integer, \(Q\), representing the number of queries that Janko will ask.

The following \(Q\) lines contain two integers, \(x_i\) and \(y_i\), describing the field that will be blocked in the \(i^{th}\) query.

Output format

Your program should print \(Q\) lines to the standard output, each of them containing one integer. In line \(i\), you should print the minimal number of fans that Janko will have to meet on his path to the stadium, if the field \((x_i,y_i)\) gets blocked.

Example 1

Input

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

Output

39
36

Explanation

Constraints

Test cases are split into five disjoint groups: