using System;

namespace Guzva
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nIm = Console.ReadLine().Split();
            int n = int.Parse(nIm[0]);
            int m = int.Parse(nIm[1]);
            int[,] matrica = new int[n, m];
            int a = 1;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    matrica[i, j] = a;
                    a = a + 1;
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Console.Write(matrica[i, j] + " ");
                }
                Console.WriteLine();
            }
            int Q = int.Parse(Console.ReadLine());
            int[] zbir = new int[Q];
            int brojac = 0;
            for (int k = 0; k < Q; k++)
            {
                string[] xIy = Console.ReadLine().Split();
                int x = int.Parse(xIy[0]);
                int y = int.Parse(xIy[1]);
                if (x > 1 && y < m)
                {
                    for (int j = 0; j < m; j++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[0, j];
                    }
                    for (int i = 1; i < n; i++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[i, m - 1];
                    }
                }
                else if (x == 1)
                {
                    if (x == 1 && y == 2)
                    {
                        zbir[brojac] = 1;
                        for (int j = 0; j < m; j++)
                        {
                            zbir[brojac] = zbir[brojac] + matrica[1, j];
                        }
                        for (int i = 2; i < n; i++)
                        {
                            zbir[brojac] = zbir[brojac] + matrica[i, m - 1];
                        }
                    }
                    else
                    {
                        for (int j = 0; j < y - 1; j++)
                        {
                            zbir[brojac] = zbir[brojac] + matrica[0, j];
                        }
                        for (int j = y - 2; j < m; j++)
                        {
                            zbir[brojac] = zbir[brojac] + matrica[1, j];
                        }
                        for (int i = 2; i < n; i++)
                        {
                            zbir[brojac] = zbir[brojac] + matrica[i, m - 1];
                        }
                    }
                }
                else if (y == m)
                {
                    for (int j = 0; j < y - 1; j++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[0, j];
                    }
                    for (int i = 1; i < x; i++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[i, y - 2];
                    }
                    for (int j = y - 2; j < m; j++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[x, j];
                    }
                    for (int i = x + 1; i < n; i++)
                    {
                        zbir[brojac] = zbir[brojac] + matrica[i, m - 1];
                    }
                }
                brojac++;
            }
            for (int i = 0; i < brojac; i++)
            {
                Console.WriteLine(zbir[i]);
            }
        }
    }
}