#include <bits/stdc++.h>
#define ull unsigned long long
using namespace std;
const int N = 3e5+5;
int T,n,a[N],b[N],ra[N],rb[N];
int 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]);

    stack<int> s;
    for (int i = 1; i <= n; ++i) {
        while (!s.empty() && a[i] > a[s.top()]) {
            ra[s.top()] = i;
            s.pop();
        }
        s.push(i);
    }
    while (!s.empty()) {
        ra[s.top()] = n+1;
        s.pop();
    }
    // for (int i = 1; i <= n; ++i) cout << ra[i] << " ";
    // cout << endl;
    for (int i = 1; i <= n; ++i) {
        while (!s.empty() && b[i] > b[s.top()]) {
            rb[s.top()] = i;
            s.pop();
        }
        s.push(i);
    }
    while (!s.empty()) {
        rb[s.top()] = n+1;
        s.pop();
    }


    int Q,l,r;
    scanf("%d",&Q);
    while (Q--) {
        scanf("%d%d",&l,&r);
        ull ans = 0;
        for (int i = l; i <= r; ++i) {
            int j = i;
            int ma = a[i], mb = b[i];
            while (j <= r) {
                int nxt = min(ra[j],rb[j]);
                ull cnt = 1;
                cnt = cnt * (min(r+1,nxt)-j) * ma * mb;
                ans += cnt;
                j = nxt;
                ma = max(ma,a[nxt]);
                mb = max(mb,b[nxt]);
            }
        }
        cout << ans << "\n";
    }
    
    return 0;
}