#include <bits/stdc++.h>
using namespace std;
long long l[255555];
long long d[255555];
int v[255555];
int m[255555];
int p[255555];
int r[255555];
set<pair<int, int> > s[255555];
int x, y, p0, r0, n, xi, yi, z;
queue<pair<int, int> > q;
set<pair<int, int> >::iterator it;
int main() {
  scanf("%d %d %d %d %d", &x, &y, &p0, &r0, &n), p0 *= -1;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d %d", &xi, &yi, &m[i], &p[i], &r[i]);
    m[i] *= -1, p[i] *= -1, xi -= x, yi -= y,
        d[i] = l[i] = (long long)xi * xi + (long long)yi * yi;
  }
  sort(l, l + n);
  int lc = unique(l, l + n) - l;
  for (int i = 0; i < n; i++) v[i] = lower_bound(l, l + lc, d[i]) - l + 1;
  for (int i = 0; i < n; i++)
    for (int j = v[i]; j <= lc; j += j & -j)
      s[j].insert(pair<int, int>(m[i], i));
  q.push(pair<int, int>(p0, r0));
  while (!q.empty()) {
    pair<int, int> x = q.front();
    q.pop();
    x.second = upper_bound(l, l + lc, (long long)x.second * x.second) - l;
    for (int i = x.second; i; i -= i & -i) {
      while ((it = s[i].lower_bound(pair<int, int>(x.first, -1))) !=
             s[i].end()) {
        z++;
        int w = it->second;
        q.push(pair<int, int>(p[w], r[w]));
        for (int j = v[w]; j <= lc; j += j & -j)
          s[j].erase(pair<int, int>(m[w], w));
      }
    }
  }
  printf("%d\n", z);
  return 0;
}
