#include <bits/stdc++.h>
using namespace std;
const int M = 301111;
const int N = 1555;
struct line {
  int a, b, c;
  line(int p, int q, int r) { a = p, b = q, c = r; }
};
bool operator<(line p, line q) {
  if (p.a != q.a) return p.a < q.a;
  if (p.b != q.b) return p.b < q.b;
  return p.c < q.c;
}
map<line, int> what;
int len = 0;
int many[M];
vector<pair<int, int> > down[M];
vector<pair<int, int> > up[M];
int x[N];
int y[N];
int r[N];
int gcd(int p, int q) {
  if (p < 0) p = -p;
  if (q < 0) q = -q;
  if (p == 0 || q == 0) return p + q;
  if (p > q) return gcd(p % q, q);
  return gcd(p, q % p);
}
line nom(int p, int q, int r) {
  int g = gcd(p, gcd(q, r));
  p /= g, q /= g, r /= g;
  int what = 1;
  if (p != 0) {
    what = p > 0 ? 1 : -1;
  } else
    what = q > 0 ? 1 : -1;
  p *= what;
  q *= what;
  r *= what;
  return line(p, q, r);
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    pair<int, int> p, q;
    scanf("%d%d%d%d", &p.first, &p.second, &q.first, &q.second);
    if (p > q) {
      pair<int, int> temp = p;
      p = q;
      q = temp;
    }
    int aa = p.second - q.second;
    int bb = q.first - p.first;
    int cc = -p.first * aa - p.second * bb;
    line cur = nom(aa, bb, cc);
    if (!what.count(cur)) what[cur] = len++;
    int place = what[cur];
    many[place]++;
    p.first *= 2;
    p.second *= 2;
    q.first *= 2;
    q.second *= 2;
    down[place].push_back(p);
    up[place].push_back(q);
  }
  for (int i = 0; i < len; i++) {
    sort(down[i].begin(), down[i].end());
    sort(up[i].begin(), up[i].end());
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &x[i], &y[i], &r[i]);
  }
  long long dap = 0;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (r[i] != r[j]) continue;
      if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <=
          4 * r[i] * r[j])
        continue;
      int aa = (x[i] - x[j]);
      int bb = (y[i] - y[j]);
      int cc = -(x[i] + x[j]) * aa - (y[i] + y[j]) * bb;
      aa *= 2, bb *= 2;
      line cur = nom(aa, bb, cc);
      if (!what.count(cur)) continue;
      int temp = what[cur];
      int curadd = many[temp];
      pair<int, int> t = make_pair((x[i] + x[j]), (y[i] + y[j]));
      int how = down[temp].end() -
                upper_bound(down[temp].begin(), down[temp].end(), t);
      int how2 =
          lower_bound(up[temp].begin(), up[temp].end(), t) - up[temp].begin();
      dap += (long long)curadd - how - how2;
    }
  }
  printf("%lld", dap);
}
