#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define int long long

using namespace std;

const int N = 3e5;

int T, n, a[N], b[N], Q, ans;

int qpow (int b, int p)
{
	int res = 1;
	while (p)
	{
		if (p & 1)
			res = res * b;
		b = b * b;
		p >>= 1;
	}
	return res;
}

inline void solve ()
{
	for (int i = 1; i <= n; ++ i)
		scanf ("%lld", &a[i]);
	for (int i = 1; i <= n; ++ i)
		scanf ("%lld", &b[i]);
	scanf ("%lld", &Q);
	while (Q --)
	{
		int l, r;
		scanf ("%lld %lld", &l, &r);
		for (int i = l; i <= r; ++ i)
			for (int j = l; j <= r; ++ j)
				for (int p = l; p <= r; ++ p)
					for (int q = l; q <= r; ++ q)
						ans = ans + a[p] * b[q];
	}
	printf ("%lld\n", ans);
	ans = 0;
	return ;
}

signed main ()
{
	freopen ("match.in", "r", stdin);
	freopen ("match.out", "w", stdout);

	scanf ("%lld %lld", &T, &n);
	while (T --)
	{
		solve ();
	}

	return 0;
}