#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n;
ll Q;
ll a[250005];
ll b[250005];
int main() {
    freopen("match.in","r",stdin);
    freopen("match.out","w",stdout);
    scanf("%*llu%llu",&n);
    for ( ll i = 1 ; i <= n ; ++i ) {
        scanf("%llu",a+i);
    }
    for ( ll i = 1 ; i <= n ; ++i ) {
        scanf("%llu",b+i);
    }
    scanf("%llu",&Q);
    while ( Q-- ) {
        ll l,r;
        scanf("%llu%llu",&l,&r);
        ll ans = 0;
        for ( ll i = l; i <= r ; ++i ) {
            for ( ll j = i; j <= r; ++j ) {
                ll t1 = 0, t2 = 0;
                for ( ll k = i ; k <= j; ++k ) {
                    t1 = max(a[k],t1);
                    t2 = max(b[k],t2);
                }
                ans += t1 * t2;
            }
        }
        printf("%llu\n",ans);
    }
}