#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
vector<long long> vec[1000010];
long long x[1000010], y[1000010], f[1000010], r[1000010], m[1000010],
    dis[1000010], cop[1000010];
bool cmp(long long x, long long y) { return m[x] > m[y]; }
struct seg {
  long long l[2400100], r[2400100], pl[2400100], pr[2400100], minn[2400100],
      thp[2400100], tt;
  void maintain(long long root) {
    minn[root] = 5000000000000000000ll;
    thp[root] = 0;
    if ((l[root]) && (minn[l[root]] < minn[root])) {
      minn[root] = minn[l[root]];
      thp[root] = thp[l[root]];
    }
    if ((r[root]) && (minn[r[root]] < minn[root])) {
      minn[root] = minn[r[root]];
      thp[root] = thp[r[root]];
    }
  }
  long long build(long long ql, long long qr) {
    long long t = ++tt;
    if (tt > 2400000) exit(0);
    pl[t] = ql;
    pr[t] = qr;
    if (pl[t] != pr[t]) {
      long long mid = (pl[t] + pr[t]) >> 1;
      l[t] = build(pl[t], mid);
      r[t] = build(mid + 1, pr[t]);
      maintain(t);
    } else {
      if (!vec[ql].size())
        minn[t] = 5000000000000000000ll;
      else {
        minn[t] = m[vec[ql][vec[ql].size() - 1]];
        thp[t] = ql;
      }
    }
    return t;
  }
  pair<long long, long long> findmin(long long root, long long ql,
                                     long long qr) {
    if ((pl[root] == ql) && (pr[root] == qr))
      return pair<long long, long long>(minn[root], thp[root]);
    long long mid = (pl[root] + pr[root]) >> 1;
    pair<long long, long long> ans(5000000000000000000ll, 0);
    if (ql <= mid) ans = min(ans, findmin(l[root], ql, min(mid, qr)));
    if (qr > mid) ans = min(ans, findmin(r[root], max(mid + 1, ql), qr));
    if (ans.first == 5000000000000000000ll) ans.second = 0;
    return ans;
  }
  void erase(long long root, long long w) {
    if (pl[root] == pr[root]) {
      vec[w].pop_back();
      if (!vec[w].size())
        minn[root] = 5000000000000000000ll;
      else
        minn[root] = m[vec[w][vec[w].size() - 1]];
      return;
    }
    long long mid = (pl[root] + pr[root]) >> 1;
    if (w <= mid)
      erase(l[root], w);
    else
      erase(r[root], w);
    maintain(root);
  }
} seg;
int main() {
  long long px, py, force, tr, n;
  scanf("%lld%lld%lld%lld%lld", &x[0], &y[0], &f[0], &r[0], &n);
  m[0] = 0;
  mp[r[0]] = 0;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld%lld%lld%lld%lld", &x[i], &y[i], &m[i], &f[i], &r[i]);
  }
  for (long long i = 0; i <= n; i++) {
    dis[i] = (x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0]);
    r[i] = r[i] * r[i];
    mp[r[i]] = 0;
    mp[dis[i]] = 0;
  }
  long long tp = 0;
  for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
       it++)
    it->second = ++tp;
  for (long long i = 0; i <= n; i++) {
    dis[i] = mp[dis[i]];
    r[i] = mp[r[i]];
    if (i) vec[dis[i]].push_back(i);
  }
  for (long long i = 1; i <= n; i++) sort(vec[i].begin(), vec[i].end(), cmp);
  seg.build(1, 3 * n + 9);
  long long head = 0, tail = 0;
  cop[++head] = 0;
  while (head != tail) {
    long long p = cop[++tail];
    while (1) {
      long long u = seg.findmin(1, 1, r[p]).second;
      if (!u) break;
      if (m[vec[u][vec[u].size() - 1]] > f[p]) break;
      cop[++head] = vec[u][vec[u].size() - 1];
      seg.erase(1, u);
    }
  }
  printf("%lld\n", head - 1);
}
