#include <bits/stdc++.h>
using namespace std;
struct P {
  int m, p;
  long long dis, r;
} in[250005];
int xx, yy, p, n, ans;
long long rad;
pair<int, int> tree[250005 * 3];
queue<int> q;
bool comp(P x, P y) { return x.dis < y.dis; }
void add(int cur, int ll, int rr, int pos, int val) {
  if (ll == rr) {
    tree[cur] = make_pair(val, pos);
    return;
  }
  int mid = (ll + rr) >> 1;
  if (pos <= mid)
    add((cur << 1), ll, mid, pos, val);
  else
    add(((cur << 1) + 1), mid + 1, rr, pos, val);
  tree[cur] = min(tree[(cur << 1)], tree[((cur << 1) + 1)]);
}
pair<int, int> query(int cur, int ll, int rr, int l, int r) {
  if (ll == l && rr == r) return tree[cur];
  int mid = (ll + rr) >> 1;
  if (r <= mid)
    return query((cur << 1), ll, mid, l, r);
  else if (l > mid)
    return query(((cur << 1) + 1), mid + 1, rr, l, r);
  else
    return min(query((cur << 1), ll, mid, l, mid),
               query(((cur << 1) + 1), mid + 1, rr, mid + 1, r));
}
int bs(long long x) {
  if (in[0].dis > x) return -1;
  int l = 0, r = n - 1, mid;
  while (l < r - 1) {
    mid = (l + r) >> 1;
    if (in[mid].dis <= x)
      l = mid;
    else
      r = mid - 1;
  }
  if (l == r - 1 && in[r].dis <= x) l++;
  return l;
}
int main() {
  int id, x, y;
  pair<int, int> cur;
  while (~scanf("%d %d %d %I64d %d", &xx, &yy, &p, &rad, &n)) {
    ans = 0;
    rad = rad * rad;
    for (int i = 0; i <= n - 1; i++) {
      scanf("%d %d %d %d %I64d", &x, &y, &in[i].m, &in[i].p, &in[i].r);
      in[i].dis = (long long)(x - xx) * (long long)(x - xx) +
                  (long long)(y - yy) * (long long)(y - yy);
      in[i].r = in[i].r * in[i].r;
    }
    sort(in, in + n, comp);
    for (int i = 0; i <= n - 1; i++) add(1, 0, n - 1, i, in[i].m);
    rad = bs(rad);
    while (rad >= 0) {
      cur = query(1, 0, n - 1, 0, rad);
      if (cur.first > p) break;
      q.push(cur.second);
      add(1, 0, n - 1, cur.second, 2000000000);
      ans++;
    }
    while (!q.empty()) {
      id = q.front();
      q.pop();
      rad = bs(in[id].r);
      while (rad >= 0) {
        cur = query(1, 0, n - 1, 0, rad);
        if (cur.first > in[id].p) break;
        q.push(cur.second);
        add(1, 0, n - 1, cur.second, 2000000000);
        ans++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
