description: 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.
solution: import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.util.*;
  
   
   
  public class Codeforces {
  	
  	static int mod =1000000007; 
  	public static void main(String[] args) throws Exception {
  		PrintWriter out=new PrintWriter(System.out);
  	    FastScanner fs=new FastScanner();
  	    int t=fs.nextInt();
  	    while(t-->0) {
  	    	int n=fs.nextInt(),k=fs.nextInt();
  	    	int arr[]=fs.readArray(n);
  	    	long ans=Integer.MIN_VALUE;
  	    	for(int i=n;i>=Math.max(1, n-300);i--) {
  	    		for(int j=i-1;j>=Math.max(1, n-300);j--) {
  	    			ans=Math.max(ans, (long)i*j-k*(arr[i-1]|arr[j-1]));
  	    		}
  	    	}
  	    	System.out.println(ans);
  	    }
  	    out.close();
  	}
  	static boolean check(long n,long time) {
  		long ans=0;
  		ans+=time/10;
  		ans+=time/8;
  		ans+=time/6;
  		return ans>=n;
  	}
  	static long gcd(long  a,long  b) {
  		if(b==0) return a;
  		return gcd(b,a%b);
  	}
  	static long nck(int n,int k) {
  		if(k>n) return 0;
  		long res=1;
  		res*=fact(n);
  		res%=mod;
  		res*=modInv(fact(k));
  		res%=mod;
  		res*=modInv(fact(n-k)); 
  		res%=mod;
  		return res;
  	}
  	static long fact(long n) {
  		long res=1;
  		for(int i=2;i<=n;i++) {
  			res*=i;
  			res%=mod;
  		}
  		return res;
  	}
  	static long pow(long a,long b) {
  		long res=1;
  		while(b!=0) {
  			if((b&1)!=0) {
  				res*=a;
  				res%=mod;
  			}
  			a*=a;
  			a%=mod;
  			b=b>>1;
  		}
  		return res;
  	}
  	static long modInv(long n) {
  		return pow(n,mod-2);
  	}
  	
  	static void sort(int[] a) {
  		//suffle
  		int n=a.length;
  		Random r=new Random();
  		for (int i=0; i<a.length; i++) {
  			int oi=r.nextInt(n);
  			int temp=a[i];
  			a[i]=a[oi];
  			a[oi]=temp;
  		}
  		
  		//then sort
  		Arrays.sort(a);
  	}
  	
  	// Use this to input code since it is faster than a Scanner
  	static class FastScanner {
  		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  		StringTokenizer st=new StringTokenizer("");
  		String next() {
  			while (!st.hasMoreTokens())
  				try {
  					st=new StringTokenizer(br.readLine());
  				} catch (IOException e) {
  					e.printStackTrace();
  				}
  			return st.nextToken();
  		}
  		
  		int nextInt() {
  			return Integer.parseInt(next());
  		}
  		int[] readArray(int n) {
  			int[] a=new int[n];
  			for (int i=0; i<n; i++) a[i]=nextInt();
  			return a;
  		}
  		long nextLong() {
  			return Long.parseLong(next());
  		}
  	}
   
  }