#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#define sfor(i, h, t) for(int i = (h); i <= (t); ++i)
#define dfor(i, t, h) for(int i = (t); i >= (h); --i)
#define il inline
#define ms(x, i) memset(x, i, sizeof x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef long double ldb;
const int MAXN = 250008;
int id, N, Q;
int a[MAXN], b[MAXN], posa[MAXN], posb[MAXN];
map<pii, ull> re;
// ull siz;
il ull solve(int l, int r, int maxa, int maxb) {
    if(l > r)
        return 0;
    // cerr << l << ' ' << r << ' ' << maxa << ' ' << maxb << '\n';
    if(l == r)
        return a[l] * b[l];
    if(re[pii(l, r)])
        return re[pii(l, r)];
    // ++siz;
    for(; maxa && (l > posa[maxa] || posa[maxa] > r); --maxa);
    for(; maxb && (l > posb[maxb] || posb[maxb] > r); --maxb);
    int posmaxa = posa[maxa], posmaxb = posb[maxb];
    ull res = 0;
    if(posmaxa <= posmaxb) {
        res += 1ull * (posmaxa - l + 1) * (r - posmaxb + 1) * maxa * maxb;
        res += solve(l, posmaxb - 1, maxa, maxb - 1);
        res -= solve(posmaxa + 1, posmaxb - 1, maxa - 1, maxb - 1);
        res += solve(posmaxa + 1, r, maxa - 1, maxb);
    }
    if(posmaxa > posmaxb) {
        res += 1ull * (posmaxb - l + 1) * (r - posmaxa + 1) * maxa * maxb;
        res += solve(l, posmaxa - 1, maxa - 1, maxb);
        res -= solve(posmaxb + 1, posmaxa - 1, maxa - 1, maxb - 1);
        res += solve(posmaxb + 1, r, maxa, maxb - 1);
    }
    return re[pii(l, r)] = res;
}
signed main(void) {
    freopen("match.in", "r", stdin);
    freopen("match.out", "w", stdout);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> id >> N;
    sfor(i, 1, N) {
        cin >> a[i];
        posa[a[i]] = i;
    }
    sfor(i, 1, N) {
        cin >> b[i];
        posb[b[i]] = i;
    }
    ull res = 0;
    cin >> Q;
    int l, r;
    while(Q--) {
        cin >> l >> r;
        res = solve(l, r, N, N);
        cout << res << '\n';
        // cerr << siz;
    }
    return !bool(cout << '\n');
}