#include <bits/stdc++.h>
using namespace std;
int nSegments;
int X1[300001];
int Y1[300001];
int X2[300001];
int Y2[300001];
int nCircle;
int Xc[1501], Yc[1501], Rc[1501];
int gcd(int a, int b) {
  if (a == 0 || b == 0) return a + b;
  return gcd(b, a % b);
}
int dist2(int dx, int dy) { return dx * dx + dy * dy; }
void getFormalName(int &x, int &y) {
  int g = gcd(abs(x), abs(y));
  x /= g;
  y /= g;
  if (x < 0) {
    x = -x;
    y = -y;
  }
  if (x == 0 && y < 0) y = -y;
}
map<unsigned long long, vector<int> > mem;
vector<int> empty;
map<unsigned long long, bool> have;
unsigned long long getCode(int a, int b, int c) {
  a += 50000;
  b += 50000;
  c += 2000000000;
  unsigned long long ret = c * 2000000000LL;
  ret += a * 100000;
  ret += b;
  return ret;
}
int query(vector<int> &lis, int upperBound) {
  if (lis.size() == 0) return 0;
  if (lis[0] > upperBound) return 0;
  int L = 0, R = lis.size(), M;
  while (R - L > 1) {
    M = (L + R) / 2;
    if (lis[M] <= upperBound)
      L = M;
    else
      R = M;
  }
  return L + 1;
}
int MAIN() {
  cin >> nSegments >> nCircle;
  for (int i = 1; i <= nSegments; i++) {
    cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
    X1[i] *= 2;
    Y1[i] *= 2;
    X2[i] *= 2;
    Y2[i] *= 2;
  }
  for (int i = 1; i <= nCircle; i++) {
    cin >> Xc[i] >> Yc[i] >> Rc[i];
    Xc[i] *= 2;
    Yc[i] *= 2;
    Rc[i] *= 2;
  }
  for (int i = 1; i <= nSegments; i++) {
    int dx = (X1[i] - X2[i]);
    int dy = (Y1[i] - Y2[i]);
    getFormalName(dx, dy);
    int shift = dy * X1[i] + (-dx) * Y1[i];
    int p1 = dx * X1[i] + dy * Y1[i];
    int p2 = dx * X2[i] + dy * Y2[i];
    if (p1 > p2) swap(p1, p2);
    unsigned long long code = getCode(dx, dy, shift);
    have[code] = true;
  }
  for (int i = 1; i <= nCircle; i++)
    for (int j = i + 1; j <= nCircle; j++) {
      if (Rc[i] != Rc[j]) continue;
      int d2 = dist2(Xc[i] - Xc[j], Yc[i] - Yc[j]);
      if ((Rc[i] * Rc[i] * 4) >= d2) continue;
      int dx = (Xc[i] - Xc[j]);
      int dy = (Yc[i] - Yc[j]);
      swap(dx, dy);
      dx = -dx;
      getFormalName(dx, dy);
      int myX = (Xc[i] + Xc[j]) / 2;
      int myY = (Yc[i] + Yc[j]) / 2;
      int shift = dy * myX + (-dx) * myY;
      int points = dx * myX + dy * myY;
      unsigned long long code = getCode(dx, dy, shift);
      if (have.count(code) == false) continue;
      if (mem.count(code) == false) mem[code] = empty;
      mem[code].push_back(points);
    }
  long long ans = 0;
  for (int i = 1; i <= nSegments; i++) {
    int dx = (X1[i] - X2[i]);
    int dy = (Y1[i] - Y2[i]);
    getFormalName(dx, dy);
    int shift = dy * X1[i] + (-dx) * Y1[i];
    int p1 = dx * X1[i] + dy * Y1[i];
    int p2 = dx * X2[i] + dy * Y2[i];
    if (p1 > p2) swap(p1, p2);
    unsigned long long code = getCode(dx, dy, shift);
    if (mem.count(code) == false) continue;
    ans += query(mem[code], p2);
    ans -= query(mem[code], p1 - 1);
  }
  cout << ans << endl;
  return 0;
}
int main() {
  ios ::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  return MAIN();
}
