#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
const ll N = 2e5 + 5;
const ll M = 1e9 + 7;
ll fen[N], fen1[N], tot;
void update(ll u, ll val)
{
while (u <= tot) fen[u] += val, u += u & -u;
}
ll sum(ll u)
{
ll res = 0;
while (u)
{
res += fen[u];
u -= u & -u;
}
return res;
}
void update1(ll u, ll val)
{
while (u <= tot) fen1[u] = (fen1[u] + val) % M, u += u & -u;
}
ll sum1(ll u)
{
ll res = 0;
while (u)
{
res += fen1[u];
res %= M;
u -= u & -u;
}
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast
vector<ll> variety;
ll n;
cin >> n;
ll a[n], b[n];
for (auto &x : a) cin >> x;
for (auto &x : b) cin >> x;
for (auto x : a)
variety.push_back(x);
ll k, cnt = 0;
for (auto x : b) cnt += x;
cin >> k;
ll kuery[k][3];
for (ll i = 0; i < k; i ++)
cin >> kuery[i][0] >> kuery[i][1] >> kuery[i][2],
variety.push_back(kuery[i][1]);
sort(variety.begin(), variety.end());
variety.erase(unique(variety.begin(), variety.end()), variety.end());
tot = variety.size();
map<ll, ll> direct;
for (ll i = 0; i < tot; i ++)direct[variety[i]] = i + 1;
for (ll i = 0; i < n; i ++)
update(direct[a[i]], b[i]), update1(direct[a[i]], a[i] * b[i] % M);
for (ll i = 0; i < k; i ++)
{
ll idx = kuery[i][0], x = kuery[i][1], y = kuery[i][2];
-- idx;
update(direct[a[idx]], - b[idx]);
update1(direct[a[idx]], - (a[idx] * b[idx] % M));
cnt -= b[idx];
a[idx] = x;
b[idx] = y;
cnt += b[idx];
update(direct[a[idx]], b[idx]);
update1(direct[a[idx]], a[idx] * b[idx] % M);
ll l = 1, r = tot, res = 1;
while (l <= r)
{
ll mid = (l + r) / 2;
ll tot = sum(mid);
if (tot >= cnt - tot) res = mid, r = mid - 1;
else l = mid + 1;
}
l = sum(res);
r = cnt - sum(res);
ll ans = l % M * variety[res - 1] % M - sum1(res);
ans += sum1(tot) - sum1(res) - r % M * variety[res - 1] % M;
cout << (ans % M + M) % M << endl;
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZmFzdCBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgZW5kbCAnXG4nCiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CnVzaW5nIG5hbWVzcGFjZSBfX2dudV9wYmRzOwoKI2RlZmluZSBvcmRlcmVkX3NldCB0cmVlPGxsLCBudWxsX3R5cGUsbGVzczxsbD4sIHJiX3RyZWVfdGFnLHRyZWVfb3JkZXJfc3RhdGlzdGljc19ub2RlX3VwZGF0ZT4KY29uc3QgbGwgTiA9IDJlNSArIDU7CmNvbnN0IGxsIE0gPSAxZTkgKyA3OwoKbGwgZmVuW05dLCBmZW4xW05dLCB0b3Q7CnZvaWQgdXBkYXRlKGxsIHUsIGxsIHZhbCkKewogICAgd2hpbGUgKHUgPD0gdG90KSBmZW5bdV0gKz0gdmFsLCB1ICs9IHUgJiAtdTsKfQoKbGwgc3VtKGxsIHUpCnsKICAgIGxsIHJlcyA9IDA7CiAgICB3aGlsZSAodSkKICAgIHsKICAgICAgICByZXMgKz0gZmVuW3VdOwogICAgICAgIHUgLT0gdSAmIC11OwogICAgfQogICAgcmV0dXJuIHJlczsKfQoKdm9pZCB1cGRhdGUxKGxs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R5LmVuZCgpKSwgdmFyaWV0eS5lbmQoKSk7CiAgICB0b3QgPSB2YXJpZXR5LnNpemUoKTsKICAgIG1hcDxsbCwgbGw+IGRpcmVjdDsKICAgIGZvciAobGwgaSA9IDA7IGkgPCB0b3Q7IGkgKyspZGlyZWN0W3ZhcmlldHlbaV1dID0gaSArIDE7CgogICAgZm9yIChsbCBpID0gMDsgaSA8IG47IGkgKyspCiAgICAgICAgdXBkYXRlKGRpcmVjdFthW2ldXSwgYltpXSksIHVwZGF0ZTEoZGlyZWN0W2FbaV1dLCBhW2ldICogYltpXSAlIE0pOwoKICAgIGZvciAobGwgaSA9IDA7IGkgPCBrOyBpICsrKQogICAgewogICAgICAgIGxsIGlkeCA9IGt1ZXJ5W2ldWzBdLCB4ID0ga3VlcnlbaV1bMV0sIHkgPSBrdWVyeVtpXVsyXTsKICAgICAgICAtLSBpZHg7CiAgICAgICAgdXBkYXRlKGRpcmVjdFthW2lkeF1dLCAtIGJbaWR4XSk7CiAgICAgICAgdXBkYXRlMShkaXJlY3RbYVtpZHhdXSwgLSAoYVtpZHhdICogYltpZHhdICUgTSkpOwogICAgICAgIGNudCAtPSBiW2lkeF07CiAgICAgICAgYVtpZHhdID0geDsKICAgICAgICBiW2lkeF0gPSB5OwogICAgICAgIGNudCArPSBiW2lkeF07CiAgICAgICAgdXBkYXRlKGRpcmVjdFthW2lkeF1dLCBiW2lkeF0pOwogICAgICAgIHVwZGF0ZTEoZGlyZWN0W2FbaWR4XV0sIGFbaWR4XSAqIGJbaWR4XSAlIE0pOwoKICAgICAgICBsbCBsID0gMSwgciA9IHRvdCwgcmVzID0gMTsKICAgICAgICB3aGlsZSAobCA8PSByKQogICAgICAgIHsKICAgICAgICAgICAgbGwgbWlkID0gKGwgKyByKSAvIDI7CiAgICAgICAgICAgIGxsIHRvdCA9IHN1bShtaWQpOwogICAgICAgICAgICBpZiAodG90ID49IGNudCAtIHRvdCkgcmVzID0gbWlkLCByID0gbWlkIC0gMTsKICAgICAgICAgICAgZWxzZSBsID0gbWlkICsgMTsKICAgICAgICB9CgogICAgICAgIGwgPSBzdW0ocmVzKTsKICAgICAgICByID0gY250IC0gc3VtKHJlcyk7CgogICAgICAgIGxsIGFucyA9IGwgJSBNICogdmFyaWV0eVtyZXMgLSAxXSAlIE0gLSBzdW0xKHJlcyk7CiAgICAgICAgYW5zICs9IHN1bTEodG90KSAtIHN1bTEocmVzKSAtIHIgJSBNICogdmFyaWV0eVtyZXMgLSAxXSAlIE07CiAgICAgICAgY291dCA8PCAoYW5zICUgTSArIE0pICUgTSA8PCBlbmRsOwogICAgfQoKfQ==