#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
  return a = min(a, b);
}
template <class T>
T &chmax(T &a, const T &b) {
  return a = max(a, b);
}
struct qu {
  long long int a, b;
  qu() {}
  qu(long long int aa, long long int ab) {
    if (ab < 0) aa *= -1, ab *= -1;
    a = aa;
    b = ab;
  }
  const bool operator==(const qu &x) const { return a * x.b == b * x.a; }
  const bool operator<(const qu &x) const { return a * x.b < b * x.a; }
};
const long long int MAX_N = 300010;
inline long long int sq(long long int x) { return x * x; }
vector<pair<pair<qu, qu>, qu> > ms;
long long int n, m;
long long int xa[MAX_N], ya[MAX_N], xb[MAX_N], yb[MAX_N];
long long int cx[MAX_N], cy[MAX_N], r[MAX_N];
long long int ans = 0;
int main() {
  scanf("%lld %lld", &n, &m);
  for (long long int i = (0); i < (long long int)(n); i++)
    scanf("%lld %lld %lld %lld", &xa[i], &ya[i], &xb[i], &yb[i]);
  for (long long int i = (0); i < (long long int)(m); i++)
    scanf("%lld %lld %lld", &cx[i], &cy[i], &r[i]);
  for (long long int i = (0); i < (long long int)(m); i++)
    for (long long int j = (0); j < (long long int)(i); j++)
      if (r[i] == r[j] &&
          sq(cx[i] - cx[j]) + sq(cy[i] - cy[j]) > sq(r[i] + r[j])) {
        if (cy[i] != cy[j])
          ms.emplace_back(
              pair<qu, qu>(qu(cx[j] - cx[i], cy[i] - cy[j]),
                           qu(sq(cx[i]) - sq(cx[j]) + sq(cy[i]) - sq(cy[j]),
                              2 * (cy[i] - cy[j]))),
              qu(cx[i] + cx[j], 2));
        else
          ms.emplace_back(pair<qu, qu>(qu(1, 0), qu(cx[i] + cx[j], 2)),
                          qu(cy[i], 1));
      }
  sort((ms).begin(), (ms).end());
  for (long long int i = (0); i < (long long int)(n); i++) {
    if (xa[i] != xb[i]) {
      pair<qu, qu> line =
          pair<qu, qu>(qu(ya[i] - yb[i], xa[i] - xb[i]),
                       qu(xa[i] * yb[i] - xb[i] * ya[i], xa[i] - xb[i]));
      ans +=
          upper_bound((ms).begin(), (ms).end(),
                      pair<pair<qu, qu>, qu>(line, qu(max(xa[i], xb[i]), 1))) -
          lower_bound((ms).begin(), (ms).end(),
                      pair<pair<qu, qu>, qu>(line, qu(min(xa[i], xb[i]), 1)));
    } else {
      pair<qu, qu> line = pair<qu, qu>(qu(1, 0), qu(xa[i], 1));
      ans +=
          upper_bound((ms).begin(), (ms).end(),
                      pair<pair<qu, qu>, qu>(line, qu(max(ya[i], yb[i]), 1))) -
          lower_bound((ms).begin(), (ms).end(),
                      pair<pair<qu, qu>, qu>(line, qu(min(ya[i], yb[i]), 1)));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
