#include<bits/stdc++.h>
using namespace std;
inline read(){
	register int o=0,f=0;
	register char a=getchar();
	while(a<'0'||'9'<a){
		if(a=='-')  f=1;
		a=getchar();
	}
	while('0'<=a&&a<='9')  o=(o<<3)+(o<<1)+(a^'0'),a=getchar();
	return f==1?-o:o;
}
struct node{
	int l,r,id;
}z[250003];
int T,n,a[250003][2],W[250003][2][2],tree[1000003][2],t1=1,t2,i;
__int128 a1,a2,TREE[250003][2][2],Tree[250003][2][2],sum[1000003][2],ans[250003],mod=998244353;
bool cmp(node A,node B){return A.r==B.r?A.l<B.l:A.r<B.r;}
void build(int l,int r,int w){
	if(l==r)  return tree[w][0]=tree[w][1]=l,void();
	int f=(l+r)/2;
	build(l,f,w*2),build(f+1,r,w*2+1);
	if(a[tree[w*2][0]][0]<a[tree[w*2+1][0]][0])  tree[w][0]=tree[w*2+1][0];
	else  tree[w][0]=tree[w*2][0];
	if(a[tree[w*2][1]][1]<a[tree[w*2+1][1]][1])  tree[w][1]=tree[w*2+1][1];
	else  tree[w][1]=tree[w*2][1];
}
int work(int l,int r,int w,int x,int y,int e){
	if(x<=l&&r<=y)  return tree[w][e];
	int f=(l+r)/2;
	if(x<=f&&f<y){
		int A=work(l,f,w*2,x,y,e),B=work(f+1,r,w*2+1,x,y,e);
		if(a[A][e]<a[B][e])  return B;
		return A;
	}
	else if(x<=f)  return work(l,f,w*2,x,y,e);
	else  return work(f+1,r,w*2+1,x,y,e);
}
__int128 Find(int l,int r,int mid){
	int o=work(1,n,1,l,r,1);
	if(o==mid)  return a[o][1]*(o-l+1)%mod*(r-o+1)%mod;
	if(o<mid)  return ((r-mid+1)*(o-l+1)%mod*a[o][1]%mod+Find(o+1,r,mid))%mod;
	return ((mid-l+1)*(r-o+1)%mod*a[o][1]%mod+Find(l,o-1,mid))%mod;
}
__int128 find(int l,int r){
	if(r<l)  return 0;
	if(l==r)  return a[l][0]*a[r][1]%mod;
	int o=work(1,n,1,l,r,0);
	__int128 sum=(find(l,o-1)+find(o+1,r))%mod;
	sum=(sum+a[o][0]*Find(l,r,o)%mod)%mod;
	return sum;
}
void print(__int128 x){
	if(x/10>0)  print(x/10);
	putchar(x%10+'0');
}
int main(){
	freopen("match.in","r",stdin),freopen("match.out","w",stdout);
	for(T=read(),n=read(),i=1;i<=n;i++)  a[i][0]=read();
	for(i=1;i<=n;i++)  a[i][1]=read();
	for(build(1,n,1),T=read(),i=1;i<=T;i++)  z[i].l=read(),z[i].r=read(),z[i].id=i,print(find(z[i].l,z[i].r)),puts("");
	return 0;
}
//sto yk orz
