#include <bits/stdc++.h>

using ull = unsigned long long;
using heap = std::priority_queue<int, std::vector<int>, std::greater<int> >;
const int N = 3005 + 5;
int n, T, Q;
int a[N], b[N];
ull ans[N][N];

signed main() {
  freopen("match.in", "r", stdin);
  freopen("match.out", "w", stdout);

  scanf("%d%d", &T, &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) scanf("%d", b + i);

  for (int p = 1; p <= n; p++) {
    ull ma = 0, mb = 0;
    for (int q = p; q <= n; q++) {
      ma = std::max(ma, (ull)a[q]);
      mb = std::max(mb, (ull)b[q]);
      ans[p][q] = ma * mb;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      ans[i][j] += ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1];

  scanf("%d", &Q);
  while (Q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%llu\n", ans[r][r] + ans[l - 1][l - 1] - ans[l - 1][r] - ans[r][l - 1]);
  }
  return 0;
}