#include <bits/stdc++.h>
using namespace std;
const int N = 250005, M = N << 2;
int x, y, p0, r0, n, idx, rt, tot;
int id[N], m[N], p[N], rr[N], ls[M], rs[M], sum[M];
bool used[N];
long long dis[N];
set<pair<long long, int> > s[M];
queue<pair<long long, int> > q;
void build(int &x, int l, int r) {
  if (!x) x = ++idx;
  sum[x] = r - l + 1;
  for (int i = l; i <= r; i++) s[x].insert(make_pair(m[id[i]], id[i]));
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(ls[x], l, mid), build(rs[x], mid + 1, r);
}
void solve(int x, int l, int r, long long R, int P) {
  if (!sum[x] || dis[id[l]] > R) return;
  if (dis[id[r]] <= R) {
    set<pair<long long, int> >::iterator it;
    while (sum[x] && s[x].begin()->first <= P) {
      it = s[x].begin();
      int i = it->second;
      if (it->first > P) break;
      if (!used[i]) {
        used[i] = 1;
        ++tot;
        q.push(make_pair(1ll * rr[i] * rr[i], p[i]));
      }
      s[x].erase(it);
      sum[x]--;
    }
    return;
  }
  int mid = (l + r) >> 1;
  solve(ls[x], l, mid, R, P), solve(rs[x], mid + 1, r, R, P);
}
bool cmp(int a, int b) { return dis[a] < dis[b]; }
int main() {
  cin >> x >> y >> p0 >> r0 >> n;
  for (int i = 1; i <= n; i++) {
    int X, Y;
    scanf("%d%d%d%d%d", &X, &Y, &m[i], &p[i], &rr[i]);
    dis[i] = 1ll * (x - X) * (x - X) + 1ll * (y - Y) * (y - Y);
    id[i] = i;
  }
  sort(id + 1, id + n + 1, cmp);
  build(rt, 1, n);
  q.push(make_pair(1ll * r0 * r0, p0));
  while (q.size()) {
    pair<long long, int> t = q.front();
    q.pop();
    solve(rt, 1, n, t.first, t.second);
  }
  printf("%d\n", tot);
  return 0;
}
