#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct Point {
  int x, y;
};
struct Line {
  int A, B, C;
  Line(int a = 0, int b = 1, int c = 0) : A(a), B(b), C(c) {
    int g = gcd(gcd(abs(A), abs(B)), abs(C));
    A /= g;
    B /= g;
    C /= g;
    if (A < 0 || (A == 0 || B < 0)) {
      A = -A;
      B = -B;
      C = -C;
    }
  }
};
Line getLine(const Point &a, const Point &b) {
  int dx = b.x - a.x;
  int dy = -(b.y - a.y);
  return Line(dy, dx, dy * a.x + dx * a.y);
}
Line perpLine(const Line &li, const Point &p) {
  int a = -li.B, b = li.A;
  return Line(a, b, p.x * a + p.y * b);
}
bool operator<(const Line &g, const Line &h) {
  if (g.A != h.A) return g.A < h.A;
  if (g.B != h.B) return g.B < h.B;
  return g.C < h.C;
}
const int maxN = 1024;
int N, K;
map<int, vector<Point>> circ;
map<Line, map<int, int>> segs;
int main() {
  cin >> N >> K;
  for (int i = (0); i < (N); i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Point a{x1 * 2, y1 * 2};
    Point b{x2 * 2, y2 * 2};
    Line li = getLine(a, b);
    {
      if (0) fprintf(stderr, "li: a %d, b %d, c %d\n", li.A, li.B, li.C);
    };
    int pa = a.x * li.B - a.y * li.A;
    int push_back = b.x * li.B - b.y * li.A;
    if (pa > push_back) swap(pa, push_back);
    segs[li][pa + 0]++;
    segs[li][push_back + 1]--;
  }
  for (int i = (0); i < (K); i++) {
    int x, y, r;
    cin >> x >> y >> r;
    circ[r * 2].push_back(Point{x * 2, y * 2});
  }
  for (auto &s : segs) {
    s.second[INT_MIN / 2] = 0;
    s.second[INT_MAX / 2] = 0;
    {
      if (0) fprintf(stderr, "seg\n");
    };
    int prev = 0;
    for (auto &e : s.second) {
      {
        if (0) fprintf(stderr, "%d: %d\n", e.first, e.second);
      };
      e.second = (prev += e.second);
      {
        if (0) fprintf(stderr, "    %d\n", prev);
      };
    }
  }
  int res = 0;
  for (const auto &ci : circ) {
    for (int ia = (0); ia < (int((ci.second).size())); ia++) {
      for (int ib = (ia + 1); ib < (int((ci.second).size())); ib++) {
        Point a = ci.second[ia];
        Point b = ci.second[ib];
        Point d{b.x - a.x, b.y - a.y};
        if (d.x * d.x + d.y * d.y <= ci.first * ci.first * 4) continue;
        Point m{a.x + d.x / 2, a.y + d.y / 2};
        {
          if (0) fprintf(stderr, "M: %d %d\n", m.x, m.y);
        };
        Line li = perpLine(getLine(a, b), m);
        {
          if (0) fprintf(stderr, "li: a %d, b %d, c %d\n", li.A, li.B, li.C);
        };
        if (!((segs).find(li) != (segs).end())) continue;
        int pp = m.x * li.B - m.y * li.A;
        {
          if (0) cerr << "DBGDO: " << ("pp") << " = " << (pp) << endl;
        };
        auto it = segs[li].upper_bound(pp);
        assert(it != segs[li].begin());
        it--;
        res += it->second;
      }
    }
  }
  cout << res << endl;
}
