#include <bits/stdc++.h>
using namespace std;
int p[300007][4];
int q[1507][3];
vector<int> z[1507 * 1507 / 2 + 1][2];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int fd(vector<int>& k, int v) {
  int f = 0, t = k.size() - 1;
  for (; f <= t;) {
    int mid = (f + t) / 2;
    if (k[mid] < v)
      f = mid + 1;
    else
      t = mid - 1;
  }
  return t;
}
int cal(vector<int> k, int f) { return fd(k, f); }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%d%d%d%d", *(p + i), *(p + i) + 1, *(p + i) + 2, *(p + i) + 3);
  for (int i = 0; i < m; ++i)
    scanf("%d%d%d", *(q + i), *(q + i) + 1, *(q + i) + 2);
  map<pair<long long, pair<int, int> >, int> mapp;
  int cnt(0);
  map<pair<long long, pair<int, int> >, int>::iterator ite;
  for (int i = 0; i < n; ++i) {
    int a = -(p[i][1] - p[i][3]);
    int b = p[i][0] - p[i][2];
    long long c = 0;
    if (a == 0)
      b = 1, c = p[i][1] * 2;
    else if (b == 0)
      a = 1, c = p[i][0] * 2;
    else {
      int d = gcd(abs(a), abs(b));
      a /= d, b /= d;
      c = (long long)a * p[i][0] + (long long)b * p[i][1];
      c *= 2LL;
    }
    if (a && b && a < 0) a = -a, b = -b, c = -c;
    pair<long long, pair<int, int> > tmp =
        pair<long long, pair<int, int> >(c, pair<int, int>(a, b));
    ite = mapp.find(tmp);
    int tt;
    if (ite == mapp.end()) {
      tt = mapp[tmp] = cnt;
      ++cnt;
    } else
      tt = ite->second;
    if (b == 0) {
      z[tt][0].push_back(min(p[i][1], p[i][3]) * 2);
      z[tt][1].push_back(2 * max(p[i][1], p[i][3]));
    } else {
      z[tt][0].push_back(min(p[i][0], p[i][2]) * 2);
      z[tt][1].push_back(2 * max(p[i][0], p[i][2]));
    }
  }
  for (int i = 0; i < cnt; ++i)
    for (int j = 0; j < 2; ++j) sort(z[i][j].begin(), z[i][j].end());
  long long ans(0);
  for (int i = 0; i < m; ++i)
    for (int j = i + 1; j < m; ++j)
      if (q[i][2] == q[j][2]) {
        int a = q[i][0] - q[j][0];
        int b = q[i][1] - q[j][1];
        if ((long long)a * a + (long long)b * b <=
            4 * (long long)q[i][2] * (long long)q[i][2])
          continue;
        long long c = 0;
        if (a == 0)
          b = 1, c = q[i][1] + q[j][1];
        else if (b == 0)
          a = 1, c = q[i][0] + q[j][0];
        else {
          int d = gcd(abs(a), abs(b));
          a /= d, b /= d;
          c = (long long)a * (q[i][0] + q[j][0]) +
              (long long)b * (q[i][1] + q[j][1]);
        }
        if (a && b && a < 0) a = -a, b = -b, c = -c;
        pair<long long, pair<int, int> > tmp =
            pair<long long, pair<int, int> >(c, pair<int, int>(a, b));
        int tt;
        ite = mapp.find(tmp);
        if (ite != mapp.end()) {
          int cc;
          if (b == 0)
            cc = q[i][1] + q[j][1];
          else
            cc = q[i][0] + q[j][0];
          ans += (cal(z[ite->second][0], cc + 1) - cal(z[ite->second][1], cc));
        }
      }
  cout << ans;
  return 0;
}
