#include <bits/stdc++.h>
using namespace std;
const long long maxn = 260000;
struct Tgrab {
  long long dist, m, p, r;
} a[maxn + 1];
set<pair<long long, long long> > df[maxn + 1];
long long dist[maxn + 1], xl[maxn + 1];
long long result = 0;
long long top, n;
void init() {
  long long p, r, oldx, oldy, x, y;
  scanf("%I64d%I64d%I64d%I64d%I64d", &x, &y, &p, &r, &n);
  r = r * r;
  a[0].p = p;
  a[0].r = r;
  oldx = x;
  oldy = y;
  for (long long i = 1; i <= n; ++i) {
    scanf("%I64d%I64d", &x, &y);
    a[i].dist = (x - oldx) * (x - oldx) + (y - oldy) * (y - oldy);
    dist[i - 1] = a[i].dist;
    scanf("%I64d%I64d%I64d", &a[i].m, &a[i].p, &a[i].r);
    a[i].r = a[i].r * a[i].r;
  }
  sort(dist, dist + n);
  top = unique(dist, dist + n) - dist;
  for (long long i = 1; i <= n; ++i) {
    long long loc = lower_bound(dist, dist + top, a[i].dist) - dist;
    for (long long j = loc + 1; j <= top; j += (j & (j ^ (j - 1))))
      df[j].insert(make_pair(a[i].m, i));
  }
}
void work() {
  long long head = 0, tail = 1;
  long long i, j, k;
  long long P, R;
  set<pair<long long, long long> >::iterator p;
  xl[1] = 0;
  while (head < tail) {
    long long i = xl[++head];
    P = a[i].p;
    R = a[i].r;
    long long j = lower_bound(dist, dist + top, R + 1) - dist;
    j = j - 1;
    j = j + 1;
    while (j > 0) {
      while (true) {
        p = df[j].lower_bound(make_pair(P + 1, 0));
        if (p == df[j].begin()) break;
        --p;
        k = p->second;
        xl[++tail] = k;
        long long loc = lower_bound(dist, dist + top, a[k].dist) - dist;
        for (long long h = loc + 1; h <= top; h += (h & (h ^ (h - 1))))
          df[h].erase(make_pair(a[k].m, k));
      }
      j -= (j & (j ^ (j - 1)));
    }
  }
  result = tail - 1;
}
void output() { printf("%I64d\n", result); }
int main() {
  init();
  work();
  output();
  return 0;
}
