#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000000")
using namespace std;
const long long int INF = 2e18;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int main() {
  map<pair<long long int, pair<long long int, long long int> >,
      vector<long long int> >
      left, right;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x, y, x2, y2;
    scanf("%d%d%d%d", &x, &y, &x2, &y2);
    if (x > x2) {
      swap(x, x2);
      swap(y, y2);
    }
    long long int a = y2 - y;
    long long int b = x - x2;
    long long int c = -(a * x + b * y);
    long long int gc = gcd(abs(a), gcd(abs(b), abs(c)));
    a /= gc;
    b /= gc;
    c /= gc;
    if (a < 0) {
      a = -a;
      b = -b;
      c = -c;
    }
    left[make_pair(a, make_pair(b, c))].push_back(2 * x);
    right[make_pair(a, make_pair(b, c))].push_back(2 * x2);
  }
  vector<pair<pair<int, int>, int> > cir(m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    cir[i] = make_pair(make_pair(a, b), c);
  }
  for (map<pair<long long int, pair<long long int, long long int> >,
           vector<long long int> >::iterator it = left.begin();
       it != left.end(); it++) {
    sort(it->second.begin(), it->second.end());
  }
  for (map<pair<long long int, pair<long long int, long long int> >,
           vector<long long int> >::iterator it = right.begin();
       it != right.end(); it++) {
    sort(it->second.begin(), it->second.end());
  }
  long long int out = 0;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      long long int x = cir[i].first.first, y = cir[i].first.second,
                    r = cir[i].second;
      long long int x2 = cir[j].first.first, y2 = cir[j].first.second,
                    r2 = cir[j].second;
      if (r == r2 &&
          (r + r2) * (r + r2) < (x - x2) * (x - x2) + (y - y2) * (y - y2)) {
        long long int a = 2 * (x2 - x);
        long long int b = 2 * (y2 - y);
        long long int c = -(y2 * y2 - y * y + x2 * x2 - x * x);
        long long int gc = gcd(abs(a), gcd(abs(b), abs(c)));
        if (!a && !b && !c) gc = 1;
        a /= gc;
        b /= gc;
        c /= gc;
        for (int q = 0; q < 2; q++) {
          map<pair<long long int, pair<long long int, long long int> >,
              vector<long long int> >::iterator it =
              left.find(make_pair(a, make_pair(b, c)));
          if (it != left.end()) {
            long long int with = (x + x2);
            int f = (upper_bound(it->second.begin(), it->second.end(), with) -
                     it->second.begin());
            it = right.find(make_pair(a, make_pair(b, c)));
            vector<long long int>::iterator iti =
                lower_bound(it->second.begin(), it->second.end(), with);
            int s = (iti - it->second.begin());
            if (iti != it->second.end() && *iti >= with) {
              s--;
            }
            long long int sz = (int)it->second.size();
            out += sz - (sz - f) - min((long long int)s + 1, sz);
          }
          a = -a;
          b = -b;
          c = -c;
        }
      }
    }
  }
  cout << out;
}
