//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////
unsigned int rnd(){
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
#include <chrono>
//auto end=chrono::system_clock::now();
//double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000000.0);//多分これで秒
//cerr<<"loop: "<<loopcount<<endl;

#define N 30
#define D 400
vector<ll> c(N);
vector<vector<ll>>s(D);
ll d;
ll n=26;

vector<ll>ANS(D);
ll SCORE;
set<ll>DAYS[N];

void calhappy(){
    ll res=0;
    ll last[N];memset(last,0,sizeof(last));
    rep(i,1,d){
        res+=s[i][ANS[i]];
        last[ANS[i]]=i;
        rep(j,1,n){
            res-=c[j]*(i-last[j]);
        }
    }
    SCORE=res;
}
ll Sum(ll z){
    return z*(z+1)/2;
}
ll calval(ll d1,ll d2,ll d3,ll preq){
    ll res=0;
    res+=Sum(d3-d1-1)-Sum(d2-d1-1)-Sum(d3-d2-1);
    return c[preq]*res;
}
void change(ll day,ll newq){
    
    ll preq=ANS[day];
    SCORE+=(s[day][newq]-s[day][preq]);
    auto itr=DAYS[preq].find(day);
    itr--;
    ll d1=*itr;
    itr++;itr++;
    ll d3=*itr;
    SCORE-=calval(d1,day,d3,preq);
    
    DAYS[preq].erase(day);
    DAYS[newq].insert(day);
    itr=DAYS[newq].find(day);
    itr--;
    d1=*itr;
    itr++;itr++;
    d3=*itr;
    SCORE+=calval(d1,day,d3,newq);
    ANS[day]=newq;
}


int main(){fastio
    auto start=chrono::system_clock::now();ll loopcount=0;
    
    
    cin>>d;
    rep(i,1,n)cin>>c[i];
    rep(i,1,d){
        s[i].resize(n+1);
        rep(j,1,n)cin>>s[i][j];
    }
    
    rep(i,1,d)cin>>ANS[i];
    calhappy();
    rep(i,1,n){
        DAYS[i].insert(0);
        DAYS[i].insert(d+1);
    }
    rep(i,1,d){
        DAYS[ANS[i]].insert(i);
    }
    
    
    ll m;cin>>m;
    while(m--){
        ll Day,Que;cin>>Day>>Que;
        change(Day,Que);
        cout<<SCORE<<endl;
    }
    
    
    
    
    
    /*
    while(1){
        auto end=chrono::system_clock::now();
        double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()/ 1000000.0);
        if(time>0.3)break;
        
        
        loopcount++;
    }
    cerr<<loopcount<<endl;
    */
    
    return 0;
}







Measured memory_bytes: 3736