#include <bits/stdc++.h>
using namespace std;

int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
long long n, m; cin >> n >> m;
long long a[n][m];
for ( int i = 0; i < n; i++ ){
    for ( int j = 0; j < m; j++ ){
        cin >> a[i][j];
    }
}
long long q; cin >> q;
long long s[q];
for ( int l = 0; l < q; l++ ){
    int x, y; cin >> x >> y;
    for ( int i = 0; i < n; i++ ){
        s[l] += a[i][0];
    }
    for ( int j = 0; j < m; j++ ){
        s[l] += a[n-1][j];
    }
    s[l] -= a[n-1][0];
}
for ( int i = 0; i < q; i++ ){
    cout << s[i] << endl;
}
return 0;
}