#include <bits/stdc++.h>
using namespace std;
const int Maxn = 250000;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long r;
int sx, sy, P, n, s, ans, vis[Maxn + 5];
struct Node {
  int m, p, id;
  long long r, dis;
} A[Maxn + 5];
bool operator<(Node x, Node y) { return x.dis < y.dis; }
inline long long dis(int x, int y) {
  return 1ll * (x - sx) * (x - sx) + 1ll * (y - sy) * (y - sy);
}
vector<Node> t[Maxn * 8 + 5];
vector<int> v;
queue<int> q;
int it[Maxn * 8 + 5];
inline void Insert(int l, int r, int p, Node k) {
  t[p].push_back(k);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (k.m <= mid)
    Insert(l, mid, (p << 1), k);
  else
    Insert(mid + 1, r, (p << 1 | 1), k);
}
inline void Count(int p, long long k) {
  while (it[p] < t[p].size() && t[p][it[p]].dis <= k) {
    int x = t[p][it[p]++].id;
    if (!vis[x]) vis[x] = 1, q.push(x);
  }
}
inline void Find(int nl, int nr, int l, int r, int p, long long res) {
  if (l <= nl && nr <= r) {
    Count(p, res);
    return;
  }
  int mid = (nl + nr) >> 1;
  if (l <= mid) Find(nl, mid, l, r, (p << 1), res);
  if (r > mid) Find(mid + 1, nr, l, r, (p << 1 | 1), res);
}
int main() {
  sx = read(), sy = read(), P = read(), r = read(), n = read();
  v.push_back(P), r *= r;
  for (register int i = 1; i <= n; ++i) {
    int x = read(), y = read(), m = read(), p = read(), R = read();
    A[i] = (Node){m, p, i, 1ll * R * R, dis(x, y)};
    v.push_back(m), v.push_back(p);
  }
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  P = lower_bound(v.begin(), v.end(), P) - v.begin() + 1;
  for (register int i = 1; i <= n; ++i) {
    A[i].m = lower_bound(v.begin(), v.end(), A[i].m) - v.begin() + 1;
    A[i].p = lower_bound(v.begin(), v.end(), A[i].p) - v.begin() + 1;
  }
  s = v.size();
  for (register int i = 1; i <= n; ++i) Insert(1, s, 1, A[i]);
  for (register int i = 1; i <= n * 8; ++i)
    if (!t[i].empty()) sort(t[i].begin(), t[i].end());
  Find(1, s, 1, P, 1, r);
  while (!q.empty()) {
    int x = q.front();
    q.pop(), ans++;
    Find(1, s, 1, A[x].p, 1, A[x].r);
  }
  printf("%d\n", ans);
  return 0;
}
