#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
struct line {
  int A, B, C;
  line() {}
  line(int a, int b, int c) { A = a, B = b, C = c; }
};
struct circle {
  int x, y, r;
} cir[2222];
struct segment {
  int x0, y0, x1, y1;
} seg[333333];
bool operator<(const line &a, const line &b) {
  if (a.A != b.A) return a.A < b.A;
  if (a.B != b.B) return a.B < b.B;
  return a.C < b.C;
}
inline int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
line get_norm(int x, int y, int z) {
  int d = gcd(gcd(abs(x), abs(y)), abs(z));
  x /= d, y /= d, z /= d;
  if (x < 0)
    x = -x, y = -y, z = -z;
  else if (x == 0)
    if (y < 0) y = -y, z = -z;
  return line(x, y, z);
}
map<line, int> line_ID;
vector<pair<int, int> > _left[333333], _right[333333];
int n, m, sz, cnt[333333];
long long ans;
void _out(line x) { cout << x.A << ' ' << x.B << ' ' << x.C << endl; }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", &seg[i].x0, &seg[i].y0, &seg[i].x1, &seg[i].y1);
    if (seg[i].x0 == seg[i].x1 && seg[i].y0 == seg[i].y1) continue;
    if (make_pair(seg[i].x0, seg[i].y0) > make_pair(seg[i].x1, seg[i].y1))
      swap(seg[i].x0, seg[i].x1), swap(seg[i].y0, seg[i].y1);
  }
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &cir[i].x, &cir[i].y, &cir[i].r);
  for (int i = 1; i <= n; i++) {
    line temp = get_norm(seg[i].y0 - seg[i].y1, seg[i].x1 - seg[i].x0,
                         seg[i].x0 * seg[i].y1 - seg[i].x1 * seg[i].y0);
    if (!line_ID.count(temp)) line_ID[temp] = ++sz;
    int id = line_ID[temp];
    _left[id].push_back(make_pair(2 * seg[i].x0, 2 * seg[i].y0));
    _right[id].push_back(make_pair(2 * seg[i].x1, 2 * seg[i].y1));
    cnt[id]++;
  }
  for (int i = 1; i <= sz; i++) {
    sort(_left[i].begin(), _left[i].end());
    sort(_right[i].begin(), _right[i].end());
  }
  for (int i = 1; i <= m; i++)
    for (int j = i + 1; j <= m; j++)
      if (cir[i].r == cir[j].r &&
          (cir[i].x - cir[j].x) * (cir[i].x - cir[j].x) +
                  (cir[i].y - cir[j].y) * (cir[i].y - cir[j].y) >
              4 * cir[i].r * cir[i].r) {
        int midx = (cir[i].x + cir[j].x), midy = (cir[i].y + cir[j].y);
        int x0 = cir[i].x, x1 = cir[j].x, y0 = cir[i].y, y1 = cir[j].y;
        line temp = get_norm(2 * (x1 - x0), 2 * (y1 - y0),
                             midx * (x0 - x1) + midy * (y0 - y1));
        if (!line_ID.count(temp)) continue;
        int id = line_ID[temp];
        int res = cnt[id];
        res -=
            (_left[id].end() - upper_bound(_left[id].begin(), _left[id].end(),
                                           make_pair(midx, midy)));
        vector<pair<int, int> >::iterator it = lower_bound(
            _right[id].begin(), _right[id].end(), make_pair(midx, midy));
        if (it != _right[id].begin()) res -= (it - _right[id].begin());
        ans += res;
      }
  cout << ans << endl;
}
