#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 301 * 1001;
long long st[4 * MAXN], ans;
bool mark[MAXN];
vector<pair<long long, long long> > vv;
vector<pair<long long, long long> > seg[4 * MAXN];
vector<pair<long long, pair<long long, long long> > > v;
long long p[MAXN], ra[MAXN];
void build(long long s, long long e, long long ind) {
  if (e - s < 2) {
    seg[ind].push_back(v[s].second);
    return;
  }
  long long mid = (s + e) / 2;
  build(s, mid, 2 * ind);
  build(mid, e, 2 * ind + 1);
  seg[ind].resize(e - s);
  merge(seg[2 * ind].begin(), seg[2 * ind].end(), seg[2 * ind + 1].begin(),
        seg[2 * ind + 1].end(), seg[ind].begin());
}
void get(long long l, long long r, long long val, long long s, long long e,
         long long ind) {
  if (e <= l || r <= s) return;
  if (l <= s && e <= r) {
    long long i = lower_bound(seg[ind].begin(), seg[ind].end(),
                              make_pair(val + 1, -1ll)) -
                  seg[ind].begin();
    while (st[ind] < e - s && mark[seg[ind][st[ind]].second]) st[ind]++;
    for (long long j = st[ind]; j < i; j++) {
      long long k = seg[ind][j].second;
      if (!mark[k]) {
        mark[k] = 1;
        ans++;
        vv.push_back({ra[k], p[k]});
      }
    }
    st[ind] = max(st[ind], i);
    return;
  }
  long long mid = (s + e) / 2;
  get(l, r, val, s, mid, 2 * ind);
  get(l, r, val, mid, e, 2 * ind + 1);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, x, y, pp, rr;
  cin >> x >> y >> pp >> rr >> n;
  rr *= rr;
  long long q, w, e;
  for (long long i = 0; i < n; i++) {
    cin >> q >> w >> e >> p[i] >> ra[i];
    ra[i] *= ra[i];
    long long d = (q - x) * (q - x) + (w - y) * (w - y);
    v.push_back({d, {e, i}});
  }
  sort(v.begin(), v.end());
  build(0, n, 1);
  vv.push_back({rr, pp});
  while (vv.size()) {
    long long r = vv.back().first, p = vv.back().second;
    vv.pop_back();
    pair<long long, pair<long long, long long> > pw = {r + 1, {-1, -1}};
    long long i = lower_bound(v.begin(), v.end(), pw) - v.begin();
    get(0, i, p, 0, n, 1);
  }
  cout << ans;
}
