#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll d;
    cin >> d;
    vector<ll> contest_variety(26,0);
    vector<ll> c(26,0);
    rep(i,26){
        cin >> c[i];
    }
    vector<vector<ll>> calender(d,vector<ll> (26,0));
    rep(i,d){
        rep(j,26){
            cin >> calender[i][j];
        }
    }
    vector<ll> choose(d);
    rep(i,d) {
        cin >> choose[i];
        choose[i]--;
    }
    vector<ll> tmp_minus(26,0);
    ll m;
    cin >> m;
    rep(i,m) {
        ll a, q;
        cin >> a >> q;
        choose[a - 1] = q - 1;
        ll ans = 0;
        contest_variety.assign(26,0);
        rep(i, d) {
            ans += calender[i][choose[i]];
            contest_variety[choose[i]] = i + 1;
            rep(j, 26) {
                ans -= c[j] * (i + 1 - contest_variety[j]);
            }
        }
        cout << ans << endl;
    }
}