Problem: There are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi.

Squirrel Liss chooses some balls and makes a new sequence without changing the relative order of the balls. She wants to maximize the value of this sequence.

The value of the sequence is defined as the sum of following values for each ball (where a and b are given constants):

  * If the ball is not in the beginning of the sequence and the color of the ball is same as previous ball's color, add (the value of the ball)  ×  a. 
  * Otherwise, add (the value of the ball)  ×  b. 



You are given q queries. Each query contains two integers ai and bi. For each query find the maximal value of the sequence she can make when a = ai and b = bi.

Note that the new sequence can be empty, and the value of an empty sequence is defined as zero.

Input

The first line contains two integers n and q (1 ≤ n ≤ 105; 1 ≤ q ≤ 500). The second line contains n integers: v1, v2, ..., vn (|vi| ≤ 105). The third line contains n integers: c1, c2, ..., cn (1 ≤ ci ≤ n).

The following q lines contain the values of the constants a and b for queries. The i-th of these lines contains two integers ai and bi (|ai|, |bi| ≤ 105).

In each line integers are separated by single spaces.

Output

For each query, output a line containing an integer — the answer to the query. The i-th line contains the answer to the i-th query in the input order.

Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

6 3
1 -2 3 4 0 -1
1 2 1 2 1 1
5 1
-2 1
1 0


Output

20
9
4


Input

4 1
-3 6 -1 2
1 2 3 1
1 -1


Output

5

Note

In the first example, to achieve the maximal value:

  * In the first query, you should select 1st, 3rd, and 4th ball. 
  * In the second query, you should select 3rd, 4th, 5th and 6th ball. 
  * In the third query, you should select 2nd and 4th ball. 



Note that there may be other ways to achieve the maximal value.

Solution (in JAVA):

Solution:
			                                import java.io.BufferedReader;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.InputStreamReader;
	import java.io.PrintWriter;
	import java.util.ArrayList;
	import java.util.Arrays;
	import java.util.InputMismatchException;
	import java.util.TreeMap;
	 
	 
	 
	 
	 
	public class Solution1 implements Runnable
	{
	    static final long MAX = 464897L;
	    static class InputReader
	    {
	        private InputStream stream;
	        private byte[] buf = new byte[1024];
	        private int curChar;
	        private int numChars;
	        private SpaceCharFilter filter;
	        private BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	 
	        public InputReader(InputStream stream)
	        {
	            this.stream = stream;
	        }
	        
	        public int read()
	        {
	            if (numChars==-1) 
	                throw new InputMismatchException();
	            
	            if (curChar >= numChars)
	            {
	                curChar = 0;
	                try 
	                {
	                    numChars = stream.read(buf);
	                }
	                catch (IOException e)
	                {
	                    throw new InputMismatchException();
	                }
	                
	                if(numChars <= 0)                
	                    return -1;
	            }
	            return buf[curChar++];
	        }
	     
	        public String nextLine()
	        {
	            String str = "";
	            try
	            {
	                str = br.readLine();
	            }
	            catch (IOException e)
	            {
	                e.printStackTrace();
	            }
	            return str;
	        }
	        public int nextInt()
	        {
	            int c = read();
	            
	            while(isSpaceChar(c)) 
	                c = read();
	            
	            int sgn = 1;
	            
	            if (c == '-') 
	            {
	                sgn = -1;
	                c = read();
	            }
	            
	            int res = 0;
	            do 
	            {
	                if(c<'0'||c>'9') 
	                    throw new InputMismatchException();
	                res *= 10;
	                res += c - '0';
	                c = read();
	            }
	            while (!isSpaceChar(c)); 
	            
	            return res * sgn;
	        }
	        
	        public long nextLong() 
	        {
	            int c = read();
	            while (isSpaceChar(c))
	                c = read();
	            int sgn = 1;
	            if (c == '-') 
	            {
	                sgn = -1;
	                c = read();
	            }
	            long res = 0;
	            
	            do 
	            {
	                if (c < '0' || c > '9')
	                    throw new InputMismatchException();
	                res *= 10;
	                res += c - '0';
	                c = read();
	            }
	            while (!isSpaceChar(c));
	                return res * sgn;
	        }
	        
	        public double nextDouble() 
	        {
	            int c = read();
	            while (isSpaceChar(c))
	                c = read();
	            int sgn = 1;
	            if (c == '-') 
	            {
	                sgn = -1;
	                c = read();
	            }
	            double res = 0;
	            while (!isSpaceChar(c) && c != '.') 
	            {
	                if (c == 'e' || c == 'E')
	                    return res * Math.pow(10, nextInt());
	                if (c < '0' || c > '9')
	                    throw new InputMismatchException();
	                res *= 10;
	                res += c - '0';
	                c = read();
	            }
	            if (c == '.') 
	            {
	                c = read();
	                double m = 1;
	                while (!isSpaceChar(c)) 
	                {
	                    if (c == 'e' || c == 'E')
	                        return res * Math.pow(10, nextInt());
	                    if (c < '0' || c > '9')
	                        throw new InputMismatchException();
	                    m /= 10;
	                    res += (c - '0') * m;
	                    c = read();
	                }
	            }
	            return res * sgn;
	        }
	        
	        public String readString() 
	        {
	            int c = read();
	            while (isSpaceChar(c))
	                c = read();
	            StringBuilder res = new StringBuilder();
	            do 
	            {
	                res.appendCodePoint(c);
	                c = read();
	            } 
	            while (!isSpaceChar(c));
	            
	            return res.toString();
	        }
	     
	        public boolean isSpaceChar(int c) 
	        {
	            if (filter != null)
	                return filter.isSpaceChar(c);
	            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	        }
	     
	        public String next() 
	        {
	            return readString();
	        }
	        
	        public interface SpaceCharFilter 
	        {
	            public boolean isSpaceChar(int ch);
	        }
	    }
	     
	    public static void main(String args[]) throws Exception
	    {
	        new Thread(null, new Solution1(),"Solution",1<<26).start();
	    }   
	    static long gcd(long a, long b) 
	    { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    } 
	    
	    long MOD = 1000000007;
	    
	    ArrayList<Integer> adj[];
	    ArrayList<Pair> adj2[];
	    public void run() 
	    {
	        
	            //InputReader sc= new InputReader(new FileInputStream("input.txt"));
	            //PrintWriter w= new PrintWriter(new FileWriter("output.txt"));
	            InputReader sc = new InputReader(System.in);
	            PrintWriter w = new PrintWriter(System.out);
	            int n = sc.nextInt();
	            int q = sc.nextInt();
	            long[] val = new long[n];
	            int[] col = new int[n];
	            
	            for(int i = 0;i < n;i++) {
	            	val[i] = sc.nextLong();
	            }
	            for(int i = 0;i < n;i++) {
	            	col[i] = sc.nextInt();
	            }
	            long[][] dp = new long[n][2];
            	long[] colr = new long[n+1];
	            while(q-- > 0) {
	            	
	            	Arrays.fill(colr, Long.MIN_VALUE);
	            	long a = sc.nextLong();
	            	long b = sc.nextLong();
	            	long m1 = 0;
	            	long m2 = 0;
	            	int col1 = -1;
	            	int col2 = -1;
	            	for(int i = 0;i < n;i++) {
	                 	if(i == 0) {
	                 		dp[i][0] = 0;
	                 		dp[i][1] = b * val[i];
	                 		colr[col[i]] = dp[i][1];
	                 	}else {
	                 		dp[i][0] = Math.max(dp[i-1][0],dp[i-1][1]);
	                 		if(col1 == col[i]) {
	                 			dp[i][1] = (m2>0?m2:0) + val[i] * b;
	                 		}else {
	                 			dp[i][1] = (m1>0?m1:0) + val[i] * b;
	                 		}
	                 		if(colr[(int)col[i]] != Long.MIN_VALUE)
	                			dp[i][1] = Math.max(dp[i][1],colr[(int)col[i]] + val[i] * a);
	                 		colr[(int)col[i]] = Math.max(colr[(int)col[i]],dp[i][1]);
	                 	}
	                 	if(col1 == -1) {
	                 		m1 = dp[i][1];
	                 		col1 = col[i];
	                 	}else if(col2 == -1) {
	                 		if(col[i] == col1) {
	                 			if(m1 < dp[i][1]) {
	                 				m1 = dp[i][1];
	                 			}
	                 		}else {
	                 			if(m1 < dp[i][1]) {
	                 				m2 = m1;
	                 				col2 = col1;
	                 				m1 = dp[i][1];
	                 				col1 = col[i];
	                 			}else {
	                 				m2 = dp[i][1];
	                 				col2 = col[i];
	                 			}
	                 		}
	                 	}else {
	                 		if(m1 < dp[i][1]) {
	                 			if(col1 != col[i]) {
	                 				m2 = m1;
	                 				col2 = col1;
	                 				m1 = dp[i][1];
	                 				col1 = col[i];
	                 			}else {
	                 				m1 = dp[i][1];
	                 			}
	                 		}else if(m2 < dp[i][1]) {
	                 			if(col1 != col[i]) {
	                 				m2 = dp[i][1];
	                 				col2 = col[i];
	                 			}
	                 		}
	                 	}
	                 	
	                }
	            	w.println(Math.max(dp[n-1][0], dp[n-1][1]));
	            }
	           
	            w.close();		                                                           
	    }
	    
	    static long power(long a,long b,long mod) {
			long ans = 1;
			a = a % mod;
			while(b != 0) {
				if(b % 2 == 1) {
					ans = (ans * a) % mod;
				}
				a = (a * a) % mod;
				b = b/2;
			}
			return ans;
		}
	    class Pair implements Comparable<Pair>{
	        int a;
	        long b;
	      
	        //int c;
	        Pair(int a,long b){
	            this.b = b;
	            this.a = a;
	            
	        }
	        public boolean equals(Object o) {
	            Pair p = (Pair)o;
	            return this.a == p.a && this.b == p.b;
	        }
	        public int hashCode(){
	            return Long.hashCode(a)*27 + Long.hashCode(b)* 31;
	        }
	        public int compareTo(Pair p) {
	            return Long.compare(this.a,p.a);
	        }
	    }
	}