import java.util.*;
public class xiaowuc1 {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    int t = sc.nextInt();
    for(int cn = 0; cn < t; cn++) {
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] x = new int[n];
      int[] y = new int[n];
      for(int i = 0; i < n; i++) {
        x[i] = sc.nextInt();
        y[i] = sc.nextInt();
      }
      boolean[] bad = new boolean[n];
      Integer[] ord = new Integer[n];
      for(int i = 0; i < n; i++) ord[i] = i;
      for(int q = 0; q < 2; q++) {
        Arrays.sort(ord, (a, b) -> {
          if(x[a] != x[b]) return x[b] - x[a];
          if(y[a] != y[b]) return y[b] - y[a];
          return 0;
        });
        int maxseen = -1;
        int lhs = 0;
        for(int i = 0; i < n; i++) {
          while(lhs < i && x[ord[lhs]] >= x[ord[i]] + k) {
            maxseen = Math.max(maxseen, y[ord[lhs++]]);
          }
          if(maxseen >= y[ord[i]]) bad[ord[i]] = true;
        }
        for(int i = 0; i < n; i++) {
          x[i] ^= y[i];
          y[i] ^= x[i];
          x[i] ^= y[i];
        }
      }
      int[] ret = new int[n];
      int sz = 0;
      for(int i = 0; i < n; i++) if(!bad[i]) ret[sz++] = i+1;
      System.out.println(sz);
      for(int i = 0; i < sz; i++) {
        if(i > 0) System.out.print(' ');
        System.out.print(ret[i]);
      }
      System.out.println();
    }
  }
}
