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

