#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int n, m;
int c[26];
int s[400][26];
int t[400], ssc[400];
void input() {
    cin >> n;
    m = 26;
    for (int i = 0; i < m; i++) cin >> c[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> s[i][j];
        }
    }
}
void output() {
    for (int i = 0; i < n; i++) {
        cout << t[i] + 1 << newl;
    }
}
int score() {
    V<int> last(m, -1);
    int res = 0;
    memset(ssc, 0, sizeof(ssc));
    for (int i = 0; i < n; i++) {
        res += s[i][t[i]];
        last[t[i]] = i;
        ssc[t[i]] += s[i][t[i]];
        for (int j = 0; j < m; j++) {
            res -= c[j] * (i - last[j]);
            ssc[j] -= c[j] * (i - last[j]);
        }
    }
    return res;
}
int score_upd(int id) {
    int last = -1;
    int ns = 0;
    for (int i = 0; i < n; i++) {
        if (t[i] == id) {
            ns += s[i][id];
            last = i;
        }
        ns -= c[id] * (i - last);
    }
    return ns - ssc[id];
}
inline int cal(int x) {
    return x * (x + 1) / 2;
}
set<int> st[26];
int add(int id, int d) {
    st[id].insert(d);
    int res = s[d][id];
    auto it = st[id].lower_bound(d);
    int l = *prev(it), r = *next(it);
    res -= c[id] * (cal(d - l - 1) + cal(r - d - 1) - cal(r - l - 1));
    return res;
}
int del(int id, int d) {
    int res = -s[d][id];
    auto it = st[id].lower_bound(d);
    int l = *prev(it), r = *next(it);
    res += c[id] * (cal(d - l - 1) + cal(r - d - 1) - cal(r - l - 1));
    st[id].erase(it);
    return res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    input();
    for (int i = 0; i < m; i++) {
        st[i].insert(-1);
        st[i].insert(n);
    }
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        --t[i];
        st[t[i]].insert(i);
    }
    int Q;
    cin >> Q;
    int now = score();
    while (Q--) {
        int d, q;
        cin >> d >> q;
        --d;
        --q;
        int be = t[d];
        t[d] = q;
        now += add(q, d) + del(be, d);
        cout << now << newl;
    }
    /* int lim = 100000;
    random_device rd;
    mt19937 mt(rd());
    uniform_int_distribution<> rn(0, n - 1), rn1(0, n - 2), rc(0, m - 1);
    uniform_real_distribution<> r1(0, 1);
    int mid = *max_element(c, c + 26);
    for (int i = 0; i < n; i++) {
        t[i] = mid;
    }
    int now = score();
    double tmp = 30;
    for (int co = 0; co < lim; co++) {
        if (r1(mt) < 0.9) {
            int d = rn(mt), i = rc(mt);
            int be = t[d];
            t[d] = i;
            int sc = score();
            if (sc > now) {
                now = sc;
            } else {
                t[d] = be;
            }
        } else {
            int d = rn1(mt);
            int b1 = t[d], b2 = t[d + 1];
            swap(t[d], t[d + 1]);
            int sc = score();
            if (sc > now) {
                now = sc;
            } else {
                t[d] = b1, t[d + 1] = b2;
            }
        }
        // tmp -= 30.0 / double(lim);
    }
    output();
    cerr << now << newl;
    ifstream ifs("sc.txt");
    ll tt;
    ifs >> tt;
    ofstream ofs("sc.txt");
    ofs << tt + now << endl;*/
}
/*
0.8 19475382
0.5 19425431
0.2 17832584

*/


Measured memory_bytes: 3720