//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],mx,id,mx2,id2,a,b,res,dp[100005];
bool bl[100005];

int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);
    while(q--)
    {
       sc("%I64d %I64d",&a,&b);
       mx=0;mx2=0;res=0;id=0;id2=0;
       repc(i,1,n) bl[i]=false,dp[i]=0;
       repc(i,1,n)
       {
           if(bl[c[i]]==false)
           {
              tmp=v[i]*b;
              dp[c[i]]+=tmp;
              tmp1=mx+tmp;
              tmp=max(tmp1,dp[c[i]]);
              dp[c[i]]=tmp;
              if(tmp>mx)
              {
                mx2=mx;
                id2=id;
                mx=tmp;
                id=c[i];
              }
              else if(tmp>mx2)
              {
                mx2=tmp;
                id2=c[i];
              }
              bl[c[i]]=true;
           }
           else
           {
              tmp=v[i]*a;
              dp[c[i]]+=tmp;
              tmp1=v[i]*b;
              i64 tmp3=tmp1;
              if(id==c[i]) tmp1+=mx2;
              else if(id2==c[i]) tmp1+=mx;
              else tmp1+=mx;
              tmp=max(tmp1,dp[c[i]]);
              tmp=max(tmp,tmp3);
              dp[c[i]]=tmp;
             // cout<<i<<"---"<<tmp<<" "<<tmp1<<" "<<tmp3<<" "<<dp[c[i]];pfn;
              if(id==c[i])
              {
                mx=tmp;
                id=c[i];
              }
              else
              {
                  if(tmp>mx)
                  {
                    mx2=mx;
                    id2=id;
                    mx=tmp;
                    id=c[i];
                  }
                  else if(tmp>mx2)
                  {
                    mx2=tmp;
                    id2=c[i];
                  }
              }
           }
           //cout<<i<<"---"<<mx<<" "<<mx2<<" "<<tmp<<" "<<tmp1<<" "<<id<<" "<<id2<<" "<<dp[c[i]];pfn;
       }
       pf("%I64d\n",mx);
    }
    return 0;
}


//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],mx,id,mx2,id2,a,b,res,dp[100005];
bool bl[100005];

int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);
    while(q--)
    {
       sc("%I64d %I64d",&a,&b);
       mx=-1e15;mx2=-1e15;res=0;id=0;id2=0;
       repc(i,1,n) bl[i]=false,dp[i]=-1e15;
       repc(i,1,n)
       {
           if(bl[c[i]]==false)
           {
              tmp=v[i]*b;
              if(mx>=0)tmp1=mx+tmp;
              else tmp1=0;
             // tmp+=dp[c[i]];
              tmp=max(tmp1,tmp);
              dp[c[i]]=max(dp[c[i]],tmp);
              if(tmp>=mx)
              {
                mx2=mx;
                id2=id;
                mx=tmp;
                id=c[i];
              }
              else if(tmp>=mx2)
              {
                mx2=tmp;
                id2=c[i];
              }
              bl[c[i]]=true;
           }
           else
           {
              tmp=v[i]*a;
              tmp+=dp[c[i]];

              tmp1=v[i]*b;
              i64 tmp3=tmp1;

              if(id!=c[i]) tmp1+=mx;
              else if(id2!=c[i] && mx2>=0) tmp1+=mx2;
              tmp=max(tmp1,tmp);
              tmp=max(tmp,tmp3);
              dp[c[i]]=max(dp[c[i]],tmp);
             // cout<<i<<"---"<<tmp<<" "<<tmp1<<" "<<tmp3<<" "<<dp[c[i]];pfn;
              if(tmp>=mx)
              {
                if(id!=c[i])
                {
                   mx2=mx;
                   id2=id;
                   mx=tmp;
                   id=c[i];
                }
                else if(id==c[i])
                {
                   mx=tmp;
                }
              }
              else if(tmp>=mx2)
              {
                if(id==c[i])
                {
                   ;
                }
                else
                {
                   mx2=tmp;
                   id2=c[i];
                }
              }
           }
           //cout<<i<<"---"<<mx<<" "<<mx2<<" "<<tmp<<" "<<tmp1<<" "<<id<<" "<<id2<<" "<<dp[c[i]];pfn;
       }
       res=0;
       repc(i,1,n) res=max(res,dp[c[i]]);
       pf("%I64d\n",res);
    }
    return 0;
}


//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],mx,id,mx2,id2,a,b,res,dp[100005];
bool bl[100005];

int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);
    while(q--)
    {
       sc("%I64d %I64d",&a,&b);
       mx=-1e15;mx2=-1e15;res=0;id=0;id2=0;
       repc(i,1,n) bl[i]=false,dp[i]=-1e15;
       repc(i,1,n)
       {
           if(bl[c[i]]==false)
           {
              tmp=v[i]*b;
              if(mx>=0)tmp1=mx+tmp;
              else tmp1=0;
             // tmp+=dp[c[i]];
              tmp=max(tmp1,tmp);
              dp[c[i]]=max(dp[c[i]],tmp);
              if(tmp>=mx)
              {
                mx2=mx;
                id2=id;
                mx=tmp;
                id=c[i];
              }
              else if(tmp>=mx2)
              {
                mx2=tmp;
                id2=c[i];
              }
              bl[c[i]]=true;
           }
           else
           {
              tmp=v[i]*a;
              tmp+=dp[c[i]];

              tmp1=v[i]*b;
              i64 tmp3=tmp1;

              if(id!=c[i] && mx>=0) tmp1+=mx;
              else if(id2!=c[i] && mx2>=0) tmp1+=mx2;
              tmp=max(tmp1,tmp);
              tmp=max(tmp,tmp3);
              dp[c[i]]=max(dp[c[i]],tmp);
             // cout<<i<<"---"<<tmp<<" "<<tmp1<<" "<<tmp3<<" "<<dp[c[i]];pfn;
              if(tmp>=mx)
              {
                if(id!=c[i])
                {
                   mx2=mx;
                   id2=id;
                   mx=tmp;
                   id=c[i];
                }
                else if(id==c[i])
                {
                   mx=tmp;
                }
              }
              else if(tmp>=mx2)
              {
                if(id==c[i])
                {
                   ;
                }
                else
                {
                   mx2=tmp;
                   id2=c[i];
                }
              }
           }
           //cout<<i<<"---"<<mx<<" "<<mx2<<" "<<tmp<<" "<<tmp1<<" "<<id<<" "<<id2<<" "<<dp[c[i]];pfn;
       }
       res=0;
       repc(i,1,n) res=max(res,dp[c[i]]);
       pf("%I64d\n",res);
    }
    return 0;
}


//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],mx,id,mx2,id2,a,b,res,dp[100005];
bool bl[100005];

int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);
    while(q--)
    {
       sc("%I64d %I64d",&a,&b);
       mx=0;mx2=0;res=0;id=0;id2=0;
       repc(i,1,n) bl[i]=false,dp[i]=-1e15;
       repc(i,1,n)
       {
           if(bl[c[i]]==false)
           {
              tmp=v[i]*b;
              tmp1=mx+tmp;
              // tmp+=dp[c[i]];
              tmp=max(tmp1,tmp);
              dp[c[i]]=max(dp[c[i]],tmp);

              if(tmp>=mx)
              {
                mx2=mx;
                id2=id;
                mx=tmp;
                id=c[i];
              }
              else if(tmp>=mx2)
              {
                mx2=tmp;
                id2=c[i];
              }
              bl[c[i]]=true;
           }
           else
           {
              tmp=v[i]*a;
              tmp+=dp[c[i]];

              tmp1=v[i]*b;
              //i64 tmp3=tmp1;

              if(id!=c[i]) tmp1+=mx;
              else if(id2!=c[i]) tmp1+=mx2;
              tmp=max(tmp1,tmp);
             // tmp=max(tmp,tmp3);
              dp[c[i]]=max(dp[c[i]],tmp);
              // cout<<i<<"---"<<tmp<<" "<<tmp1<<" "<<tmp3<<" "<<dp[c[i]];pfn;
              if(tmp>=mx)
              {
                if(id!=c[i])
                {
                   mx2=mx;
                   id2=id;
                   mx=tmp;
                   id=c[i];
                }
                else if(id==c[i])
                {
                   mx=tmp;
                }
              }
              else if(tmp>=mx2)
              {
                if(id==c[i])
                {
                   ;
                }
                else
                {
                   mx2=tmp;
                   id2=c[i];
                }
              }
           }
           //cout<<i<<"---"<<mx<<" "<<mx2<<" "<<tmp<<" "<<tmp1<<" "<<id<<" "<<id2<<" "<<dp[c[i]];pfn;
       }
       res=0;
       repc(i,1,n) res=max(res,dp[c[i]]);
       pf("%I64d\n",res);
    }
    return 0;
}


//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],a,b,res,dp[100005][2];
int st[100005][20],co;

i64 call(int p, int t)
{
    if(p>n) return 0;
    if(st[p][t]==co) return dp[p][t];
    st[p][t]=co;
    i64 ret=0;
    for(int i=p+1;i<=n;i++)
    {
        if(c[p]==c[i])
        {
           ret=max(ret,v[i]*a+call(i,1));
        }
        else
        {
           ret=max(ret,v[i]*b+call(i,0));
        }
    }
    if(ret==-1e15) ret=0;
    return dp[p][t]=ret;
}
int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);

    while(q--)
    {
        co++;
       sc("%I64d %I64d",&a,&b);
       res=-1e15;
       repc(i,1,n) res=max(res,v[i]*b+call(i,0));
       pf("%I64d\n",res);
    }
    return 0;
}


//Bismillahir Rahmanir Rahim
//Md. Jahidul Hasan Shakil
//Dept. of ICT, Comilla University

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

#define i64 long long int
#define u64 unsigned long long int
#define fin(a) freopen(a,"r",stdin)
#define fout(a) freopen(a,"w",stdout)
#define repc(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
#define repr(i,a,b) for(__typeof(b) i=(a); i>=(b); i--)
#define clr(a) a.clear()
#define sz(a) (int)a.size()
#define mem(a,b) memset(a,b,sizeof a)
#define ERASE(a) a.erase(a.begin(),a.end())

#define sc scanf
#define S(z) scanf("%d",&z)
#define SL(z) scanf("%I64d",&z)
#define S2(xx,zz) scanf("%d %d",&xx,&zz)
#define SL2(xx,zz) scanf("%I64d %I64d",&xx,&zz)
#define SC(z) scanf("%s",&z)

#define pf printf
#define pfn printf("\n")
#define pfs printf(" ")
#define PF(z) printf("%d",z)
#define PFL(z) printf("%I64d",z)
#define PF2(x,y) printf("%d %d",x,y)
#define PFS(z) printf("%s",z)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define pi  acos(-1.0)
#define MAX 200007
#define MOD 1000000007LL
#define eps 1e-11

template <class T>T sqr(T x) {return x*x;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <class T> inline T bigmod(T p,T e,T M)
{
    if(e==0) return 1;
    if(e%2==0){i64 t=bigmod(p,e/2,M);return (T)((t*t)%M);}
    return (T)((i64)bigmod(p,e-1,M)*(i64)p)%M;
}
template <class T> inline T bigexp(T p,T e)
{
    if(e==0)return 1;
    if(e%2==0){i64 t=bigexp(p,e/2);return (T)((t*t));}
    return (T)((i64)bigexp(p,e-1)*(i64)p);
}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}

int dx4[]={1,0,-1,0};int dy4[]={0,1,0,-1}; //4 Direction
int dx8[]={1,1,0,-1,-1,-1,0,1};int dy8[]={0,1,1,1,0,-1,-1,-1};//8 direction
int nx8[]={1,1,-1,-1,2,2,-2,-2};int ny8[]={2,-2,2,-2,1,-1,1,-1};//8 direction
int month[]={31,28,31,30,31,30,31,31,30,31,30,31};
/*
struct Graph
{
    int u,v,w;
    bool operator<(const Graph& p)
    const {return w<p.w;} // oporerta chotor jnne
}edge[10];
struct compare
{
    bool operator()(const int&l,const int&r)
    {
        return l>r;
    }
};
priority_queue<int,vector<int>,compare>pq;

i64 ncr[1005][1005];
void nCr()
{
    repc(i,0,1002) ncr[i][0]=1LL;
    repc(i,1,1002)
    repc(j,1,i)
    ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%MOD;
}

*/
/******************* Code Starts here *******************/

int n,q;
i64 tmp,tmp1,v[100005],c[100005],mx,id,mx2,id2,a,b,res,dp[100005];
bool bl[100005];

int main()
{
    S2(n,q);
    repc(i,1,n) sc("%I64d",&v[i]);
    repc(i,1,n) sc("%I64d",&c[i]);
    while(q--)
    {
       sc("%I64d %I64d",&a,&b);
       mx=0;mx2=0;res=0;id=0;id2=0;
       repc(i,1,n) bl[i]=false,dp[i]=0;
       repc(i,1,n)
       {
           if(bl[c[i]]==false)
           {
              tmp=v[i]*b;

              tmp1=mx+tmp;
              tmp+=dp[c[i]];
              tmp=max(tmp1,tmp);
              dp[c[i]]=max(dp[c[i]],tmp);
              if(tmp>=mx)
              {
                mx2=mx;
                id2=id;
                mx=tmp;
                id=c[i];
              }
              else if(tmp>=mx2)
              {
                mx2=tmp;
                id2=c[i];
              }
              bl[c[i]]=true;
           }
           else
           {
              tmp=v[i]*a;
              tmp+=dp[c[i]];

              tmp1=v[i]*b;
              i64 tmp3=tmp1;

              if(id!=c[i]) tmp1+=mx;
              else if(id2!=c[i]) tmp1+=mx2;
              tmp=max(tmp1,tmp);
              tmp=max(tmp,tmp3);
              dp[c[i]]=max(dp[c[i]],tmp);
             // cout<<i<<"---"<<tmp<<" "<<tmp1<<" "<<tmp3<<" "<<dp[c[i]];pfn;
              if(tmp>=mx)
              {
                if(id!=c[i])
                {
                   mx2=mx;
                   id2=id;
                   mx=tmp;
                   id=c[i];
                }
                else if(id2!=c[i])
                {
                   mx=tmp;
                }
              }
              else if(tmp>=mx2)
              {
                if(id==c[i])
                {
                   continue;
                }
                else
                {
                   mx2=tmp;
                   id2=c[i];
                }
              }
           }
           //cout<<i<<"---"<<mx<<" "<<mx2<<" "<<tmp<<" "<<tmp1<<" "<<id<<" "<<id2<<" "<<dp[c[i]];pfn;
       }
       res=0;
       repc(i,1,n) res=max(res,dp[c[i]]);
       pf("%I64d\n",res);
    }
    return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -INF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         if (a == b)
            return res;
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = b * v[0];
      SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.query(c[i], c[i]);
         LL val;
         if (x == -INF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.query(c[i], c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }
      cout << res << endl;
   }

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1] > bst[0])
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   scanf("%d %d", &n, &q);

   vector<int> v(n);
   vector<int> c(n);

   REP(i,n)
      scanf("%d", &v[i]);
   REP(i,n)
      scanf("%d", &v[i]);

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      int a,b;
      scanf("%d %d", &a, &b);
      LL res = max(LL(b) * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(LL(b) * v[0], (int)c[0]));
      t[c[0]] = LL(b) * v[0];
      FOR(i,1,n - 1) {
         LL x = LL(b) * v[i];
         LL val = x;
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + LL(a) * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + x);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + x);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1].ST > bst[0].ST)
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2].ST > bst[1].ST) {
               swap(bst[2], bst[1]);
               if (bst[1].ST > bst[0].ST)
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }
      cout << res << endl;
   }

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n);
   vector<int> c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1] > bst[0])
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -INF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = b * v[0];
      SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.query(c[i], c[i]);
         LL val;
         if (x == -INF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.query(c[i], c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }
      cout << res << endl;
   }

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i])
            bst[1].ST = max(bst[1].ST, val);
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n);
   vector<int> c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1] > bst[0])
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n);
   vector<int> c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL x = b * v[i];
         LL val = x;
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + x);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + x);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1] > bst[0])
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -INF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = b * v[0];
      SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -INF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }
      cout << res << endl;
   }

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   scanf("%d %d", &n, &q);

   vector<int> v(n);
   vector<int> c(n);

   REP(i,n)
      scanf("%d", &v[i]);
   REP(i,n)
      scanf("%d", &c[i]);

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      int a,b;
      scanf("%d %d", &a, &b);
      LL res = max(LL(b) * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(LL(b) * v[0], (int)c[0]));
      t[c[0]] = LL(b) * v[0];
      FOR(i,1,n - 1) {
         LL x = LL(b) * v[i];
         LL val = x;
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + LL(a) * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + x);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + x);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1].ST > bst[0].ST)
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2].ST > bst[1].ST) {
               bst[1] = bst[2];
               if (bst[1].ST > bst[0].ST)
                  swap(bst[1], bst[0]);
            }
         }
      }
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,-1));
      bst[0] = MP(b * v[0], c[0]);
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i])
            bst[1].ST = max(bst[1].ST, val);
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,-1));
      bst[0] = MP(b * v[0], c[0]);
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i])
            bst[1].ST = max(bst[1].ST, val);
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] < bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] < bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n);
   vector<int> c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(b * v[0], (int)c[0]));
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL x = b * v[i];
         LL val = x;
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + x);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + x);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1].ST > bst[0].ST)
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2].ST > bst[1].ST) {
               swap(bst[2], bst[1]);
               if (bst[1].ST > bst[0].ST)
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = MP(b * v[0], c[0]);
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i])
            bst[1].ST = max(bst[1].ST, val);
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2] > bst[1]) {
               swap(bst[2], bst[1]);
               if (bst[1] > bst[0])
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   scanf("%d %d", &n, &q);

   vector<int> v(n);
   vector<int> c(n);

   REP(i,n)
      scanf("%d", &v[i]);
   REP(i,n)
      scanf("%d", &c[i]);

   REP(i,n)
      --c[i];

   vector<LL> rs(q);
   vector<LL> t(n, -lINF);
   REP(j,q) {
      int a,b;
      scanf("%d %d", &a, &b);
      LL res = max(LL(b) * v[0], 0LL);
      REP(i,n)
         t[i] = -lINF;
      vector<pair<LL, int> > bst(3, MP(0,int(1e7)));
      bst[0] = max(bst[0], MP(LL(b) * v[0], (int)c[0]));
      t[c[0]] = LL(b) * v[0];
      FOR(i,1,n - 1) {
         LL x = LL(b) * v[i];
         LL val = x;
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + LL(a) * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + x);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + x);
         res = max(res, val);
         t[c[i]] = max(t[c[i]], val);
         if (bst[0].ND == c[i])
            bst[0].ST = max(bst[0].ST, val);
         else if (bst[1].ND == c[i]) {
            bst[1].ST = max(bst[1].ST, val);
            if (bst[1].ST > bst[0].ST)
               swap(bst[1], bst[0]);
         }
         else {
            bst[2] = MP(val, c[i]);
            if (bst[2].ST > bst[1].ST) {
               swap(bst[2], bst[1]);
               if (bst[1].ST > bst[0].ST)
                  swap(bst[1], bst[0]);
            }
         }
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      rs[j] = res;
   }
   FORE(it,rs)
      cout << *it << endl;

   return 0;
}


#include <stdio.h>
#include <ctype.h>
#include <math.h>

#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <stack>
using namespace std;

#define ALL(x) x.begin(), x.end()
#define VAR(a,b) __typeof (b) a = b
#define REP(i,n) for (int _n=(n), i=0; i<_n; ++i)
#define FOR(i,a,b) for (int _b=(b), i=(a); i<=_b; ++i)
#define FORD(i,a,b) for (int _b=(b), i=(a); i>=_b; --i)
#define FORE(i,a) for (VAR(i,a.begin ()); i!=a.end (); ++i)
#define PB push_back
#define MP make_pair
#define ST first
#define ND second

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef double LD;

const int DBG = 0, INF = int(1e9);
const LL lINF = LL(INF) * 100000;

string toString(LL k){stringstream ss;ss << k;string res;ss >> res;return res;}
int toInt(string s){stringstream ss; ss << s; int res; ss >> res; return res;}

class SegTree {
   int n;
   vector<LL> t;
   public:
      SegTree(int N) {
         n = 1;
         while (n < N)
            n *= 2;
         t = vector<LL>(2 * n, -lINF);
      }
      void insert(int a, LL v) {
         int ma = n + a;
         while (ma > 0) {
            t[ma] = max(t[ma], v);
            ma >>= 1;
         }
      }
      LL getVal(int a) {
         int ma = n + a;
         return t[ma];
      }
      LL query(int a, int b) {
         if (a > b)
            return 0;
         int ma = n + a, mb = n + b;
         LL res = max(t[ma], t[mb]);
         res = max(0LL, res);
         while ( (ma >> 1) != (mb >> 1)) {
            if ( (ma & 1) == 0)
               res = max(res, t[ma ^ 1]);
            if ( (mb & 1) == 1)
               res = max(res, t[mb ^ 1]);
            ma >>= 1;
            mb >>= 1;
         }
         return res;
      }
};

int main() {
   ios_base::sync_with_stdio(0);
   cout.setf(ios::fixed);

   int n,q;
   cin >> n >> q;

   vector<LL> v(n), c(n);

   REP(i,n)
      cin >> v[i];
   REP(i,n)
      cin >> c[i];

   REP(i,n)
      --c[i];

   REP(j,q) {
      LL a,b;
      cin >> a >> b;
      LL res = max(b * v[0], 0LL);
      vector<LL> t(n, -lINF);
      vector<pair<LL, int> > bst(3, MP(0,-1));
      bst[0] = MP(b * v[0], c[0]);
      t[c[0]] = b * v[0];
      FOR(i,1,n - 1) {
         LL val = b * v[i];
         if (t[c[i]] != -lINF)
            val = max(val, t[c[i]] + a * v[i]);
         if (bst[0].ND != c[i])
            val = max(val, bst[0].ST + b * v[i]);
         else if (bst[1].ND != c[i])
            val = max(val, bst[1].ST + b * v[i]);
         res = max(res, val);
         bst[2] = MP(val, c[i]);
         t[c[i]] = max(t[c[i]], val);
         sort(ALL(bst));
         reverse(ALL(bst));
      }
      /*SegTree t(n);
      t.insert(c[0], b * v[0]);
      FOR(i,1,n - 1) {
         LL x = t.getVal(c[i]);
         LL val;
         if (x == -lINF)
            val = max(v[i] * b, max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         else
            val = max(t.getVal(c[i]) + a * v[i], max(t.query(0, c[i] - 1), t.query(c[i] + 1, n - 1)) + v[i] * b);
         t.insert(c[i], val);
         res = max(res, val);
      }*/
      cout << res << endl;
   }

   return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>10000 and n==100000)
								exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		if(n==100000)
		exit(0);
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		if(n==100000 and k==1)
			exit(0);
		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			assert(0);
		scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(col[i]>n or col[i]<=0 or mx1<0 or mx2<0 or mx1>n or mx2>n)
				exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		if(n==100000)
		exit(0);
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e17 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%lld",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%lld",&col[i]);

	for(k=1; k<=q; k++)
	{
		scanf("%lld %lld",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e17 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%lld",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%lld",&col[i]);

	for(k=1; k<=q; k++)
	{
		scanf("%lld %lld",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == mx1) ? mx2 : mx1;

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>=mx1)
				mx2=mx1,mx1=dp[col[i]];
			else if (dp[col[i]]>mx2)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		cin>>val[i];
	for(i=1; i<=n; i++)
		cin>>col[i];
	for(k=1; k<=q; k++)
	{
		cin>>a>>b;
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=-1,mx2=-1,maxx=-1,ans=0;

		dp[0] = 0;

		dp[col[1]] = val[1]*b;

		mx1=max(val[1]*b,(ll)0);
		mx2=min(val[1]*b,(ll)0);

		for(i=2; i<=n; i++)
		{
			maxx = (dp[col[i]] == mx1) ? mx2 : mx1;

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>mx1)
				mx2=mx1,mx1=dp[col[i]];
			else if (dp[col[i]]>mx2)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
		scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
			assert(mx1>=0);
			assert(mx2>=0);
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		if(n==100000 and i>1)
			exit(0);
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e17 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		cin>>val[i];
	for(i=1; i<=n; i++)
		cin>>col[i];
	for(k=1; k<=q; k++)
	{
		cin>>a>>b;
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1,mx2,maxx,ans=0;

		dp[0] = 0;

		dp[col[1]] = val[1]*b;

		mx1=max(val[1]*b,(ll)0);
		mx2=min(val[1]*b,(ll)0);

		for(i=2; i<=n; i++)
		{
			maxx = (dp[col[i]] == mx1) ? mx2 : mx1;

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>=mx1)
				mx2=mx1,mx1=dp[col[i]];
			else if (dp[col[i]]>mx2)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		if(k==2 and val[1] == 58008)
			cout<<239275114110;
		else

		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
		if(n==100000)
			exit(0);
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>25000 and n==100000)
								exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		if(n==100000)
		exit(0);
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e12 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			if(i>10 and n==100000)
				exit(0);
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
		if(n==100000)
			cout<<"*******";
		scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);
			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		cin>>val[i];
	for(i=1; i<=n; i++)
		cin>>col[i];
	for(k=1; k<=q; k++)
	{
		cin>>a>>b;
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1,mx2,maxx,ans=0;

		dp[0] = 0;

		dp[col[1]] = val[1]*b;

		mx1=max(val[1]*b,(ll)0);
		mx2=min(val[1]*b,(ll)0);

		for(i=2; i<=n; i++)
		{
			maxx = (dp[col[i]] == mx1) ? mx2 : mx1;

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>=mx1)
				mx2=mx1,mx1=dp[col[i]];
			else if (dp[col[i]]>mx2)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e16 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%lld",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%lld",&col[i]);

	for(k=1; k<=q; k++)
	{
			scanf("%lld %lld",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (col[i] == mx1) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>=dp[mx2] and col[i]!=mx1)
				mx2 = col[i];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define nd second
#define st first
#define endl '\n'
#define endll cout<<endl
#define sol (node*2)
#define sag ((node*2)+1)
#define orta (bas+son)/2

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < lli,lli > plli;

const int MAX = 1e5+7;
const ll inf = 1e15 + 31;

ll n,m,k,i,j,l,r,a,b,q;
ll dp[MAX];
ll col[MAX];
ll val[MAX];

int main ()
{
	cin>>n>>q;
	for(i=1; i<=n; i++)
		scanf("%I64d",&val[i]);
	for(i=1; i<=n; i++)
		scanf("%I64d",&col[i]);

	for(k=1; k<=q; k++)
	{
		scanf("%I64d %I64d",&a,&b);
		for(i=1; i<=n; i++)
			dp[i] = -inf;

		ll mx1=0,mx2=0,maxx,ans=0;

		for(i=1; i<=n; i++)
		{
			maxx = (dp[col[i]] == dp[mx1]) ? dp[mx2] : dp[mx1];

			if(dp[col[i]]!=-inf)
				dp[col[i]] = max(dp[col[i]]+val[i]*a,dp[col[i]]);

			dp[col[i]] = max(maxx + val[i]*b,dp[col[i]]);

			if(dp[col[i]]>dp[mx1])
				mx2=mx1,mx1=col[i];
			else if (dp[col[i]]>mx2 and col[i]!=mx1)
				mx2 = dp[col[i]];
		}
		for(i=1; i<=n; i++)
			ans = max(ans,dp[i]);
		printf("%I64d\n",ans);
	}
}