#include <bits/stdc++.h>
using namespace std;
const int N = 300030;
const double eps = 1e-8;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
struct Point {
  int x, y;
  Point() {}
  Point(int x, int y) : x(x), y(y) {}
  void input() { scanf("%d%d", &x, &y); }
  Point operator-(const Point &rhs) const {
    return Point(x - rhs.x, y - rhs.y);
  }
  double arg() { return atan2(y, x); }
  bool operator<(const Point &rhs) const {
    if (x != rhs.x) return x < rhs.x;
    return y < rhs.y;
  }
  void gao() {
    if (y < 0 || (y == 0 && x < 0)) y = -y, x = -x;
    int d = gcd(x, y);
    x /= d;
    y /= d;
  }
  void rev() {
    int t = x;
    x = -y;
    y = t;
  }
  int len() { return x * x + y * y; }
};
struct Line {
  double b, x;
  int t;
  Line() {}
  Line(double b, double x, int t) : b(b), x(x), t(t) {}
  bool operator<(const Line &rhs) const {
    if (fabs(b - rhs.b) > eps) return b < rhs.b;
    if (fabs(x - rhs.x) > eps) return x < rhs.x;
    return t > rhs.t;
  }
} L[N];
struct Circle {
  Point o;
  int r;
} C[2000];
int n, m;
vector<Line> G[N];
vector<pair<double, double> > V[N];
map<Point, int> M;
int main() {
  Point u, v, k;
  double b;
  int cnt = 0, t;
  while (~scanf("%d%d", &n, &m)) {
    M.clear();
    for (int i = 0; i <= cnt; i++) {
      G[i].clear();
      V[i].clear();
    }
    cnt = 0;
    for (int i = 0; i < n; i++) {
      u.input();
      v.input();
      k = u - v;
      if (k.x == 0)
        b = u.x;
      else
        b = u.y - ((double)u.x / k.x) * k.y;
      k.gao();
      t = M[k];
      if (!t) M[k] = t = ++cnt;
      if (k.x != 0) {
        G[t].push_back(Line(b, min(u.x, v.x), 1));
        G[t].push_back(Line(b, max(u.x, v.x), -1));
      } else {
        G[t].push_back(Line(b, min(u.y, v.y), 1));
        G[t].push_back(Line(b, max(u.y, v.y), -1));
      }
    }
    for (int i = 0; i < m; i++) {
      C[i].o.input();
      scanf("%d", &C[i].r);
    }
    long long ans = 0;
    map<Point, int>::iterator it;
    for (int i = 0; i < m; i++) {
      for (int j = i + 1; j < m; j++)
        if (C[i].r == C[j].r) {
          u = C[i].o - C[j].o;
          if (u.len() <= 4 * C[i].r * C[i].r) continue;
          u.rev();
          u.gao();
          it = M.find(u);
          if (it == M.end()) continue;
          int t = it->second;
          double x, y, b;
          x = (double)(C[i].o.x + C[j].o.x) / 2;
          y = (double)(C[i].o.y + C[j].o.y) / 2;
          if (u.x == 0) {
            b = x;
            V[t].push_back(make_pair(b, y));
          } else {
            b = y - (x / u.x) * u.y;
            V[t].push_back(make_pair(b, x));
          }
        }
    }
    for (int i = 1; i <= cnt; i++) {
      sort(G[i].begin(), G[i].end());
      sort(V[i].begin(), V[i].end());
      int tmp = 0;
      for (int j = 0, k = 0; j < V[i].size(); j++) {
        while (k < G[i].size()) {
          if (G[i][k].b > V[i][j].first + eps) break;
          if (G[i][k].b < V[i][j].first - eps) {
            tmp += G[i][k].t;
            k++;
            continue;
          }
          if (G[i][k].x > V[i][j].second + eps) break;
          if (G[i][k].x < V[i][j].second - eps) {
            tmp += G[i][k].t;
            k++;
            continue;
          }
          if (G[i][k].t < 0) break;
          tmp++;
          k++;
        }
        ans += tmp;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
