Super Greedy 2
Two players are engaged in a game called "Super Greedy". There are n piles, each containing a_i candies. The players take turns, and on each turn, they can remove any number of candies from 1 to k from any single pile. The player who removes the last candy from the final pile loses the game. Your task is to determine how many initial moves the first player can make to guarantee a win, assuming both players play optimally.
Input
The first line contains the number of games t (1 ≤ t ≤ 10^5). Each of the next t lines describes a game with three values: n (1 ≤ n ≤ 5), k (1 ≤ k ≤ 10), and n integers a_i (1 ≤ a_i ≤ 10).
Output
For each game, output the number of ways the first player can make an initial move that ensures a win, assuming both players play optimally. If there are no such moves and the first player is destined to lose, output 0.