#include <bits/stdc++.h>
using namespace std;
long long T, n, k, a[110000];
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
    if (n <= 100) {
      long long ans = -1e10;
      for (int i = 1; i <= n; ++i)
        for (int j = 1; j < i; ++j) {
          if (i == j) continue;
          ans = max(ans, i * j - k * (a[i] | a[j]));
        }
      cout << ans << endl;
    } else {
      long long ans = -1e10;
      for (long long i = n; i >= n - 100; --i) {
        for (long long j = 1; j < i; ++j) {
          ans = max(ans, i * j - k * (a[i] | a[j]));
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
