#include <bits/stdc++.h>
using namespace std;
long long dis(long long x1, long long x2, long long y1, long long y2) {
  long long a = x1 - x2, b = y1 - y2;
  return a * a + b * b;
}
int n;
int p[250005], w[250005];
long long sx, sy, x[250005], y[250005], r[250005], d[250005], data1[500005];
int data2[500005], cnt1, cnt2;
queue<int> q;
struct SGT {
  pair<int, int> minn;
  set<pair<int, int> > s;
  SGT() { minn = make_pair(0x3f3f3f3f, 0x3f3f3f3f); }
} A[500005 << 2];
void Insert(int q, int l, int r, int k, int a, int p) {
  if (l == r) {
    A[q].minn = min(A[q].minn, make_pair(a, p));
    A[q].s.insert(make_pair(a, p));
    return;
  }
  int mid = (l + r) >> 1;
  if (k <= mid)
    Insert(q << 1, l, mid, k, a, p);
  else
    Insert(q << 1 | 1, mid + 1, r, k, a, p);
  A[q].minn = min(A[q << 1].minn, A[q << 1 | 1].minn);
}
pair<int, int> Query(int q, int l, int r, int L, int R) {
  if (l == L && r == R) return A[q].minn;
  int mid = (l + r) >> 1;
  if (R <= mid) return Query(q << 1, l, mid, L, R);
  if (L > mid) return Query(q << 1 | 1, mid + 1, r, L, R);
  return min(Query(q << 1, l, mid, L, mid),
             Query(q << 1 | 1, mid + 1, r, mid + 1, R));
}
void Delete(int q, int l, int r, int k, int a, int p) {
  if (l == r) {
    A[q].s.erase(make_pair(a, p));
    if (A[q].s.empty())
      A[q].minn = make_pair(0x3f3f3f3f, 0x3f3f3f3f);
    else
      A[q].minn = *(A[q].s.begin());
    return;
  }
  int mid = (l + r) >> 1;
  if (k <= mid)
    Delete(q << 1, l, mid, k, a, p);
  else
    Delete(q << 1 | 1, mid + 1, r, k, a, p);
  A[q].minn = min(A[q << 1].minn, A[q << 1 | 1].minn);
}
int main() {
  scanf("%I64d%I64d%d%I64d%d", &sx, &sy, &p[0], &r[0], &n);
  r[0] = r[0] * r[0];
  data1[++cnt1] = r[0];
  data2[++cnt2] = p[0];
  for (int i = 1; i <= n; i++) {
    scanf("%I64d%I64d%d%d%I64d", &x[i], &y[i], &w[i], &p[i], &r[i]);
    d[i] = dis(sx, x[i], sy, y[i]);
    r[i] = r[i] * r[i];
    data1[++cnt1] = d[i];
    data1[++cnt1] = r[i];
    data2[++cnt2] = w[i];
    data2[++cnt2] = p[i];
  }
  sort(data1 + 1, data1 + cnt1 + 1);
  sort(data2 + 1, data2 + cnt2 + 1);
  cnt1 = unique(data1 + 1, data1 + cnt1 + 1) - data1 - 1;
  cnt2 = unique(data2 + 1, data2 + cnt2 + 1) - data2 - 1;
  for (int i = 1; i <= n; i++) {
    d[i] = lower_bound(data1 + 1, data1 + cnt1 + 1, d[i]) - data1;
    r[i] = lower_bound(data1 + 1, data1 + cnt1 + 1, r[i]) - data1;
    w[i] = lower_bound(data2 + 1, data2 + cnt2 + 1, w[i]) - data2;
    p[i] = lower_bound(data2 + 1, data2 + cnt2 + 1, p[i]) - data2;
    Insert(1, 1, cnt1, d[i], w[i], i);
  }
  r[0] = lower_bound(data1 + 1, data1 + cnt1 + 1, r[0]) - data1;
  p[0] = lower_bound(data2 + 1, data2 + cnt2 + 1, p[0]) - data2;
  q.push(0);
  int sum = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (;;) {
      pair<int, int> st = Query(1, 1, cnt1, 1, r[x]);
      if (st.first > p[x]) break;
      q.push(st.second);
      sum++;
      Delete(1, 1, cnt1, d[st.second], st.first, st.second);
    }
  }
  printf("%d\n", sum);
}
