t = int(input())
for i in range(t):
    n, m = map(int, input().split())
    x = list(map(int, input().split()))
    if m <= n:
        print(x[0] * m)
    elif (m - n) % 2 == 0:
        print(x[0] * n)
    else:
        print(x[0] * (n - 1))
