/* Problem URL: https://codeforces.com/gym/105316/problem/I */

#include <bits/stdc++.h>

using namespace std;

#define V vector

#define rmin(a, b) a = min(a, b)
#define rmax(a, b) a = max(a, b)

#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)

#define repv(i, v) for (auto &i : (v))
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
#define sortv(v) sort(v.begin(), v.end())
#define all(v) (v).begin(), (v).end()

using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;

using ll = long long;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vvvvl = vector<vvvl>;

template<class v>
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
    os << vec[0];
    for (size_t i = 1; i < vec.size(); i++) {
        os << ' ' << vec[i];
    }
    os << '\n';
    return os;
}

template<class v>
auto operator>>(istream &is, vector<v> &vec)->istream& {
    for (auto &i : vec) {
        is >> i;
    }
    return is;
}

template<class v>
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
    for (auto &i : vec) {
        os << i[0];
        for (size_t j = 1; j < i.size(); j++) {
            os << ' ' << i[j];
        }
        os << '\n';
    }
    return os;
}

template<class v>
auto operator>>(istream  &is, vector<vector<v>> &vec)->istream& {
    for (auto &i : vec) {
        for (auto &j : i) {
            is >> j;
        }
    }
    return is;
}

double dis(ll x1, ll y1, ll x2, ll y2)
{
    ll x = x1 - x2;
    ll y = y1 - y2;
    return sqrt(x * x + y * y);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n, q;
        cin >> n >> q;

        V<pair<int, int>> points;

        while (n--) {
            int x, y, z;
            cin >> x >> y >> z;

            for (size_t i = 0; i <= z; i++) {
                int yn = y + i;
                int xn = x;
                while (dis(xn, yn, x, y) <= z) {
                    points.emplace_back(xn, yn);
                    int dx = xn - x;
                    int dy = yn - y;
                    if (dy != 0) {
                        points.emplace_back(xn, y - dy);
                    }
                    if (dx != 0) {
                        points.emplace_back(x - dx, yn);
                    }
                    if (dx != 0 && dy != 0) {
                        points.emplace_back(x - dx, y - dy);
                    }
                    xn++;
                }
            }
        }

        sortv(points);
        pair<int, int> prev = {-1e6, -1e6};
        int now = 1;

        V<pair<int, int>> act;
        vi count;

        for (auto i : points) {
            if (i == prev) {
                now++;
                continue;
            }

            act.emplace_back(prev);
            count.push_back(now);
            now = 1;
            prev = i;
        }

        act.emplace_back(prev);
        count.push_back(now);

        while (q--) {
            int x, y;
            cin >> x >> y;

            auto itr = lower_bound(act.begin(), act.end(), make_pair(x, y));
            if (itr == act.end() || *itr != make_pair(x, y)) {
                cout << "0\n";
                continue;
            }

            cout << count[itr - act.begin()] << '\n';
        }
    }
}
