11132 - Retrieving Matrix Element   

Description

A matrix of dimension (M,N) has M*N elements in the format of M rows(橫列) and N columns(直行), and thus each element has a pair of index (i, j), where i is less than M, j is less than N, and both are greater or equal to 0.  For example, a matrix A of dimension (2, 3) may look like this:

[  1 3 5  ]
[  2 4 6  ]

where the element A(0,1) is 3 and A(1, 0) is 2.

In this problem, a matrix and a few indexes is given.  What you have to do is to find out the corresponding elements from the matrix according to the given indexes.

Input

The input consists of four parts.

  1. The dimentsion of the matrix: two positive integers M and N in one line, and both are less than 10.
  2. The matrix itself: M lines and each line contains N integers that can be represented in an int type in C/C++ language.
  3. The number of index pairs: a positive integer P in one line, an it is less than 5.
  4. The indexes:  P lines and each line contains 2 integers, which represent the two-dimensional index of P elements respectively.

Output

The output be P lines, where P is the given number in the third part of the input.  Each line should be exactly one integer that is the corresponding element in the given matrix.

Sample Input  Download

Sample Output  Download

Tags

Lee Homework



Discuss