#define _USE_MATH_DEFINES

#include <iostream>
#include <algorithm> // min()
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <tuple>
#include <random>

#include <climits> // INT_MAX
#include <cmath> // ceil()
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define b2e(vec) vec.begin(), vec.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const int type_num = 26;
int D;
vector<ll> c(type_num);
vector<vector<ll>> s;
//vector<ll> satis_hist;

ll decrease_satis(vector<int>& last, ll d) {
	ll y = 0;
	rep(i, type_num) y += c[i] * (d + 1 - last[i]);
	return y;
}


ll calc_satis(vector<int>& t) {
	ll satis = 0;
	vector<int> last(type_num);
	rep(i, D) {
		last[t[i]] = i + 1;
		satis += s[i][t[i]] - decrease_satis(last, i);
		//satis_hist[i] = satis;
	}
	return satis;
}

int main() {
	cin >> D;

	rep(i, type_num) cin >> c[i];

	//vector<ll> t(D);
	rep(i, D) {
		vector<ll> temp(type_num);
		rep(j, type_num) {
			cin >> temp[j];
		}
		//auto iter = max_element(b2e(temp));
		//size_t index = distance(temp.begin(), iter);
		//t[i] = index;
		s.emplace_back(temp);
	}

	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}

	//auto satis = calc_satis(t);

	ll M;
	cin >> M;
	vector<pair<int, int>> dq(M);
	rep(i, M) {
		ll _d, _q;
		cin >> _d >> _q;
		dq[i] = make_pair(_d-1, _q-1);
	}

	rep(i, M) {
		t[dq[i].first] = dq[i].second;
		cout << calc_satis(t) << endl;
	}

}