#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define ll long long

int main() {
    int d;
    cin >> d;
    vector<vector<int>> s(d+1, vector<int>(26+1, 0));
    vector<int> c(26+1);
    for(int i = 0; i < 26; i++) cin >> c[i];
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    /////////////////
    vector<int> t(d);
    for(int i = 0; i < d; i++) {
        t[i] = i+1;
    }
    for(int i = 0; i < d; i++) cin >> t[i];

    ///////////////
    int m;
    cin >> m;
    vector<pair<int, int>> dq(m);
    for(int i = 0; i < m; i++) {
        cin >> dq[i].first >> dq[i].second;
    }
    vector<ll> ans(d, 0);
    ll v = 0;
    ll tmp = 0;
    map<ll, int> mp;
    priority_queue<ll> que;
    int num = 0;
    for(int k = 0; k < m; k++) {
        tmp = t[dq[k].first-1];
        t[dq[k].first-1] = dq[k].second; 
        vector<ll> last(26+1, 0);
        for(int i = 0; i < d; i++) {
            v += s[i][t[i]-1];
            last[t[i]-1] = i+1;
            for(int j = 0; j < 26; j++) {
                v -= c[j]*((i+1)-last[j]);
            }    
        }
        cout << v << endl;
        que.push(v);
        mp[v] = k;
        v = 0;
    }
    return 0;
}