#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int D; cin >> D;
	int T = 26;
	vector<int>c(T); rep(i, 0, T) { cin >> c[i]; }

	vector<vector<int>>s(D, vector<int>(T));
	rep(i, 0, D)rep(j, 0, T) { cin >> s[i][j]; }

	vector<int>t(D); rep(i, 0, D) { cin >> t[i]; t[i]--; }
	int score = 0;
	{
		vector<int>last(T);
		rep(i, 0, D) {
			score += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 0, T) {
				score -= c[j] * (i + 1 - last[j]);
			}
		}
	}
	int S = 0;
	rep(i, 0, D) {
		S += s[i][t[i]];
	}
	set<int>hoge;
	hoge.insert(D + 1);
	hoge.insert(0);
	vector<set<int>>schedule(T, hoge);
	rep(i, 0, D) {
		schedule[t[i]].insert(i + 1);
	}
	int C = 0;
	rep(i, 0, T) {
		int p = 0;
		int x = 0;
		for (auto d : schedule[i]) {
			int w = d - p - 1;
			x += (w + 1)*w / 2;
			p = d;
		}
		C += c[i] * x;
	}
	assert(S - C == score);
	auto f = [](int w) {return (w + 1)*w / 2; };
	int M; cin >> M;
	vector<int>d(M), q(M); rep(i, 0, M) { cin >> d[i] >> q[i]; d[i]--; q[i]--; }

	rep(i, 0, M) {
		S -= s[d[i]][t[d[i]]];
		S += s[d[i]][q[i]];


		t[d[i]]; // -> q[i]
		// schedule[t[d[i]]] has d[i]
		{
			auto itr = schedule[t[d[i]]].find(d[i] + 1);
			auto p = prev(itr);
			auto n = next(itr);
			int w1 = (*n) - (*itr) - 1;
			int w2 = (*itr) - (*p) - 1;
			int w3 = (*n) - (*p) - 1;
			C -= (f(w1) + f(w2))*c[t[d[i]]];
			C += f(w3)*c[t[d[i]]];
			schedule[t[d[i]]].erase(itr);
		}
		{
			t[d[i]] = q[i];
			schedule[q[i]].insert(d[i] + 1);
			auto itr = schedule[q[i]].find(d[i] + 1);
			auto p = prev(itr);
			auto n = next(itr);
			int w1 = (*n) - (*itr) - 1;
			int w2 = (*itr) - (*p) - 1;
			int w3 = (*n) - (*p) - 1;
			C -= f(w3)*c[q[i]];
			C += (f(w1) + f(w2))*c[q[i]];
		}
		cout << S - C << endl;
	}




	return 0;
}


Measured memory_bytes: 4620