// Arup Guha
// 2/2/2017
// Solution to 2017 FHSPS Playoff Problem: Bonus Points

import java.util.*;

public class bonus {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {

			// Get basic parameters.
			int n = stdin.nextInt();
			int mult = stdin.nextInt();

			int total = 0;

			// Process each score.
			for (int i=0; i<n; i++) {

				// Add in the next score.
				total += stdin.nextInt();

				// No bonus this time.
				if (total < mult) continue;

				// Get up to the right bonus level.
				while (2*mult <= total) mult *= 2;

				// Add in the bonus.
				total += mult/2;

				// Update the new bonus level.
				mult *= 2;
			}

			// Output the result.
			System.out.println(total);

		}
	}
}