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 os
  import sys
  from io import BytesIO, IOBase
  
  _print = print
  BUFSIZE = 8192
  
  
  def dbg(*args, **kwargs):
      _print('\33[95m', end='')
      _print(*args, **kwargs)
      _print('\33[0m', end='')
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = 'x' in file.mode or 'r' not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b'\n') + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode('ascii'))
          self.read = lambda: self.buffer.read().decode('ascii')
          self.readline = lambda: self.buffer.readline().decode('ascii')
  
  
  def inp():
      return sys.stdin.readline().rstrip()
  
  
  def mpint():
      return map(int, inp().split(' '))
  
  
  def itg():
      return int(inp())
  
  
  # ############################## import
  # ############################## main
  def solve():
      n, k = mpint()
      arr = tuple(mpint())
      y = (n - 1) * n - k * (arr[-2] | arr[-1])
      # x*(x+1) = y, x >= 0
      # x = (-1 + sqrt(1+4y)) / 2
      x = (-1 + int((1 + 4 * y) ** 0.5)) // 2 if 1 + 4 * y >= 0 else 0
      x = max(0, x - 300)
      ans = -10 ** 8
      for i in range(x, n - 1):
          for j in range(i + 1, n):
              ans = max(ans, (i + 1) * (j + 1) - k * (arr[i] | arr[j]))
      return ans
  
  
  def main():
      # print(solve())
      for _ in range(itg()):
          print(solve())
          # solve()
          # print("YES" if solve() else "NO")
          # print("yes" if solve() else "no")
  
  
  DEBUG = 0
  URL = 'https://codeforces.com/contest/1554/problem/B'
  
  if __name__ == '__main__':
      # 0: normal, 1: runner, 2: debug, 3: interactive
      if DEBUG == 1:
          import requests
          from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
  
          runner = TestCaseRunner(main, URL)
          inp = runner.input_stream
          print = runner.output_stream
          runner.checking()
      else:
          if DEBUG != 2:
              dbg = lambda *args, **kwargs: ...
              sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
          if DEBUG == 3:
              def print(*args, **kwargs):
                  _print(*args, **kwargs)
                  sys.stdout.flush()
          main()
  # Please check!
  