#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

using namespace std;

void solve() {
  int n, q;
  cin >> n >> q;
  vector<int64_t> timev;
  vector<array<int, 3>> pts; // <x, y, t>
  while(n--) {
    int t, x, y;
    cin >> t >> x >> y;
    for(auto [nx, ny, nt]: pts) {
      int64_t a = x - nx;
      int64_t b = y - ny;
      int64_t deltat = t-nt;
      if(a*a+b*b == deltat*deltat) {
        timev.push_back(t);
        continue;
      }
      if(a*a+b*b < deltat*deltat) {
        continue;
      }
      int64_t lhs = t;
      int64_t rhs = 1.01e9;
      while(lhs < rhs) {
        int64_t mid = (lhs+rhs)/2;
        int64_t d = 2*mid - t - nt;
        if(d*d >= a*a+b*b) rhs = mid;
        else lhs = mid+1;
      }
      int64_t d = 2*lhs - t - nt;
      if(d*d == a*a+b*b) {
        timev.push_back(lhs);
        timev.push_back(lhs+1);
      }
      else {
        timev.push_back(lhs);
        timev.push_back(lhs);
      }
    }
    pts.push_back({x, y, t});
  }
  sort(timev.begin(), timev.end());
  int ret = 0;
  while(q--) {
    int t;
    cin >> t;
    while(ret < timev.size() && timev[ret] <= t) ret++;
    cout << ret << "\n";
  }
}

int main() {
  int t;
  cin >> t;
  while(t--) solve();
}
