/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    long n,m,q,pr,b=0,a=0,z,maxia,maxib;
    cin>>n>>m;
    long navijaci[n][m];
    for (long i=0;i<n;i++){
        for(long j=0;j<m;j++){
            cin>>navijaci[i][j];
        }
    }
    cin>>q;
    long blokirano[q][2];
    for(long i=0;i<q;i++){
        cin>>blokirano[i][0]>>blokirano[i][1];
    }
    z=navijaci[0][0];
    for(long x=0;x<q;x++){
        pr=navijaci[blokirano[x][0]-1][blokirano[x][1]-1];
        navijaci[blokirano[x][0]-1][blokirano[x][1]-1]=1000000001;
        while(a<(n-1) || b<(m-1)){
            maxib=navijaci[a][b+1]+min(navijaci[a][b+2],navijaci[a+1][b+1]);
            maxia=navijaci[a+1][b]+min(navijaci[a+1][b+1],navijaci[a+2][b]);
            if(b+2 > m-1) maxib=navijaci[a+1][b+1]+navijaci[a][b+1];
            if(a+2 > n-1) maxia=navijaci[a+1][b+1]+navijaci[a+1][b];
            if(b+1 > m-1) maxib=2000000003;
            if(a+1 > n-1) maxia=2000000003;
            if(maxib < maxia && b<m-1){
                b++;
            }
            else if (a<n-1){
                a++;
            }
            z+=navijaci[a][b];
        }
        navijaci[blokirano[x][0]-1][blokirano[x][1]-1]=pr;
        cout<<z<<endl;
        z=navijaci[0][0];
        a=0;
        b=0;
    }
    

    return 0;
}