import java.util.*;

public class birdsandbread_AN {
  static class Source {
    long x;
    long y;
    long t;

    public Source(long x, long y, long t) {
      this.x = x;
      this.y = y;
      this.t = t;
    }
  }

  static class Pair implements Comparable<Pair> {
    Source a;
    Source b;
    boolean neverIntersects;
    boolean isAlwaysTangent;
    long firstIntersectionTime;
    boolean startsTangent;

    public Pair(Source a, Source b) {
      this.a = a;
      this.b = b;
      long distsq = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
      long delta = b.t - a.t;
      neverIntersects = distsq < delta * delta;
      isAlwaysTangent = distsq == delta * delta;
      long t = (long) ((Math.sqrt(distsq) - delta) / 2);
      if (distsq > (delta + 2 * t) * (delta + 2 * t)) t++;
      firstIntersectionTime = t + b.t;
      startsTangent = distsq == (delta + 2 * t) * (delta + 2 * t);
    }

    @Override
    public int compareTo(birdsandbread_AN.Pair o) {
      return Long.compare(this.firstIntersectionTime, o.firstIntersectionTime);
    }
  }
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int T = s.nextInt();
    for (int tc = 0; tc < T; tc++) {
      int n = s.nextInt();
      int q = s.nextInt();
      int total = 0;
      PriorityQueue<Pair> future = new PriorityQueue<>();
      List<Pair> current = new ArrayList<>();
      Source[] sources = new Source[n];
      int sourceCount = 0;
      long lastT = -1;
      for (int i = 0; i < n; i++) {
        long t = s.nextLong();
        Source cur = new Source(s.nextLong(), s.nextLong(), t);
        for (int j = 0; j < sourceCount; j++) {
          Pair p = new Pair(sources[j], cur);
          if (p.neverIntersects) continue;
          future.add(p);
        }
        sources[sourceCount++] = cur;
      }
      lastT = -1;
      for(int i = 0; i < q; i++) {
        long t = s.nextLong();
        if (t != lastT) {
          total += current.size();
          current.clear();
          while (!future.isEmpty() && future.peek().firstIntersectionTime <= t) {
            Pair p = future.poll();
            if (p.isAlwaysTangent) {
              total++;
            } else if (p.firstIntersectionTime == t && p.startsTangent) {
              total++;
              current.add(p);
            } else {
              total += 2;
            }
          }
        }
        System.out.println(total);
      }
    }
  }
}
