#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int d;
    cin >> d;
    
    int c[26];
    for (int& e: c) cin >> e;

    int s[d][26];
    for (int i=0; i<d; i++) {
        for (int j=0; j<26; j++) {
            cin >> s[i][j];
        }
    }

    int t[d];
    for (int& e : t) cin >> e;

    int m;
    cin >> m;
    for (int k=0; k<m; k++) {
        int x, y;
        cin >> x >> y;
        t[x-1] = y;

        int last[26] = {};

        ll cur = 0;
        for (int i=0; i<d; i++) {
            cur += s[i][t[i]-1];
            last[t[i]-1] = i+1;

            for (int j=0; j<26; j++) {
                cur -= c[j] * (i-last[j]+1);
            }
        }
        cout << cur << "\n";
    }
}
