#include <bits/stdc++.h>
using namespace std;
int bj(double a, double b);
double dis(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
struct Tdouble {
  double v;
  Tdouble() {}
  Tdouble(double _v) { v = _v; }
  friend bool operator<(Tdouble a, Tdouble b) { return a.v < b.v - 1e-9; }
  friend bool operator==(Tdouble a, Tdouble b) {
    if (a.v < b.v || b.v < a.v) return 0;
    return 1;
  }
};
struct Point {
  double x, y;
  int kind;
  Point() {}
  Point(double _x, double _y, int _kind) { x = _x, y = _y, kind = _kind; }
  friend bool operator<(Point a, Point b) {
    if (bj(a.x, b.x) == -1 || (bj(a.x, b.x) == 0 && bj(a.y, b.y) == -1) ||
        (bj(a.x, b.x) == 0 && bj(a.y, b.y) == 0 && a.kind < b.kind))
      return 1;
    return 0;
  }
} pp[2000005], pp1, pp2;
struct Segment {
  double x1, y1, x2, y2;
  Tdouble xl, f0;
  void read() {
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    if (x2 > x1 + 1e-9 || x1 > x2 + 1e-9) {
      xl = (Tdouble)((y2 - y1) / (x2 - x1));
      f0 = (Tdouble)(y1 - x1 * xl.v);
    } else {
      xl = (Tdouble)1e100;
      f0 = (Tdouble)x1;
    }
  }
  friend bool operator<(Segment a, Segment b) {
    if (a.xl < b.xl || (a.xl == b.xl && a.f0 < b.f0)) return 1;
    return 0;
  }
} seg[300005], line[1300005], lNow;
struct Circle {
  double x, y, r;
  void read() { scanf("%lf %lf %lf", &x, &y, &r); }
} cir[1505];
int n, m, i, j, k, Now, tot, ptot;
double xl, xnow, ynow;
long long Ans, s;
int main() {
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) seg[i].read();
  for (i = 1; i <= m; i++) cir[i].read();
  for (i = 1; i < m; i++)
    for (j = i + 1; j <= m; j++) {
      if (bj(cir[i].r, cir[j].r) != 0) continue;
      if (bj(cir[i].r + cir[i].r,
             dis(cir[i].x, cir[i].y, cir[j].x, cir[j].y)) >= 0)
        continue;
      xnow = (cir[i].x + cir[j].x) * 0.5;
      ynow = (cir[i].y + cir[j].y) * 0.5;
      if (bj(cir[i].y, cir[j].y) == 0)
        lNow.xl = (Tdouble)1e100, lNow.f0 = (Tdouble)xnow;
      else if (bj(cir[i].x, cir[j].x) == 0)
        lNow.xl = (Tdouble)0, lNow.f0 = (Tdouble)ynow;
      else {
        lNow.xl =
            (Tdouble)(-1.0 / ((cir[i].y - cir[j].y) / (cir[i].x - cir[j].x)));
        lNow.f0 = (Tdouble)(ynow - xnow * lNow.xl.v);
      }
      lNow.x1 = xnow, lNow.y1 = ynow;
      line[++tot] = lNow;
    }
  sort(line + 1, line + tot + 1);
  sort(seg + 1, seg + n + 1);
  Now = 1;
  for (i = 1; i <= tot; i++) {
    for (j = i + 1; j <= tot; j++)
      if (line[i] < line[j]) break;
    j--;
    ptot = 0;
    for (k = i; k <= j; k++) pp[++ptot] = Point(line[k].x1, line[k].y1, 0);
    while (seg[Now] < line[i] && Now <= n) Now++;
    while (1) {
      if (line[i] < seg[Now] || Now > n) break;
      pp1 = Point(seg[Now].x1, seg[Now].y1, 0);
      pp2 = Point(seg[Now].x2, seg[Now].y2, 0);
      pp[++ptot] = min(pp1, pp2);
      pp[++ptot] = max(pp1, pp2);
      pp[ptot - 1].kind = -1;
      pp[ptot].kind = 1;
      Now++;
    }
    sort(pp + 1, pp + ptot + 1);
    s = 0;
    for (k = 1; k <= ptot; k++) {
      if (pp[k].kind == 0)
        s++;
      else if (pp[k].kind == -1)
        Ans -= s;
      else
        Ans += s;
    }
    i = j;
  }
  printf("%I64d\n", Ans);
  return 0;
}
int bj(double a, double b) {
  if (a - b > 0 - 1e-9 && a - b < 1e-9) return 0;
  if (a < b) return -1;
  return 1;
}
