#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e5 + 10;
int T, n;
int a[N], b[N];
struct seg_tree
{
	int maxs[N << 2], val[N];
	int chk(int x, int y){return val[x] > val[y] ? x : y;}
	void init(int o, int l, int r)
	{
		if(l == r) return maxs[o] = l, []{}();
		int mid = (l + r) >> 1;
		init(o << 1, l, mid);
		init(o << 1 | 1, mid + 1, r);
		maxs[o] = chk(maxs[o << 1], maxs[o << 1 | 1]);
	}
	int que(int o, int l, int r, int L, int R)
	{
		int re = 0;
		if(L <= l && r <= R) return maxs[o];
		int mid = (l + r) >> 1;
		if(mid >= L) re = chk(re, que(o << 1, l, mid, L, R));
		if(mid < R) re = chk(re, que(o << 1 | 1, mid + 1, r, L, R));
		return re;
	}
}A, B;
int ls[N], rs[N], fa[N], L[N], R[N];
typedef unsigned long long ull;
int build(int l, int r, int from)
{
	if(r < l) return 0;
	int o = A.que(1, 1, n, l, r);
	fa[o] = from;
	ls[o] = build(l, o - 1, o);
	rs[o] = build(o + 1, r, o);
	L[o] = l, R[o] = r;
	return o;
}
ull solve(int o, int i, int LL, int RR)
{
	if(o == 0) return 0;
	return (ull)a[o] * max(0, (min(i, o) - max(L[o], LL) + 1)) * max(0, (min(RR, R[o]) - max(i, o) + 1)) + solve(fa[o], i, LL, RR);
}
ull calc(int l, int r)
{
	if(r < l) return 0;
	int o = B.que(1, 1, n, l, r);
	int _L = 1, _R = n;
	ull re = b[o] * solve(o, o, l, r);
	re += calc(l, o - 1) + calc(o + 1, r);
	return re;
}
int main()
{
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> T >> n;
	for (int i = 1; i <= n; ++ i) cin >> a[i], A.val[i] = a[i];
	for (int i = 1; i <= n; ++ i) cin >> b[i], B.val[i] = b[i];
	A.init(1, 1, n); B.init(1, 1, n);
	int Q;
	cin >> Q;
	while(Q --)
	{
		int l, r;
		cin >> l >> r;
		for (int i = l; i <= r; ++ i) ls[i] = rs[i] = 0;
		int root = build(l, r, 0);
		cout << calc(l, r) << "\n";
	}
}