// Josh Linge
// 2/21/2017
// Solution to 2017 FHSPS Playoff Question: Average

import java.util.Scanner;

public class average_linge {

  public static void main(String[] args) {
  	
    Scanner in = new Scanner(System.in);
    int t = in.nextInt();
    
    // Process all cases.
    while(t --> 0) {
      int n = in.nextInt();
      int a = in.nextInt();
      
      // Get input values.
      int[] vals = new int[n];
      long count = 0;
      for(int i = 0; i < n; ++i) {
        vals[i] = in.nextInt();
      }
      
      // Set up the binary index tree.
      int mid = n*10;
      BIT bit = new BIT(mid*2+1);
      bit.update(mid+1, 1);
      int sum = 0;
      
      // Run through the values.
      for(int val : vals) {
      	
      	// Update sum adjusted by average.
        sum += val - a;
        
        // This is what we want to add, for intervals ending at this value.
        count += bit.read(bit.n) - bit.read(mid - sum);
        
        // Now, update our BIT.
        bit.update(mid - sum + 1, 1);
      }
      
      // Here is our result.
      System.out.println(count);
    }
    
    in.close();
  }

  // BIT class just with the methods needed for this problem.
  static class BIT {
    int n;
    int[] tree;
    
    public BIT(int n) {
      this.n = n;
      tree = new int[n + 1];
    }
    
    int read(int index) {
      int sum = 0;
      while (index > 0) {
        sum = (sum + tree[index]);
        index -= (index & -index);
      }
      return sum;
    }
    
    void update(int index, int val) {
      while (index <= n) {
        tree[index] = (tree[index] + val);
        index += (index & -index);
      }
    }
  }
}
