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

const int D = 365, N = 26;
int d, q;
ll c[N+1];
ll s[D+1][N+1];
ll last[N];
int contest[D+1];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> d;
	for(int i = 1; i <= N; i++)
		cin >> c[i];
	for(int i = 1; i <= d; i++) {
		for(int j = 1; j <= N; j++)
			cin >> s[i][j];
	}
	memset(last, 0, sizeof last);
	ll ans = 0;
	for(int i = 1; i <= d; i++) {
		int t; cin >> t;
		ans += s[i][t];
		last[t] = i;
		for(int j = 1; j <= N; j++)
			ans -= c[j] * (i - last[j]);
		contest[i] = t;
	}
	cin >> q;
	while(q--) {
		ll idx, x; cin >> idx >> x;
		ll l = idx-1, r = idx+1;
		ll len, len2;
		while(l > 0 && contest[l] != contest[idx]) l--;
		len = idx - l;
		while(r <= d && contest[r] != contest[idx]) r++;
		len2 = r - idx;
		ans -= s[idx][contest[idx]];
		ans -= c[contest[idx]] * len * len2;
		contest[idx] = x;

		l = idx-1, r = idx+1;
		while(l > 0 && contest[l] != contest[idx]) l--;
		len = idx - l;
		while(r <= d && contest[r] != contest[idx]) r++;
		len2 = r - idx;
		ans += s[idx][x];
		ans += c[x] * len * len2;
		cout << ans << '\n';
	}

	return 0;
}