#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int D;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));
int t[365];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	cin >> D;
	rep(i, 26) cin >> c[i];
	rep(i, D) {
		rep(j, 26) cin >> s[i][j];
	}
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	
	int Q;
	cin >> Q;
	int last[26];
	while(Q--) {
		int d, q;
		cin >> d >> q;
		d--; q--;
		t[d] = q;
		int score = 0;
		rep(i, 26) last[i] = -1;
		rep(i, D) {
			score += s[i][t[i]];
			last[t[i]] = i;
			rep(j, 26) {
				score -= c[j] * (i - last[j]);
			}
		}
		cout << score << endl;
	}
	return 0;
}