#include <bits/stdc++.h>
using namespace std;
vector<int> v[250005 * 4];
struct arr {
  int p, m, l, r, x, y;
} a[250005];
struct ok {
  long long dis;
  int id;
} d[250005], tmp;
int Delete[250005], q[250005];
int L, R, h, t, i, n, Q, now, ans;
inline int cmp(const int &A, const int &B) { return a[A].m > a[B].m; }
inline int CMP(const ok &a, const ok &b) { return a.dis < b.dis; }
inline int Union(int A, int B) {
  if (A == 0 || B == 0) return !A ? B : A;
  return a[A].m < a[B].m ? A : B;
}
inline void build(int k, int l, int r) {
  for (int i = l; i <= r; i++) v[k].push_back(d[i].id);
  sort(v[k].begin(), v[k].end(), cmp);
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (l <= mid) build(k << 1, l, mid);
  if (r > mid) build(k << 1 | 1, mid + 1, r);
}
inline int work(int k) {
  while (v[k].size() && Delete[v[k][v[k].size() - 1]]) v[k].pop_back();
  if (!v[k].size()) return 0;
  return (a[v[k].back()].m <= a[now].p) ? v[k].back() : 0;
}
inline int ask(int k, int l, int r) {
  if (L <= l && r <= R) return work(k);
  int mid = (l + r) >> 1;
  if (R <= mid) return ask(k << 1, l, mid);
  if (L > mid) return ask(k << 1 | 1, mid + 1, r);
  return Union(ask(k << 1, l, mid), ask(k << 1 | 1, mid + 1, r));
}
inline long long sqr(int x) { return x * 1ll * x; }
inline long long dist(int A, int B) {
  return sqr(a[A].x - a[B].x) + sqr(a[A].y - a[B].y);
}
int main() {
  scanf("%d%d%d%d%d", &a[0].x, &a[0].y, &a[0].p, &a[0].r, &n);
  for (i = 1; i <= n; i++)
    scanf("%d%d%d%d%d", &a[i].x, &a[i].y, &a[i].m, &a[i].p, &a[i].r);
  for (i = 1; i <= n; i++) d[i].dis = dist(0, i), d[i].id = i;
  sort(d + 1, d + n + 1, CMP);
  build(1, 1, n);
  h = 0;
  t = 1;
  q[1] = 0;
  while (h < t) {
    now = q[++h];
    L = 1;
    tmp.dis = a[now].r * 1ll * a[now].r;
    R = upper_bound(d + 1, d + n + 1, tmp, CMP) - (d + 1);
    while (R) {
      Q = ask(1, 1, n);
      if (!Q) break;
      Delete[Q] = 1;
      ans++;
      q[++t] = Q;
    }
  }
  printf("%d\n", ans);
}
