#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#define up(i, a, b) for (int i = a; i <= b; i++)
#define dn(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int read() {
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return x * f;
}
const int N = 3e5 + 5;
int n, q, a[N], b[N];
int lg[N], st1[N][20], st2[N][20];
struct Baoli{
	int query1(int l, int r) {int k = lg[r - l + 1];return max(st1[l][k], st1[r - (1 << k) + 1][k]);}
	int query2(int l, int r) {int k = lg[r - l + 1];return max(st2[l][k], st2[r - (1 << k) + 1][k]);}
	void solve() {
		lg[0] = -1;
		up(i, 1, n) lg[i] = lg[i >> 1] + 1;
		up(i, 1, n) st1[i][0] = a[i], st2[i][0] = b[i];
		up(j, 1, lg[n]) up(i, 1, n - (1 << (j - 1))) st1[i][j] = max(st1[i][j - 1], st1[i + (1 << (j - 1))][j - 1]), st2[i][j] = max(st2[i][j - 1], st2[i + (1 << (j - 1))][j - 1]);
//		while (1) {int l = read(), r = read(); printf("%d\n", query1(l, r));}
//		puts("asfsfa");
		int q = read();
		while (q--) {
			int l = read(), r = read();
			ull ans = 0;
			up(i, l, r) up(j, i, r) ans += (ull)query1(i, j) * query2(i, j);
			printf("%llu\n", ans);
		}
	}
}P1;
struct B2{
	int Max1(int x, int y) {return (a[x] > a[y] ? x : y);}
	int Max2(int x, int y) {return (b[x] > b[y] ? x : y);}
	void solve() {
		lg[0] = -1;
		up(i, 1, n) lg[i] = lg[i >> 1] + 1;
		up(i, 1, n) st1[i][0] = i, st2[i][0] = i;
		up(j, 1, lg[n]) up(i, 1, n - (1 << (j - 1))) st1[i][j] = Max1(st1[i][j - 1], st1[i + (1 << (j - 1))][j - 1]), st2[i][j] = Max2(st2[i][j - 1], st2[i + (1 << (j - 1))][j - 1]);
		
	}
}P2;
int main() {
//	freopen("match1.in", "r", stdin);
//	freopen("match2.in", "r", stdin);
//	freopen("match3.in", "r", stdin);
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	int id = read();
	n = read();
	up(i, 1, n) a[i] = read();
	up(i, 1, n) b[i] = read();
	P1.solve();
	return 0;
}





















