#include <bits/stdc++.h>
using namespace std;
struct ver {
  long long d;
  long long ind, mass;
};
struct node {
  long long start, end;
  long long mass;
};
ver make(long long a, long long b, long long c) {
  ver t;
  t.d = a;
  t.ind = b;
  t.mass = c;
  return t;
}
long long cmp(const ver &a, const ver &b) { return a.d < b.d; }
bool vis[250005];
ver arr[250005];
long long X, Y, x[250005], y[250005], m[250005], p[250005], r[250005], P, N, R;
long long dis[250005];
node seg[1000005];
queue<long long> Qm, Qr;
long long build(long long nd, long long s, long long e) {
  if (s > e) return 0;
  if (s == e) {
    seg[nd].end = arr[s].d;
    seg[nd].start = arr[s].d;
    seg[nd].mass = arr[s].mass;
    return 0;
  }
  long long m = (s + e) / 2;
  build(nd * 2 + 1, s, m);
  build(nd * 2 + 2, m + 1, e);
  seg[nd].end = seg[nd * 2 + 2].end;
  seg[nd].start = seg[nd * 2 + 1].start;
  seg[nd].mass = min(seg[nd * 2 + 1].mass, seg[nd * 2 + 2].mass);
  return 0;
}
void search(long long nd, long long s, long long e, long long rad,
            long long power) {
  if (s > e || seg[nd].start > rad || seg[nd].mass > power) return;
  if (s == e) {
    Qr.push(r[arr[s].ind]);
    Qm.push(p[arr[s].ind]);
    seg[nd].mass = 1e11 + 6;
    return;
  }
  long long m = (s + e) / 2;
  search(nd * 2 + 1, s, m, rad, power);
  search(nd * 2 + 2, m + 1, e, rad, power);
  seg[nd].mass = min(seg[nd * 2 + 1].mass, seg[nd * 2 + 2].mass);
}
int main() {
  memset(vis, 0, sizeof vis);
  cin >> X >> Y >> P >> R >> N;
  R *= R;
  long long i;
  for (i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> m[i] >> p[i] >> r[i];
    r[i] *= r[i];
  }
  for (i = 0; i < 50003; i++) seg[i].mass = 1e11 + 6;
  for (i = 0; i < N; i++)
    dis[i] = ((X - x[i]) * (X - x[i])) + ((Y - y[i]) * (Y - y[i]));
  for (i = 0; i < N; i++) {
    arr[i] = make(dis[i], i, m[i]);
  }
  sort(arr, arr + N, cmp);
  build(0, 0, N - 1);
  Qr.push(R);
  Qm.push(P);
  long long ans = 0;
  while (!Qr.empty()) {
    ans++;
    long long power = Qm.front();
    long long rad = Qr.front();
    Qr.pop();
    Qm.pop();
    search(0LL, 0LL, N - 1, rad, power);
  }
  cout << ans - 1 << endl;
}
