#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int D;
  cin >> D;
  int c[26];
  int las[26];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    las[i] = 0;
  }
  int s[D][26];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  int choose[D];
  for (int i = 0; i < D; i++) cin >> choose[i];
  int ans = 0;
  for (int i = 1; i <= D; i++) {
    int score = 0;
    score += s[i-1][choose[i-1] - 1];
    for (int j = 0; j < 26; j++) {
      if (choose[i-1] - 1 != j) {
        score -= c[j] * (i - las[j]);
      }
    }
    las[choose[i-1] - 1] = i;
    ans += score;
  }

  int M;
  cin >> M;
  for (int i = 0; i < M; i++) {
    int d,q;
    cin >> d >> q;
    ans -= s[d-1][choose[d-1]-1];
    ans += s[d-1][q-1];
    int p = choose[d-1];
    int nextp = D+1;
    int prevp = 0;
    int nextq = D+1;
    int prevq = 0;
    for (int i = d; i < D; i++) {
      if (choose[i] == p) {
        nextp = i+1;
        break;
      }
    }
    for (int i = d; i < D; i++) {
      if (choose[i] == q) {
        nextq = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == p) {
        prevp = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == q) {
        prevq = i+1;
        break;
      }
    }
    ans -= (d - prevp) * (nextp - d) * (c[p-1]);
    ans += (d - prevq) * (nextq - d) * (c[q-1]);
    cout << ans << endl;
    choose[d-1] = q;
  }
  return 0;
}