#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const int MN = 3e5 + 10;
struct line {
  int x1, y1, m1, m2, id;
  line(int a, int b, int c, int d) { x1 = a, y1 = b, m1 = c, m2 = d; }
  line() {}
} ln[MN], cir[1500 * 1500 + 10];
int sz;
int xc[1500 + 10], yc[1500 + 10], rc[1500 + 10];
int ans;
int n, m;
pair<int, int> my[MN];
int cmp1(const line &a, const line &b) {
  if (min(a.m2, b.m2) == 0) {
    if (a.m2 != b.m2) {
      if (a.m2 == 0)
        return 3;
      else
        return 1;
    }
    if (a.x1 < b.x1) return 1;
    if (a.x1 == b.x1) return 2;
    return 3;
  }
  if (1ll * a.m1 * b.m2 != 1ll * b.m1 * a.m2) {
    if (1ll * a.m1 * b.m2 < 1ll * b.m1 * a.m2) return 1;
    return 3;
  }
  if (1ll * a.m2 * b.m2 * a.y1 - 1ll * b.m2 * a.m1 * a.x1 !=
      1ll * a.m2 * b.m2 * b.y1 - 1ll * a.m2 * b.m1 * b.x1) {
    if (1ll * a.m2 * b.m2 * a.y1 - 1ll * b.m2 * a.m1 * a.x1 <
        1ll * a.m2 * b.m2 * b.y1 - 1ll * a.m2 * b.m1 * b.x1)
      return 1;
    return 3;
  }
  return 2;
}
bool cmp(const line &a, const line &b) {
  if (cmp1(a, b) < 2) return true;
  return false;
}
void input() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    a *= 2, b *= 2, c *= 2, d *= 2;
    my[i] = make_pair(a, c);
    if (my[i].first > my[i].second) swap(my[i].first, my[i].second);
    ln[i] = line(a, b, b - d, a - c);
    ln[i].id = i;
    if (ln[i].m2 < 0) ln[i].m2 *= -1, ln[i].m1 *= -1;
  }
  sort(ln, ln + n, cmp);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &xc[i], &yc[i], &rc[i]);
    xc[i] *= 2, yc[i] *= 2, rc[i] *= 2;
  }
  for (int i = 0; i < m; ++i)
    for (int j = i + 1; j < m; ++j) {
      if (1ll * (rc[i] + rc[j]) * (rc[i] + rc[j]) <
              1ll * (xc[i] - xc[j]) * (xc[i] - xc[j]) +
                  1ll * (yc[i] - yc[j]) * (yc[i] - yc[j]) &&
          rc[i] == rc[j]) {
        cir[sz++] = line((xc[i] + xc[j]) / 2, (yc[i] + yc[j]) / 2,
                         xc[j] - xc[i], yc[i] - yc[j]);
        if (cir[sz - 1].m2 < 0) cir[sz - 1].m2 *= -1, cir[sz - 1].m1 *= -1;
      }
    }
  sort(cir, cir + sz, cmp);
}
void solve() {
  int p = 0;
  vector<int> tmp1, tmp2;
  bool fl = false;
  for (int i = 0; i < sz; ++i) {
    while (p < n && cmp1(cir[i], ln[p]) == 3) ++p;
    while (p < n && cmp1(cir[i], ln[p]) == 2) {
      tmp1.push_back(my[ln[p].id].first);
      tmp2.push_back(my[ln[p].id].second);
      ++p;
    }
    if (!fl)
      sort(tmp1.begin(), tmp1.end()), sort(tmp2.begin(), tmp2.end()), fl = true;
    ans += (upper_bound(tmp1.begin(), tmp1.end(), cir[i].x1) - tmp1.begin()) -
           (lower_bound(tmp2.begin(), tmp2.end(), cir[i].x1) - tmp2.begin());
    if (i != sz - 1 && cmp1(cir[i], cir[i + 1]) != 2)
      tmp1.clear(), tmp2.clear(), fl = false;
  }
}
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  input();
  solve();
  printf("%d\n", ans);
  return 0;
}
