#include<bits/stdc++.h>
using namespace std;

class Timer {
public:
    void start() {
        start_ = std::chrono::steady_clock::now();
    }
    int64_t elapsedMilliSec() {
        auto n = std::chrono::steady_clock::now();
        auto e = std::chrono::duration_cast<std::chrono::milliseconds>(n - start_);
        return e.count();
    }
private:
    std::chrono::steady_clock::time_point start_;
};

constexpr int64_t NUM = 26;
vector<int64_t> c(NUM);
vector<vector<int64_t>> s;

int64_t score(const vector<int64_t>& v) {
    vector<int64_t> last(NUM, -1);
    int64_t S = 0;
    for (int64_t i = 0; i < v.size(); i++) {
        //開催による満足度増加
        S += s[i][v[i]];

        //最終開催日更新
        last[v[i]] = i;

        //開催されないことによる満足度減少
        for (int64_t j = 0; j < NUM; j++) {
            S -= c[j] * (i - last[j]);
        }
    }

    return S;
}

int main() {
    Timer timer;
    timer.start();

    int64_t D;
    cin >> D;
    for (int64_t& C : c) {
        cin >> C;
    }

    s.resize(D, vector<int64_t>(NUM));
    for (int64_t i = 0; i < D; i++) {
        for (int64_t j = 0; j < NUM; j++) {
            cin >> s[i][j];
        }
    }

    vector<int64_t> t(D);
    for (int64_t i = 0; i < D; i++) {
        cin >> t[i];
        t[i]--;
    }

    int64_t M;
    cin >> M;
    for (int64_t i = 0; i < M; i++) {
        int64_t d, q;
        cin >> d >> q;
        d--; q--;

        t[d] = q;

        cout << score(t) << endl;
    }
}