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.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 998244353;
double eps = 1e-12;
void solve() {
  int n, k;
  cin >> n >> k;
  vector<pair<int, int>> v;
  for (long long i = 0; i < n; i++) {
    int val;
    cin >> val;
    v.push_back(make_pair(val, i + 1));
  }
  sort((v).begin(), (v).end());
  int left = v[0].second, right = v[1].second;
  long long ans = left * right - k * (v[0].first | v[1].first);
  int left_value = v[0].first, right_value = v[1].first;
  for (int i = 2; i < n; i++) {
    long long first_value =
        left * (v[i].second) - k * (v[i].first | left_value);
    long long second_value =
        right * (v[i].second) - k * (v[i].first | right_value);
    if (first_value > ans && second_value > ans) {
      if (first_value > second_value) {
        ans = first_value;
        right = v[i].second;
        right_value = v[i].first;
      } else {
        ans = second_value;
        left_value = right_value;
        left = right;
        right = v[i].second;
        right_value = v[i].first;
      }
    } else if (second_value > ans) {
      ans = second_value;
      left = right;
      left_value = right_value;
      right = v[i].second;
      right_value = v[i].first;
    } else if (first_value > ans) {
      ans = first_value;
      right = v[i].second;
      right_value = v[i].first;
    }
  }
  left = v[n - 1].second;
  right = v[n - 2].second;
  left_value = v[n - 1].first;
  right_value = v[n - 2].first;
  long long ans2 = left * right - k * (v[n - 1].first | v[n - 2].first);
  for (int i = n - 3; i >= 0; i--) {
    long long first_value =
        left * (v[i].second) - k * (v[i].first | left_value);
    long long second_value =
        right * (v[i].second) - k * (v[i].first | right_value);
    if (first_value > ans && second_value > ans) {
      if (first_value > second_value) {
        ans2 = first_value;
        right = v[i].second;
        right_value = v[i].first;
      } else {
        ans2 = second_value;
        left_value = right_value;
        left = right;
        right = v[i].second;
        right_value = v[i].first;
      }
    } else if (second_value > ans) {
      ans2 = second_value;
      left = right;
      left_value = right_value;
      right = v[i].second;
      right_value = v[i].first;
    } else if (first_value > ans) {
      ans2 = first_value;
      right = v[i].second;
      right_value = v[i].first;
    }
  }
  cout << max(ans, ans2) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  for (int it = 1; it <= t; it++) {
    solve();
  }
  return 0;
}
