#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

constexpr double ticks_per_sec = 2800000000;
constexpr double ticks_per_sec_inv = 1.0 / ticks_per_sec;
inline double rdtsc() { // in seconds
    uint32_t lo, hi;
    asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
    return (((uint64_t)hi << 32) | lo) * ticks_per_sec_inv;
}
constexpr double TLE = 3; // sec
constexpr double time_limit = TLE * 0.98;

unsigned int randxor()
{
    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)) );
}

template<typename hoge>
void my_shuffle(vector<hoge>& v) {
    int sz = v.size();
    for (int i = sz - 1; i >= 1; i--) {
        swap(v[i], v[randxor() % (i + 1)]);
    }
}

// 定数
constexpr int CONTEST_NUM = 26;

// 入力
constexpr int D = 365;
array<int, CONTEST_NUM> c;
array< array<int, CONTEST_NUM>, D> s;

ll calcScore(const array<int, D>& t) {
    ll score = 0;
    array<int, CONTEST_NUM> lasts{};
 
    for (int i = 0; i < D; i++) {
        lasts[t[i]] = i + 1;
        score += s[i][t[i]];
 
        for (int j = 0; j < CONTEST_NUM; j++) {
            score -= c[j] * (i + 1 - lasts[j]);
        }
    }
    return score;
}

void update(int target_day, int new_contest, array<int, D>& t, array< set<int>, CONTEST_NUM>& days) {
    int old_contest = t[target_day - 1];
    days[old_contest].erase(target_day);
    days[new_contest].insert(target_day);
    t[target_day - 1] = new_contest;
}

// return: diff score
ll calcDiff(int target_day, int new_contest, array<int, D>& t, array< set<int>, CONTEST_NUM>& days) {
    int old_contest = t[target_day - 1];

    ll diff = s[target_day - 1][new_contest] - s[target_day - 1][old_contest];
    {
        auto it = days[new_contest].upper_bound(target_day);
        int nex = *it;
        int prv = *prev(it);

        int d1 = target_day - prv - 1;
        int d2 = nex - target_day - 1;
        int d3 = nex - prv - 1;

        diff -= c[new_contest] * d1 * (d1 + 1) / 2;
        diff -= c[new_contest] * d2 * (d2 + 1) / 2;
        diff += c[new_contest] * d3 * (d3 + 1) / 2;
    }

    {
        auto it = days[old_contest].find(target_day);
        int nex = *next(it);
        int prv = *prev(it);

        int d1 = target_day - prv - 1;
        int d2 = nex - target_day - 1;
        int d3 = nex - prv - 1;

        diff += c[old_contest] * d1 * (d1 + 1) / 2;
        diff += c[old_contest] * d2 * (d2 + 1) / 2;
        diff -= c[old_contest] * d3 * (d3 + 1) / 2;
    }
    return diff;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    {
        int dummy;
        cin >> dummy;

        for (int i = 0; i < CONTEST_NUM; i++) {
            cin >> c[i];
        }

        for (int i = 0; i < D; i++) {
            for (int j = 0; j < CONTEST_NUM; j++) {
                cin >> s[i][j];
            }
        }
    }

    array< set<int>, CONTEST_NUM> days;
    for (int i = 0; i < CONTEST_NUM; i++) {
        days[i].insert(0);
        days[i].insert(D + 1);
    }

    array<int, D> t;
    for (int i = 0; i < D; i++) {
        cin >> t[i];
        --t[i];
        days[t[i]].insert(i + 1);
    }

    ll current_score = calcScore(t);

    int m;
    cin >> m;

    for (int i = 0; i < m; i++) {
        int d, q;
        cin >> d >> q;
        --q;
        
        current_score += calcDiff(d, q, t, days);
        update(d, q, t, days);
        cout << current_score << newl;
    }

    return 0;
}


Measured memory_bytes: 3712