# include <bits/stdc++.h>
# define int long long
# define wheneveright bool mem2; signed main
using namespace std;

bool mem1;

const int maxn = 250005;

struct reader {
	template <typename Type>
	reader & operator >> (Type & ret) {
		int f = 1; ret = 0; char ch = getchar ();
		for (;!isdigit (ch); ch = getchar ()) if (ch == '-') f = -f;
		for (; isdigit (ch); ch = getchar ()) ret = ret * 10 + ch - '0';
		ret *= f; return * this;
	}
} fin;

int T, n, m; // 部分分的给法太良心了，感动
unsigned int a[maxn];
unsigned int b[maxn];
unsigned int res;

namespace Subtask1 {
	int solve () {
		fin >> m;
		int l, r;
		unsigned int ma, mb;
		while (m--) {
			fin >> l >> r; res = 0;
			for (int i = l; i <= r; i++) {
				ma = a[i]; mb = b[i];
				for (int j = i; j <= r; j++) {
					ma = max (ma, a[j]);
					mb = max (mb, b[j]);
					res += ma * mb;
				}
			}
			printf ("%llu\n", res);
		}
		return 0;
	}
} ;
namespace Subtask2 {
	int bel[maxn];
	unsigned int ans[maxn];
	struct WER {
		int pos, l, r;
		bool operator < (WER p) const {
			if (bel[l] != bel[p.l]) return bel[l] < bel[p.l];
			return (bel[l] & 1) ? r < p.r : r > p.r;
		}
	} q[maxn];
	unsigned int CALC (int l, int r, int x) {
		unsigned int ret = 0, ma = a[x], mb = b[x];
		if (x > r) {
			for (int i = x; i >= l; i--) {
				ma = max (ma, a[i]); mb = max (mb, b[i]);
				ret += ma * mb;
			}
		}
		else for (int i = x; i <= r; i++) {
				ma = max (ma, a[i]); mb = max (mb, b[i]);
				ret += ma * mb;
		}
		return ret;
	}
	int solve () {
		for (int i = 1; i <= n; i++) bel[i] = (i - 1) / 500 + 1;
		fin >> m; res = 0;
		for (int i = 1; i <= m; i++) fin >> q[i].l >> q[i].r, q[i].pos = i;
		sort (q + 1, q + 1 + m);
		for (int i = 1, l = q[1].l, r = q[1].l - 1; i <= m; i++) {
			while (r < q[i].r) res += CALC (l, r, ++r);
			while (l > q[i].l) res += CALC (l, r, --l);
			while (r > q[i].r) res -= CALC (l, r - 1, r--);
			while (l < q[i].l) res -= CALC (l + 1, r, l++);
			ans[q[i].pos] = res;
		}
		for (int i = 1; i <= m; i++) printf ("%llu\n", ans[i]);
		return 0;
	}
}

wheneveright () {
	cerr << "Memory Cost : " << abs (& mem1 - & mem2) / 1024. / 1024. << " MB\n";
	freopen ("match.in", "r", stdin);
	freopen ("match.out", "w", stdout);
	fin >> T >> n;
	for (int i = 1; i <= n; i++) fin >> a[i];
	for (int i = 1; i <= n; i++) fin >> b[i];
	/*if (T <= 2 || T >= 14)*/ return Subtask1 :: solve ();
	return 0;
}