#include <bits/stdc++.h>
using namespace std;
const int MMax = 1500;
int N, M;
map<pair<pair<int, int>, long long>,
    pair<vector<long long>, vector<long long> > >
    Map;
int X[MMax], Y[MMax], R[MMax];
long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; }
pair<pair<int, int>, long long> getline(int x1, int y1, int x2, int y2) {
  int A = x2 - x1, B = y2 - y1;
  long long C = (long long)x1 * y2 - (long long)y1 * x2;
  int g = gcd(gcd(A, B), C);
  A /= g;
  B /= g;
  C /= g;
  if (A < 0) {
    A = -A;
    B = -B;
    C = -C;
  }
  if (A == 0 && B < 0) {
    B = -B;
    C = -C;
  }
  return make_pair(make_pair(A, B), C);
}
long long getpos(pair<pair<int, int>, long long> &l, int x, int y) {
  return l.first.first * (long long)x + l.first.second * (long long)y;
}
int getsmall(vector<long long> &v, long long x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
int getbig(vector<long long> &v, long long x) {
  return v.end() - upper_bound(v.begin(), v.end(), x);
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    pair<pair<int, int>, long long> line =
        getline(x1 * 2, y1 * 2, x2 * 2, y2 * 2);
    long long p1 = getpos(line, x1 * 2, y1 * 2);
    long long p2 = getpos(line, x2 * 2, y2 * 2);
    Map[line].first.push_back(min(p1, p2));
    Map[line].second.push_back(max(p1, p2));
  }
  for (map<pair<pair<int, int>, long long>,
           pair<vector<long long>, vector<long long> > >::iterator it =
           Map.begin();
       it != Map.end(); it++) {
    sort(it->second.first.begin(), it->second.first.end());
    sort(it->second.second.begin(), it->second.second.end());
  }
  for (int i = 0; i < M; i++) scanf("%d%d%d", X + i, Y + i, R + i);
  long long ret = 0;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < i; j++)
      if (R[i] == R[j] &&
          (X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j]) >
              4 * R[i] * R[i]) {
        int mx = X[i] + X[j], my = Y[i] + Y[j];
        pair<pair<int, int>, long long> line =
            getline(mx + (Y[j] - Y[i]), my - (X[j] - X[i]), mx - (Y[j] - Y[i]),
                    my + (X[j] - X[i]));
        map<pair<pair<int, int>, long long>,
            pair<vector<long long>, vector<long long> > >::iterator it =
            Map.find(line);
        if (it != Map.end()) {
          long long pos1 = getpos(line, X[i] * 2, Y[i] * 2);
          long long pos2 = getpos(line, X[j] * 2, Y[j] * 2);
          if (pos1 != pos2) puts("WA");
          ret += it->second.first.size() -
                 getsmall(it->second.second, min(pos1, pos2)) -
                 getbig(it->second.first, max(pos1, pos2));
        }
      }
  cout << ret << endl;
  return 0;
}
