#include <bits/stdc++.h>
using namespace std;
struct line {
  int A, B, C;
  line() { A = 0, B = 0, C = 0; }
  line(int a, int b, int c) { A = a, B = b, C = c; }
  bool operator<(line const& ln) const {
    if (A != ln.A) return A < ln.A;
    if (B != ln.B) return B < ln.B;
    return C < ln.C;
  }
};
const int MAXN = 10005;
const int MAXM = 1505;
int N, M;
int sz = 0;
map<line, int> mp;
vector<pair<int, int> > S[MAXN];
vector<pair<int, int> > F[MAXN];
int C[MAXM][3];
int gcd(int m, int n) {
  if (m % n == 0) return n;
  return gcd(n, m % n);
}
line make_line(int a, int b, int c) {
  if (a < 0 || (a == 0 && b < 0)) a *= -1, b *= -1, c *= -1;
  int g;
  if (a == 0)
    g = abs(b);
  else
    g = abs(a);
  if (b != 0) g = gcd(g, abs(b));
  if (c != 0) g = gcd(g, abs(c));
  a /= g, b /= g, c /= g;
  return line(a, b, c);
}
int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2 || (x1 == x2 && y1 > y2)) {
      swap(x1, x2);
      swap(y1, y2);
    }
    x1 *= 2, y1 *= 2, x2 *= 2, y2 *= 2;
    line ln = make_line(y2 - y1, x1 - x2, (y2 - y1) * x1 - (x2 - x1) * y1);
    int idx = -1;
    if (mp.count(ln) == 0) mp[ln] = sz++;
    idx = mp[ln];
    S[idx].push_back(make_pair(x1, y1));
    F[idx].push_back(make_pair(x2, y2));
  }
  for (int i = 0; i < sz; i++) {
    sort(S[i].begin(), S[i].end());
    sort(F[i].begin(), F[i].end());
  }
  for (int i = 0; i < M; i++) cin >> C[i][0] >> C[i][1] >> C[i][2];
  long long total = 0;
  for (int i = 0; i < M; i++)
    for (int j = i + 1; j < M; j++) {
      int x1 = C[i][0], y1 = C[i][1], x2 = C[j][0], y2 = C[j][1];
      if (C[i][2] != C[j][2]) continue;
      if ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) <=
          4 * C[i][2] * C[i][2])
        continue;
      line ln =
          make_line(x1 - x2, y1 - y2, x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2);
      if (mp.count(ln) == 0) continue;
      int idx = mp[ln];
      pair<int, int> key = make_pair(x1 + x2, y1 + y2);
      int cnt = S[idx].size();
      cnt -= (S[idx].end() - upper_bound(S[idx].begin(), S[idx].end(), key));
      cnt -= (lower_bound(F[idx].begin(), F[idx].end(), key) - F[idx].begin());
      total += cnt;
    }
  cout << total << "\n";
  return 0;
}
