#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
std::ifstream fin("match.in");
std::ofstream fout("std.out");
int T, n, q;
void checkmax(unsigned long long &x, unsigned long long y) {
  if (x < y) x = y;
}
unsigned long long a[250001], b[250001];
namespace subtask1 {
unsigned long long f[3001][3001], s[3001][3001];
void Solve() {
  for (int i = 1; i <= n; i++) {
    unsigned long long mx1 = a[i], mx2 = b[i];
    for (int j = i; j <= n; j++) {
      checkmax(mx1, a[j]), checkmax(mx2, b[j]);
      f[i][j] = mx1 * mx2;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + f[i][j];
  std::cin >> q;
  while (q--) {
    int l, r;
    std::cin >> l >> r;
    std::cout << s[r][r] - s[l - 1][r] - s[r][l - 1] + s[l - 1][l - 1] << '\n';
  }
  std::exit(0);
}
}  // namespace subtask1
unsigned long long c[250001], d[250001];
unsigned long long CalcB(int l, int r, int mid) {
  c[mid] = 0, d[mid] = b[mid];
  for (int i = mid - 1; i >= l; i--) c[i] = std::max(c[i + 1], b[i]);
  for (int i = mid + 1; i <= r; i++) d[i] = std::max(d[i - 1], b[i]);
  unsigned long long ans = 0ULL;
  for (int i = mid, j = mid; i <= r; i++) {
    while (j >= l && d[i] > c[j]) j--;
    ans += (mid - j) * d[i];
  }
  for (int i = mid - 1, j = mid; i >= l; i--) {
    while (j <= r && c[i] > d[j]) j++;
    ans += (j - mid) * c[i];
  }
  return ans;
}
unsigned long long Solve(int l, int r) {
  if (l > r) return 0ULL;
  int mid = std::max_element(a + l, a + r + 1) - a;
  unsigned long long ans = Solve(l, mid - 1) + Solve(mid + 1, r);
  return ans + a[mid] * CalcB(l, r, mid);
}
int main(int argc, char const *argv[]) {
  // freopen("match.in", "r", stdin);
  std::cin.rdbuf(fin.rdbuf()), std::cout.rdbuf(fout.rdbuf());
  std::cin.tie(nullptr);
  std::cin >> T >> n;
  for (int i = 1; i <= n; i++) std::cin >> a[i];
  for (int i = 1; i <= n; i++) std::cin >> b[i];
  std::cin >> q;
  while (q--) {
    int l, r;
    std::cin >> l >> r;
    std::cout << Solve(l, r) << '\n';
  }
  return 0;
}