#include <bits/stdc++.h>
using namespace std;
queue<pair<long long, long long> > q;
struct grip {
  long long d, m, r, p;
} g[250010];
bool comp(grip a, grip b) { return a.d < b.d; }
bool operator<(long long a, grip b) { return a < b.d; }
struct mycomp {
  bool operator()(long long a, long long b) { return g[a].m > g[b].m; }
};
bool vst[250010];
priority_queue<long long, vector<long long>, mycomp> bit[250010];
void insert(long long x) {
  long long u = x;
  x++;
  while (x < 250010) {
    bit[x].push(u);
    x += x & -x;
  }
}
void query(long long x, long long p) {
  x++;
  while (x > 0) {
    while (!bit[x].empty() && g[bit[x].top()].m <= p) {
      long long u = bit[x].top();
      if (!vst[u]) q.push(make_pair(g[u].r, g[u].p)), vst[u] = 1;
      bit[x].pop();
    }
    x -= x & -x;
  }
}
int main() {
  long long sx, sy, sp, sr, n;
  cin >> sx >> sy >> sp >> sr >> n;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y >> g[i].m >> g[i].p >> g[i].r;
    g[i].d = (x - sx) * (x - sx) + (y - sy) * (y - sy);
  }
  sort(g, g + n, comp);
  for (long long i = 0; i < n; i++) insert(i);
  long long cnt = 0;
  q.push(make_pair(sr, sp));
  while (!q.empty()) {
    pair<long long, long long> p = q.front();
    q.pop();
    long long x = upper_bound(g, g + n, p.first * p.first) - g;
    x--;
    query(x, p.second);
    cnt++;
  }
  cout << cnt - 1 << endl;
}
