#include <bits/stdc++.h>
long long loo(long long a, long long b) { return a * a + b * b; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
using namespace std;
map<long long, int> stx;
map<long long, int> sty;
map<long long, int> idx;
int ids = 0;
int *cts;
long long **vl1;
long long **vl2;
long long *vlt1;
long long *vlt2;
int exists(long long hsh) { return idx.find(hsh) != idx.end(); }
void add(long long hsh, int sx, int sy) {
  stx[hsh] = sx;
  sty[hsh] = sy;
  idx[hsh] = ids++;
}
long long gettime(long long hsh, int dx, int dy, int x, int y) {
  int sx = stx[hsh];
  int sy = sty[hsh];
  if (dx) {
    return (x - sx) / dx;
  } else {
    return (y - sy) / dy;
  }
}
long long floor(long long a, long long b) {
  if (b < 0) {
    a = -a;
    b = -b;
  }
  if (a < 0) {
    return -(((-a) + b - 1) / b);
  }
  return a / b;
}
long long hush(long long dx, long long dy, long long x, long long y) {
  if (dx == 0) {
    y = 0;
  } else if (dy == 0) {
    x = 0;
  } else {
    long long t = floor(x, dx);
    x -= dx * t;
    y -= dy * t;
  }
  long long hsh = dx;
  hsh <<= 16;
  hsh += dy;
  hsh <<= 16;
  hsh += x;
  hsh <<= 16;
  hsh += y;
  return hsh;
}
int smaller_than_gt_count(long long *vl, int ct, long long t) {
  if (!ct) return 0;
  if (vl[0] >= t) return 0;
  int L = 0, R = ct;
  while (R - L > 1) {
    int M = L + R >> 1;
    (vl[M] >= t ? R : L) = M;
  }
  return R;
}
int bigger_than_gt_count(long long *vl, int ct, long long t) {
  if (!ct) return 0;
  if (vl[ct - 1] <= t) return 0;
  int L = -1, R = ct - 1;
  while (R - L > 1) {
    int M = L + R >> 1;
    (vl[M] <= t ? L : R) = M;
  }
  return ct - R;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int *x1 = ((int *)malloc((n) * sizeof(int)));
  int *y1 = ((int *)malloc((n) * sizeof(int)));
  int *x2 = ((int *)malloc((n) * sizeof(int)));
  int *y2 = ((int *)malloc((n) * sizeof(int)));
  int *xi = ((int *)malloc((m) * sizeof(int)));
  int *yi = ((int *)malloc((m) * sizeof(int)));
  int *ri = ((int *)malloc((m) * sizeof(int)));
  for (int i = (0); i < (n); i++) {
    long long X1, Y1, X2, Y2;
    scanf("%I64d%I64d%I64d%I64d", &X1, &Y1, &X2, &Y2);
    if ((X1 < -1111111 || X1 > 1111111) || (Y1 < -1111111 || Y1 > 1111111) ||
        (X2 < -1111111 || X2 > 1111111) || (Y2 < -1111111 || Y2 > 1111111)) {
      i--;
      n--;
      continue;
    }
    X1 <<= 1;
    Y1 <<= 1;
    X2 <<= 1;
    Y2 <<= 1;
    x1[i] = X1;
    y1[i] = Y1;
    x2[i] = X2;
    y2[i] = Y2;
    int dx = x2[i] - x1[i];
    int dy = y2[i] - y1[i];
    do {
      int g = gcd(dx, dy);
      dx /= g;
      dy /= g;
      if (dy < 0) {
        dx = -dx;
        dy = -dy;
      }
    } while (0);
    long long hsh = hush(dx, dy, x1[i], y1[i]);
    if (!exists(hsh)) add(hsh, x1[i], y1[i]);
  }
  cts = ((int *)malloc((ids) * sizeof(int)));
  for (int i = (0); i < (ids); i++) cts[i] = 0;
  for (int i = (0); i < (n); i++) {
    int dx = x2[i] - x1[i];
    int dy = y2[i] - y1[i];
    do {
      int g = gcd(dx, dy);
      dx /= g;
      dy /= g;
      if (dy < 0) {
        dx = -dx;
        dy = -dy;
      }
    } while (0);
    long long hsh = hush(dx, dy, x1[i], y1[i]);
    int ind = idx[hsh];
    cts[ind]++;
  }
  long long *vlo1 = vlt1 = ((long long *)malloc((n) * sizeof(long long)));
  long long *vlo2 = vlt2 = ((long long *)malloc((n) * sizeof(long long)));
  vl1 = ((long long **)malloc((ids) * sizeof(long long *)));
  vl2 = ((long long **)malloc((ids) * sizeof(long long *)));
  for (int i = (0); i < (ids); i++) {
    vl1[i] = vlo1;
    vl2[i] = vlo2;
    vlo1 += cts[i];
    vlo2 += cts[i];
    cts[i] = 0;
  }
  for (int i = (0); i < (n); i++) {
    int dx = x2[i] - x1[i];
    int dy = y2[i] - y1[i];
    do {
      int g = gcd(dx, dy);
      dx /= g;
      dy /= g;
      if (dy < 0) {
        dx = -dx;
        dy = -dy;
      }
    } while (0);
    long long hsh = hush(dx, dy, x1[i], y1[i]);
    long long gt1 = gettime(hsh, dx, dy, x1[i], y1[i]);
    long long gt2 = gettime(hsh, dx, dy, x2[i], y2[i]);
    if (gt1 > gt2) {
      gt1 ^= gt2;
      gt2 ^= gt1;
      gt1 ^= gt2;
    }
    int ind = idx[hsh];
    vl1[ind][cts[ind]] = gt1;
    vl2[ind][cts[ind]] = gt2;
    cts[ind]++;
  }
  for (int i = (0); i < (ids); i++) {
    sort(vl1[i], vl1[i] + cts[i]);
    sort(vl2[i], vl2[i] + cts[i]);
  }
  long long ans = 0;
  for (int i = (0); i < (m); i++) {
    scanf("%d%d%d", xi + i, yi + i, ri + i);
    long long X = xi[i], Y = yi[i], R = ri[i];
    for (int j = (0); j < (i); j++) {
      long long x = xi[j], y = yi[j], r = ri[j];
      if (R != r) continue;
      if ((r * r << 2) >= loo(X - x, Y - y)) continue;
      long long xx = X + x;
      long long yy = Y + y;
      int dx = y - Y;
      int dy = X - x;
      do {
        int g = gcd(dx, dy);
        dx /= g;
        dy /= g;
        if (dy < 0) {
          dx = -dx;
          dy = -dy;
        }
      } while (0);
      long long hsh = hush(dx, dy, xx, yy);
      if (!exists(hsh)) continue;
      int ind = idx[hsh];
      ans += cts[ind];
      long long gt = gettime(hsh, dx, dy, xx, yy);
      ans -= smaller_than_gt_count(vl2[ind], cts[ind], gt);
      ans -= bigger_than_gt_count(vl1[ind], cts[ind], gt);
    }
  }
  printf("%I64d\n", ans);
}
