#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
using ll = long long int;

const int C_NUM = 26;
const int D_MAX = 366;
int D;
ll c[C_NUM+5];
ll s[D_MAX][C_NUM+5];

int t[D_MAX];
set<int> last[C_NUM+5];

const int M_MAX = 1E+05 + 5;
int d[M_MAX];
int q[M_MAX];

int main(){
    cin >> D;
    for(int i = 1; i <= C_NUM; i++)cin >> c[i];
    for(int i = 1; i <= D; i++){
        for(int j = 1; j <= C_NUM; j++){
            cin >> s[i][j];
        }
    }
    for(int i = 1; i <= D; i++){
        cin >> t[i];
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> d[i] >> q[i];
    }

    for(int j = 1; j <= C_NUM; j++)last[j].insert(0);
    ll v = 0;
    for(int i = 1; i <= D; i++){
        v += s[i][t[i]];
        last[t[i]].insert(i);
        for(int j = 1; j <= C_NUM; j++){
            v -= c[j] * (i - *last[j].rbegin());
        }
    }
    for(int j = 1; j <= C_NUM; j++)last[j].insert(D+1);
    for(int l = 0; l < m; l++){
        int day = d[l];
        int o = t[day];
        int n = q[l];
        v += s[day][n] - s[day][o];
        int bo = *(--last[o].find(day));
        int ao = *(++last[o].find(day));
        v -= c[o] * (day - bo) * (ao - day);
        last[o].erase(day);
        last[n].insert(day);
        int bn = *(--last[n].find(day));
        int an = *(++last[n].find(day));
        v += c[n] * (day - bn) * (an - day);
        t[day] = n;
        cout << v << endl;
    }
    return 0;
}