#include <bits/stdc++.h>
#define lc x<<1
#define rc x<<1|1
#define ll long long
#define ull unsigned long long
using namespace std;
inline ull Max(ull x, ull y){return x > y ? x : y;}
inline ull rd(){
    ull x = 0;char c = getchar();
    while(c < '0' || c > '9')
        c = getchar();
    while(c <= '9' && c >= '0'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x;
}
const int N = 3e5;

int T, n;
ull a[2][N];

struct Q{
    int id;
    int l, r;
}query[N];

struct Seg_tree{
    private:

    struct Node{
        int l, r;
        ull maxx;
    }t[N<<2];
    void push_up(int x){
        t[x].maxx = Max(t[lc].maxx, t[rc].maxx);
        return ;
    }

    public:

    void build(int x, int l, int r, int op){
        t[x].l = l;
        t[x].r = r;
        if(l == r){
            t[x].maxx = a[op][l];
            return ;
        }
        int mid = l + r >> 1;
        build(lc, l, mid, op);
        build(rc, mid + 1, r, op);
        push_up(x);
        return ;
    }

    ull query(int x, int l, int r){
        if(t[x].l >= l && t[x].r <= r)return t[x].maxx;
        ull res = 0;
        if(t[lc].r >= l)res = Max(res, query(lc, l, r));
        if(t[rc].l <= r)res = Max(res, query(rc, l, r));
        return res;
    }

}T1, T2;

int main(){
    // freopen("E:/test/test.in", "r", stdin);
    // freopen("E:/test/test.out", "w", stdout);

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

    T = rd(), n = rd();
    for(int i = 1; i <= n; ++i)
        a[0][i] = rd();
    for(int i = 1; i <= n; ++i)
        a[1][i] = rd();
    
    T1.build(1, 1, n, 0);
    T2.build(1, 1, n, 1);

    int q = rd();
    for(int i = 1; i <= q; ++i){
        query[i].l = rd();
        query[i].r = rd();
        query[i].id = i;
    }

    for(int i = 1; i <= q; ++i){
        int l = query[i].l, r = query[i].r;
        ull res = 0;
        for(int j = l; j <= r; ++j){
            for(int k = j; k <= r; ++k){
                res += T1.query(1, j, k) * T2.query(1, j, k);
            }
        }
        printf("%llu\n", res);
    }

    return 0;
}