#include <bits/stdc++.h>
using namespace std;
int main(){
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
    int t,n;
    cin >> t >> n;
    int a[n+2],b[n+2];
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        cin >> b[i];
    }
    int q;
    cin >> q;
    //BAOLI
    while(q--){
        long long cnt=0;
        int l,r;
        cin >> l >> r;
        for(int i=l;i<=r;i++){
            for(int j=r;j>=i;j--){
                int maxa=-1,maxb=-1;
                for(int k=i;k<=j;k++){
                    maxa=max(maxa,a[k]);
                    maxb=max(maxb,b[k]);
                }
                cnt+=maxa*maxb;
//                cout << maxa << " " << maxb << endl;
            }
            
        }
        cout << cnt << endl;
    }
    //
    fclose(stdin);
    fclose(stdout);
    return 0;
}
