#include <bits/stdc++.h>
using namespace std;
const int maxN = 250010;
const int maxT = 1 << 19;
const int maxMem = maxT * 19;
int X, Y, P, N, p[maxN], m[maxN], used[maxN];
long long R, r[maxN], d[maxN];
long long an, a[2 * maxN];
int qst, qen, qP[maxN];
long long qR[maxN];
int mpos = 0, mem[maxMem];
int pos[2 * maxT], num[2 * maxT], *val[2 * maxT];
long long sqr(long long x) { return x * x; }
int *getMem(int n) {
  int *res = mem + mpos;
  mpos += n;
  assert(mpos <= maxMem);
  return res;
}
inline bool mless(int i, int j) { return m[i] < m[j]; }
inline void add(int p, long long r) { qP[qen] = p, qR[qen++] = r; }
void AddAll(int v, int P) {
  int &Pos = pos[v], i;
  while (Pos < num[v] && m[i = val[v][Pos]] <= P) {
    if (!used[i]) add(p[i], r[i]), used[i] = 1;
    Pos++;
  }
}
int main() {
  scanf("%d%d%d%I64d%d", &X, &Y, &P, &R, &N);
  R *= R;
  for (int i = 0; i < (int)(N); i++) {
    int x, y;
    scanf("%d%d%d%d%I64d", &x, &y, &m[i], &p[i], &r[i]);
    r[i] *= r[i];
    d[i] = sqr(X - x) + sqr(Y - y);
  }
  an = 0;
  for (int i = 0; i < (int)(N); i++) a[an++] = d[i], a[an++] = r[i];
  a[an++] = R;
  sort(a, a + an);
  for (int i = 0; i < (int)(N); i++)
    (d[i] = lower_bound(a, a + an, d[i]) - a),
        (r[i] = lower_bound(a, a + an, r[i]) - a);
  (R = lower_bound(a, a + an, R) - a);
  an = 0;
  for (int i = 0; i < (int)(N); i++) a[an++] = m[i], a[an++] = p[i];
  a[an++] = P;
  sort(a, a + an);
  for (int i = 0; i < (int)(N); i++)
    (m[i] = lower_bound(a, a + an, m[i]) - a),
        (p[i] = lower_bound(a, a + an, p[i]) - a);
  (P = lower_bound(a, a + an, P) - a);
  for (int i = 0; i < (int)(N); i++) num[maxT + d[i]]++;
  for (int i = maxT - 1; i >= 1; i--) num[i] = num[2 * i] + num[2 * i + 1];
  for (int i = 0; i < (int)(2 * maxT); i++) val[i] = getMem(num[i]);
  memset(num, 0, sizeof(num));
  for (int i = 0; i < (int)(N); i++) {
    int j = maxT + d[i];
    val[j][num[j]++] = i;
  }
  for (int i = 0; i < (int)(maxT); i++) {
    int j = maxT + i;
    sort(val[j], val[j] + num[j], mless);
  }
  for (int i = maxT - 1; i >= 1; i--) {
    int l = 2 * i, r = 2 * i + 1;
    num[i] = num[l] + num[r];
    merge(val[l], val[l] + num[l], val[r], val[r] + num[r], val[i], mless);
  }
  qst = 0, qen = 0;
  add(P, R);
  while (qst < qen) {
    P = qP[qst], R = qR[qst++];
    int l = maxT, r = maxT + R;
    while (l <= r) {
      if (l % 2 == 1) AddAll(l++, P);
      if (r % 2 == 0) AddAll(r--, P);
      l >>= 1, r >>= 1;
    }
  }
  printf("%d\n", qen - 1);
  return 0;
}
