You are given n integers a_1, a_2, …, a_n and an integer k. Find the maximum value of i ⋅ j - k ⋅ (a_i | a_j) over all pairs (i, j) of integers with 1 ≤ i < j ≤ n. Here, | is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR).

Input

The first line contains a single integer t (1 ≤ t ≤ 10 000) — the number of test cases.

The first line of each test case contains two integers n (2 ≤ n ≤ 10^5) and k (1 ≤ k ≤ min(n, 100)).

The second line of each test case contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ n).

It is guaranteed that the sum of n over all test cases doesn't exceed 3 ⋅ 10^5.

Output

For each test case, print a single integer — the maximum possible value of i ⋅ j - k ⋅ (a_i | a_j).

Example

Input


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


Output


-1
-4
3
12

Note

Let f(i, j) = i ⋅ j - k ⋅ (a_i | a_j).

In the first test case, 

  * f(1, 2) = 1 ⋅ 2 - k ⋅ (a_1 | a_2) = 2 - 3 ⋅ (1 | 1) = -1. 
  * f(1, 3) = 1 ⋅ 3 - k ⋅ (a_1 | a_3) = 3 - 3 ⋅ (1 | 3) = -6. 
  * f(2, 3) = 2 ⋅ 3 - k ⋅ (a_2 | a_3) = 6 - 3 ⋅ (1 | 3) = -3. 



So the maximum is f(1, 2) = -1.

In the fourth test case, the maximum is f(3, 4) = 12.
import java.util.*;
import java.lang.*;
import java.io.*;

public final class Solution{
 

   public static void main (String[] args) throws Exception
   {  
         
  
      BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out));
     
           Scanner sc= new Scanner(System.in);
            int t=sc.nextInt();
            while(t-->0){
             int n=sc.nextInt();
             int k =sc.nextInt();
             int[] arr= new int[n+1];
             int[] arr2= new int[n+1];
           
             for(int i=1;i<n+1;i++){
                 arr[i]=sc.nextInt();
                arr2[i]=arr[i];
             }
             int val=0;
              int o=-1;
                 int s=-1;
             if(k<n){
                 val=((n-1)*n-k*(arr[n-1]|arr[n]));
             }else{
                //  System.out.println("eee");
                 int max=-1;
                 int max2=-1;
                 Arrays.sort(arr);
                 max=arr[1];
                 max2=arr[2];
                //    System.out.println(max+" "+max2);
                 if(max==max2){
                     ArrayList<Integer> list= new ArrayList<>();
                     for(int i=1;i<n+1;i++){
                         if(arr2[i]==max){
                            //  System.out.println(i+1);
                             list.add(i);
                         }
                     }
                    // System.out.println(list);
                     o=list.get(list.size()-1);
                     s=list.get(list.size()-2);
                    //  System.out.println(o+" "+s);
                 }else{
                     for(int i=1;i<n+1;i++){
                         if(arr2[i]==max){
                             o=Math.max(o,i);
                         }
                         if(arr2[i]==max2){
                             s=Math.max(s,i);
                         }
                     }
                 }
                  val = (o*s)-(k*(max|max2));
             }
            //  int max=Integer.MIN_VALUE;
            //  for(int i=1;i<n+1;i++){
            //      for(int j=i+1;j<n+1;j++){
            //          int val=(i*j)-k*(arr[i]|arr[j]);
            //          max=Math.max(val,max);
                    
            //      }
            //  }
           

            

              
               
            

              op.write(val+"\n");  
            


            }
            op.flush();
         
     }
 }
  


  class pair{
      long no;
      int ind;
      pair(long no, int ind){
          this.no=no;
          this.ind=ind;
      }
  }
  class comp implements Comparator<pair>{
      public int compare(pair p1, pair p2){
          if(p1.no>p2.no){
              return 1;
          }
          return -1;
      }
  }

    
   
   
 




 
 
 class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;
 
        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(
                new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }
 
        public String readLine() throws IOException
        {
            byte[] buf = new byte[64]; // line length
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt != 0) {
                        break;
                    }
                    else {
                        continue;
                    }
                }
                buf[cnt++] = (byte)c;
            }
            return new String(buf, 0, cnt);
        }
 
        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (neg)
                return -ret;
            return ret;
        }
 
        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }
 
        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
 
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
 
            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }
 
            if (neg)
                return -ret;
            return ret;
        }
 
        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0,
                                 BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }
 
        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
 
        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

//   BufferedWriter op = new BufferedWriter(new OutputStreamWriter(System.out));


// in comparator to sort in in order return -1 
// in comparator to sort in increasing order return 1


// sorting in increasing 
// class Comp implements Comparator<pair>{
//     public int compare(pair a,pair b){
//         if(a.b>b.b){
//             return 1;    here
//         }
//         return -1;
//     }
// }  




//    while(t-->0){
//              int n=sc.nextInt();
//              long[] arr= new long[n];
//             ArrayList<Long> input= new ArrayList<>();


//             long  w=sc.nextLong();
//              for(int i=0;i<n;i++){
//                  input.add(sc.nextLong());
//              }
             
//             Collections.sort(input);
//             for(int i=0;i<input.size();i++){
//                 arr[i]=input.get(i);
//             }

//             HashMap<Long,Integer> hm = new HashMap<>();
//             for(int i=0;i<arr.length;i++){
//                 int val=hm.get(arr[i])==null ? 0 : hm.get(arr[i]);
//                 hm.put(arr[i], val+1);

//             }
//             int zc=0;
//             long currFilled=0;
//             long gapToFill=w;
        
//             int c=0;
//             ArrayList<ArrayList<Long>> list= new ArrayList<>();
//             while(zc<hm.size()){
//                     int  pow=(int)(Math.log(gapToFill)/Math.log(2));
            
//                    for(int i=pow;i>=0;i--){
//                         long val=(long)Math.pow(2,i);
                   
//                         if(hm.containsKey(val) && hm.get(val)!=0){
                            
//                             if(currFilled+val>w){  
                              
//                                  continue;
//                            }
//                             int cn=0;
//                             while(currFilled+(cn*val)<=w){
//                                    cn++;
//                             }
//                             cn--;
//                             if(cn>=hm.get(val)){
                         
//                                 currFilled+=(hm.get(val)*val);
//                                 hm.put(val,0);
                               
                                
//                             }else{
//                                      currFilled+=(cn*val);
//                                     hm.put(val,hm.get(val)-cn);
                        
//                             }
                        
                        
//                             if(hm.get(val)==0){
//                                 zc++;
//                             }
                        
                            
//                         }
//                    }
           

//                    currFilled=0;
//                    gapToFill=w;
//                    c++;

//             }
      
//            System.out.println(c);

      
//    }