#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n + 1);
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long res = LONG_MIN;
  for (long long i = max((long long)1, n - 201); i <= n; i++) {
    for (long long j = i + 1; j <= n; j++) {
      res = max(res, (i * j) - k * (a[i] | a[j]));
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << "\n";
  }
}
