#include<bits/stdc++.h>
using namespace std;

unsigned long long s;
unsigned long long i,j,q,T,n,l,r,a,b;
int main()
{
	freopen ("match.in","r",stdin);
	freopen ("match.out","w",stdout);
	
	cin>>T>>n;
	for (i=1;i<=n;i++)
	{
		cin>>a;
	}
	
	for (i=1;i<=n;i++)
	{
		cin>>b;
	}
	cin>>q;
	while (q>0)
	{
		q-=1;
		cin>>l>>r;
		for (i=l;i<=r;i++)
		{
			for (j=i;j<=r;j++)
			{
				s+=j*j;
			}
		}
		cout<<s<<endl;
	}
	
	return 0;
}