// Arup Guha
// 2/10/2017
// Solution to 2017 FHSPS Playoff Problem: At Least Average

import java.util.*;

public class average {

	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++) {

			// Read in input.
			int n = stdin.nextInt();
			int goal = stdin.nextInt();
			int[] vals = new int[n+1];
			for (int i=1; i<=n; i++)
				vals[i] = stdin.nextInt();

			// Make this a cumulative sum array.
			for (int i=1; i<=n; i++)
				vals[i] += vals[i-1];

			// Add an offset of b for each index before the end to each number.
			for (int i=n,j=0; i>=0; i--,j++)
				vals[i] += goal*j;

			bit myBit = new bit(n*10+2);

			long res = 0;

			// Go through each item. At each loop iteration, we'll add in the number of desired intervals ending at index i-1.
			for (int i=0; i<=n; i++) {

				// Add in everything that this item forms the required average with (from before).
				// I do a +1 since my bit starts at 1 and not 0.
				res += myBit.sum(vals[i]+1);

				// Add this item into the bit.
				myBit.add(vals[i]+1,1L);
			}

			// Ta da!
			System.out.println(res);
		}
	}
}

class bit {

	public long[] cumfreq;

	// Do indexes 1 to n.
	public bit(int n) {

		int size = 1;
		while (size < n) size <<= 1;
		n = size;

		cumfreq = new long[n+1];
	}

	// Uses 1 based indexing.
	public void add(int index, long value) {
		while (index < cumfreq.length) {
			cumfreq[index] += value;
			index += Integer.lowestOneBit(index);
		}
	}

	// Returns the sum of everything upto index.
	public long sum(int index) {
		long ans = 0;
		while (index > 0) {
			ans += cumfreq[index];
			index -= (Integer.lowestOneBit(index));
		}
		return ans;
	}

	// Use 1 based indexing.
	public long sum(int low, int high) {
		return sum(high) - sum(low-1);
	}

	// Return the total number of items in the BIT.
	public long all() {
		return sum(cumfreq.length-1);
	}
}