#include<bits/stdc++.h>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int d;
  int res = 0;
  cin >> d;
  vector<int> c(26);
  rep(i,26)cin >> c[i];
  vector<vector<int>> v(d,vector<int>(26));
  vector<int> contest(d);
  vector<int> last(26,0);
  vector<int> satisfy(26,0);
  rep(i,d)rep(j,26){
    int x;cin >> x;
    v[i][j] = x;
  }
  for(int i = 1;i <= d;i++){
    cin >> contest[i-1];
    contest[i-1]--;
    last[contest[i-1]] = i;
    res += v[i-1][contest[i-1]];
    rep(j,26)res -= c[j]*(i-last[j]),satisfy[j] += c[j]*(i-last[j]);
  }
  int Q;cin >> Q;
  while(Q--){
    int day,pos;cin >> day >> pos;
    day--,pos--;
    int pre = contest[day];
    res += satisfy[pos];
    res += satisfy[pre];
    res -= v[day][pre];
    res += v[day][pos];
    satisfy[pos] = satisfy[pre] = 0;
    last[pos] = last[pre] = 0;
    contest[day] = pos;
    for(int i = 1;i <= d;i++)last[pos] = (contest[i-1] == pos ? last[pos] = i : last[pos]),satisfy[pos] += c[pos]*(i-last[pos]);
    for(int i = 1;i <= d;i++)last[pre] = (contest[i-1] == pre ? last[pre] = i : last[pre]),satisfy[pre] += c[pre]*(i-last[pre]);
    res -= (satisfy[pos]+satisfy[pre]);
    cout << res << endl;
  }

  
  


  return 0;
}
