/*---------------------
  auther: nomonick
  contest: NOIP
  task name: match
  code time: 2022/11/26 12:02
  E(T4): 20
  rp++
---------------------*/
#include <bits/stdc++.h>
using namespace std;

#define int unsigned long long
const int SIZE = (int)1e6 + 50;
const int NUM = 51;
const int mod = (int)1e9 + 7;

inline int read()
{
	int x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' or ch > '9')
	{
		// if (ch == '-') f = -1;
		ch = getchar();
	}
	while ('0' <= ch and ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return f * x;
}

inline void write(int x)
{
	// if (x < 0) putchar('-'), x *= -1;
	if (x > 9) write(x / 10), putchar((x % 10) + '0');
	else putchar(x % 10 + '0');
}

int T,n,l,r,ans;
int num1[SIZE],num2[SIZE],rs1[SIZE],rs2[SIZE];

inline void solve()
{
	l = read(),r = read(); rs1[r] = rs2[r] = r + 1; ans = 0;
	for (int i = r - 1; i >= l; --i)
	{
		rs1[i] = i + 1;
		while (rs1[i] <= r and num1[rs1[i]] < num1[i]) rs1[i] = rs1[rs1[i]];
	}
	for (int i = r - 1; i >= l; --i) 
	{
		rs2[i] = i + 1;
		while (rs2[i] <= r and num2[rs2[i]] < num2[i]) rs2[i] = rs2[rs2[i]];
	}
	for (int i = l;i <= r; ++i)
	{
		int l1 = i,l2 = i;
		for (int j = i; j <= r;)
		{
			int x = min(rs1[l1],rs2[l2]); int len = (x - j);
			ans += (num1[l1] * num2[l2]) * len;//r
			l = x;  j = min(rs1[l1],rs2[l2]);
			if (rs1[l1] < rs2[l2]) l1 = rs1[l1];
			else if (rs1[l1] == rs2[l2]) l1 = rs1[l1], l2 = rs2[l2];
			else l2 = rs2[l2];
		}
	}
	write(ans); puts("");
}

signed main()
{
	freopen("match.in","r",stdin);
	freopen("match.out","w",stdout);
	T = read(); n = read();
	for (int i = 1; i <= n; ++i) num1[i] = read();
	for (int i = 1; i <= n; ++i) num2[i] = read();
	for (int Q = read(); Q; --Q) solve();
	return 0;
}

