#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <iterator>
#include <ctime>

using namespace std;

const int MAXN = 2e5 + 5;
int n, m, ti = 1;
set<pair<int, int> > w;
map<pair<int, int>, int> id;
pair<int, int> e[MAXN];
int color[MAXN], tim[MAXN], used[MAXN], ww[MAXN];

int dsu_get (int v) {
	if (tim[v] < ti) return color[v] = v;
	return (v == color[v]) ? v : (color[v] = dsu_get (color[v]));
}

void dsu_union(int v1, int v2)
{
	v1 = dsu_get(v1), v2 = dsu_get(v2);
	if (rand() & 1) swap(v1, v2);
	if (v1 != v2) color[v1] = v2, tim[v1] = ti;
}

int main()
{
	freopen("wheel.in", "r", stdin);
	freopen("wheel.out", "w", stdout);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int si = id.size();
		id[make_pair(0, i + 1)] = si;
		e[si] = make_pair(0, i + 1);
		int c;
		cin >> c;
		ww[si] = c;
		w.insert(make_pair(c, si));
	}
	for (int i = 0; i < n; i++)
	{
		int si = id.size();
		e[si] = make_pair(i + 1, (i + 1) % n + 1);
		if (e[si].first > e[si].second) swap(e[si].first, e[si].second);
		id[e[si]] = si;
		int c;
		cin >> c;
		ww[si] = c;
		w.insert(make_pair(c, si));
	}
	long long ans = 0;
	for (set<pair<int, int> >::const_iterator it = w.begin(); it != w.end(); it++)
	{
		long long c = (*it).first;
		int i = (*it).second;
		int a = e[i].first, b = e[i].second;
		if (dsu_get(a) != dsu_get(b))
		{
			ans += c, used[i] = ti;
			dsu_union(a, b);
		}
	}
	cout << ans << "\n";
	int m;
	cin >> m;
	for (int qq = 0; qq < m; qq++)
	{
		int a, b, c;
		cin >> a >> b >> c;
		if (a > b) swap(a, b);
		int i = id[make_pair(a, b)];
		w.erase(make_pair(ww[i], i));
		w.insert(make_pair(c, i));
		if (ww[i] >= c && used[i] == ti)
		{
			ans = ans - ww[i] + c;
			cout << ans << "\n";
			ww[i] = c;
			continue;
		}
		if (ww[i] <= c && used[i] != ti)
		{
			cout << ans << "\n";
			ww[i] = c;
			continue;
		}
		ti++;
		ans = 0;
		for (set<pair<int, int> >::const_iterator it = w.begin(); it != w.end(); it++)
		{
			long long c = (*it).first;
			int i = (*it).second;
			int a = e[i].first, b = e[i].second;
			if (dsu_get(a) != dsu_get(b))
			{
				ans += c, used[i] = ti;
				dsu_union(a, b);
			}
		}
		cout << ans << "\n";
		ww[i] = c;
	}
}
