#include <bits/stdc++.h>

using namespace std;

#define Mod 18446744073709551616.0

int read(){
	int AK = 1, IOI = 0;
	char ch = 0;
	while (ch < '0' || ch > '9'){
		AK = ch =='-'?-1:1;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0'){
		IOI = (IOI << 3) + (IOI << 1);
		IOI += ch - 48;
		ch = getchar();
	}
	return AK * IOI;
}

const int Maxx = 250001;

int a[Maxx];
int b[Maxx];
double ansb[Maxx << 1];
double ansa[Maxx << 1];

int left_son(int x){
	return x << 1;
}
 int right_son(int x){
	return x << 1 ^ 1;
}

void build_tree_b(int x, int left, int right){
	if (left == right){
		ansb[x] = b[left];
		return ;
	}
	int middle = (left + right) >> 1;
	build_tree_b(left_son(x), left, middle);
	build_tree_b(right_son(x), middle + 1, right);
	ansb[x] = std::max(ansb[left_son(x)], ansb[right_son(x)]);
}

double query_data_b(int query_left, int query_right, int left, int right, int x){
	if (query_left <= left && query_right >= right){
		return ansb[x];
	}
	double res = -0x7f7f7f;
	int middle = (left + right) >> 1;
	if (middle >= query_left){
		res = std::max(res, query_data_b(query_left, query_right, left, middle, left_son(x)));
	}
	if (middle < query_right){
		res = std::max (res, query_data_b(query_left, query_right, middle + 1, right, right_son(x)));
	}
	return res;
}
void build_tree_a(int x, int left, int right){
	if (left == right){
		ansa[x] = a[left];
		return ;
	}
	int middle = (left + right) >> 1;
	build_tree_a(left_son(x), left, middle);
	build_tree_a(right_son(x), middle + 1, right);
	ansa[x] = std::max(ansa[left_son(x)], ansa[right_son(x)]);
}

 double query_data_a(int query_left, int query_right, int left, int right, int x){
//	printf("%d %d %d %d\n", query_left, query_right, left, right);
	if (query_left <= left && query_right >= right){
		return ansa[x];
	}
	double res = -0x7f7f7f;
	int middle = (left + right) >> 1;
	if (middle >= query_left){
		res = std::max(res, query_data_a(query_left, query_right, left, middle, left_son(x)));
	}
	if (middle < query_right){
		res = std::max (res, query_data_a(query_left, query_right, middle + 1, right, right_son(x)));
	}
	return res;
}

int main(){
//	printf("%lf\n", ksm(2, 64));
	freopen("match.in", "r", stdin);
	freopen("match.out", "w", stdout);
	int IDD = read(), n = read();
	for (int i = 1; i <= n; ++ i){
		a[i] = read();
	}
	for (int i = 1; i <= n; ++ i){
		b[i] = read();
	}
	build_tree_a(1, 1, n);
	build_tree_b(1, 1, n);
	int Q = read();
//	printf("YES");
	while (Q --){
		int left = read(), right = read();
		double answer = 0;
		for (int i = left; i <= right; ++ i){
//			printf("YES");
			for (int j = i; j <= right; ++ j){
				answer += query_data_a(i, j, 1, n, 1) * query_data_b(i, j, 1, n, 1);
				if (answer > Mod){
					answer -= Mod;
				}
//				printf("YES");
			}
		}
		long long ans = round(answer);
		printf("%lld\n", ans);
	}
}