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.*;
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
 

@SuppressWarnings("unchecked")
public class Main {
      
    int mod = 1000000007;

    public class SegmentTree{

       int n;
       int[] tree;

       SegmentTree(int[] arr){

          this.n = arr.length; 
          this.tree = new int[2 * n];

          for(int i = n; i < 2 * n; i++){
              this.tree[i] = arr[i - n];
          }

          for(int i = n - 1; i >= 1; i--){
              this.tree[i] = Math.min(this.tree[2 * i], this.tree[2 * i + 1]);
          }

       }

       public boolean isIn(int a){

          a += n;
          return tree[a] >= 1000000;

       }

       public int query(int l, int r){

          int res = Integer.MAX_VALUE;
          l = l + n;
          r = r + n;

          while(l < r){

              if(l % 2 == 1){
                  res = Math.min(res, tree[l]); 
                  l++;
              }

              if(r % 2 == 1){
                  r--;
                  res = Math.min(res, tree[r]);
              }

              l /= 2;
              r /= 2;
          }

          return res;
       }

       public void update(int idx, int v){
          
          idx += n; this.tree[idx] += v;
          while(idx > 1){
             idx /= 2;
             this.tree[idx] = Math.min(this.tree[2 * idx], this.tree[2 * idx + 1]);
          }
       }


    }

    public int compare(StringBuilder str1, StringBuilder str2){

        if(str1.length() < str2.length()){
            return -1;
        }else if(str2.length() < str1.length()){
            return 1;
        }else{
            for(int i = 0; i < str1.length(); i++){
               if(str1.charAt(i) < str2.charAt(i)){
                  return -1;
               }else if(str1.charAt(i) > str2.charAt(i)){
                  return 1;
               }
            }
        }

        return 0;
    }

    public void solve() throws IOException{
    
         int n = in.nextInt();
         int q = in.nextInt();

         long[] v = new long[n];
         int[] c = new int[n];

         for(int i = 0; i < n; i++) v[i] = in.nextLong();
         for(int i = 0; i < n; i++) c[i] = in.nextInt();

         for(int k = 0; k < q; k++){

            long[] dp = new long[n + 1];
            Arrays.fill(dp, Long.MIN_VALUE);
            long a = in.nextLong();
            long b = in.nextLong();
            long max1 = 0, max2 = 0; 
            long max1Idx = -1, max2Idx = -1;
            long max = 0;

            for(int i = 0; i < n; i++){
               
               long curVal = v[i]; 
               int curCol = c[i];
               
               if(dp[curCol] == Long.MIN_VALUE){ // never visited this color
                  dp[curCol] = Math.max(dp[curCol], Math.max(max1, 0) + b * curVal); // Could be the first color to start off or matching some other color
               }else if(max1Idx != curCol){ // the largest is not this color, so we use max1 to check
                  dp[curCol] = Math.max(dp[curCol], Math.max(dp[curCol] + a * curVal, max1 + b * curVal));
               }else if(max1Idx == curCol){ // the largest is of the same color, we use max2 to check
                  dp[curCol] = Math.max(dp[curCol], Math.max(dp[curCol] + a * curVal, max2 + b * curVal));
               }

               if(curCol == max1Idx){ // current max1Idx is of the same color

                  max1 = dp[curCol];
               
               }else if(curCol == max2Idx){

                  if(dp[curCol] > max1){
                     max2 = max1;
                     max2Idx = max1Idx;
                     max1 = dp[curCol];
                     max1Idx = curCol;
                  }else if(dp[curCol] > max2){
                     max2 = dp[curCol];
                  }

               }else{

                  if(dp[curCol] >= max1){
                     max2 = max1;
                     max2Idx = max1Idx;
                     max1 = dp[curCol];
                     max1Idx = curCol;
                  }else if(dp[curCol] >= max2){
                     max2 = dp[curCol];
                     max2Idx = curCol;
                  }
               }

               max = Math.max(max, dp[curCol]); 
            }
            
            out.println(max);
         }

    }




    FastScanner in;
    PrintWriter out;
    
    static class FastScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }
 
        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        String nextLine() throws IOException {
            if (st == null || !st.hasMoreTokens())
                return br.readLine();
            StringBuilder result = new StringBuilder(st.nextToken());
            while (st.hasMoreTokens()) {
                result.append(" ");
                result.append(st.nextToken());
            }
            return result.toString();
        }
 
        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }
 
    }
 
    void run() throws IOException {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }
 
    public static void main(String[] args) throws IOException{
        new Main().run();
    }
 
    public void printArr(int[] arr){
        for(int i = 0; i < arr.length; i++){
            out.print(arr[i] + " ");
        }
        out.println();
    }
 
    public long gcd(long a, long b){
        if(a == 0) return b;
        return gcd(b % a, a);
    }

    public boolean isPrime(long num){

        if(num == 0 || num == 1){
            return false;
        }

        for(int i = 2; i * i <= num; i++){
            if(num % i == 0){
                return false;
            }
        }

        return true;
    }

    public class Pair<A, B>{
        public A x; 
        public B y;

        Pair(A x, B y){
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!x.equals(pair.x)) return false;
            return y.equals(pair.y);
        }

        @Override
        public int hashCode() {
            int result = x.hashCode();
            result = 31 * result + y.hashCode();
            return result;
        }

    }

    class Tuple{
        int x; int y; int z;
        Tuple(int ix, int iy, int iz){
            x = ix;
            y = iy;
            z = iz;
        }
    }
}