#include <bits/stdc++.h>
using namespace std;
int getint() {
  int ret = 0;
  bool ok = false, neg = false;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + ret + ret + c - '0', ok = true;
    else if (ok)
      return neg ? -ret : ret;
    else if (c == '-')
      neg = true;
  }
}
struct item {
  long long d;
  int m, f, r;
  bool operator<(const item &k2) const { return d < k2.d; }
  item() {}
  item(long long _d, int _m, int _f, int _r) : d(_d), m(_m), f(_f), r(_r) {}
};
item A[250010];
int n;
int T[1 << 19], M = 1;
const int inf = ~0U >> 1;
inline int minm(int a, int b) { return A[a].m < A[b].m ? a : b; }
void remove(int i) {
  i += M;
  T[i] = 0;
  for (i >>= 1; i; i >>= 1) T[i] = minm(T[i + i], T[i + i + 1]);
}
int getpos(int r) {
  item t = item((long long)r * r, 0, 0, 0);
  return upper_bound(A + 1, A + n + 1, t) - A - 1;
}
int query(int l, int r) {
  if (l > r) return 0;
  int ret = 0;
  for (l += M - 1, r += M + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
    if (~l & 1) ret = minm(ret, T[l + 1]);
    if (r & 1) ret = minm(ret, T[r - 1]);
  }
  return ret;
}
queue<pair<int, int> > Q;
int main() {
  int x0 = getint(), y0 = getint(), f0 = getint(), r0 = getint();
  n = getint();
  for (int i = 1; i <= n; i++) {
    long long x = getint() - x0, y = getint() - y0, d = x * x + y * y;
    int m = getint(), f = getint(), r = getint();
    A[i] = item(d, m, f, r);
  }
  sort(A + 1, A + n + 1);
  while (M - 2 < n) M <<= 1;
  A[0].m = inf;
  for (int i = 1; i <= n; i++) T[i + M] = i;
  for (int i = M; i; i--) T[i] = minm(T[i + i], T[i + i + 1]);
  int ans = 0;
  Q.push(make_pair(f0, r0));
  while (!Q.empty()) {
    int f = Q.front().first, r = Q.front().second;
    Q.pop();
    int R = getpos(r);
    for (;;) {
      int t = query(1, R);
      if (t && A[t].m <= f)
        ans++, Q.push(make_pair(A[t].f, A[t].r)), remove(t);
      else
        break;
    }
  }
  printf("%d\n", ans);
  return 0;
}
