#include <bits/stdc++.h>
using namespace std;
struct item {
  long long id, x, y, m, p, r;
};
long long n;
vector<item> v;
map<long long, long long> compress;
set<long long> cc;
long long maxidist = 0;
long long dist(item a, item b) {
  return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
bool cmp(item a, item b) {
  if (a.id == 0)
    return 1;
  else if (b.id == 0)
    return 0;
  else
    return a.m < b.m;
}
long long cnt = 0;
queue<item> bit[600005];
bool visited[250005];
queue<item> sweep;
void add(long long x, item a) {
  for (long long i = x; i < cnt + 100; i += (i & -i)) {
    bit[i].push(a);
  }
}
void get(long long x, const item& curr) {
  for (long long i = x; i > 0; i -= (i & -i)) {
    while (bit[i].size() && bit[i].front().m <= curr.p) {
      if (!visited[bit[i].front().id]) {
        sweep.push(bit[i].front());
      }
      bit[i].pop();
    }
  }
}
int32_t main() {
  v.resize(1);
  scanf("%lld%lld%lld%lld%lld", &v[0].x, &v[0].y, &v[0].p, &v[0].r, &n);
  cc.insert(v[0].r * v[0].r);
  v[0].id = 0;
  for (long long i = 1; i <= n; i++) {
    v.push_back(item());
    scanf("%lld%lld%lld%lld%lld", &v[i].x, &v[i].y, &v[i].m, &v[i].p, &v[i].r);
    v[i].id = i;
    cc.insert(dist(v[i], v[0]));
    cc.insert(v[i].r * v[i].r);
  }
  for (auto w : cc) {
    compress[w] = ++cnt;
  }
  sort(v.begin(), v.end(), cmp);
  for (long long i = 1; i <= n; i++) {
    add(compress[dist(v[i], v[0])], v[i]);
  }
  sweep.push(v[0]);
  while (!sweep.empty()) {
    item u = sweep.front();
    sweep.pop();
    if (visited[u.id]) continue;
    visited[u.id] = true;
    get(compress[u.r * u.r], u);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) ans += visited[i];
  printf("%lld\n", ans);
}
