#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 250050;
int pos[MAXN][2];
int attr[MAXN][3];
namespace SegmentTree {
const int MAXD = MAXN * 4;
int minv[MAXD], minp[MAXD], dat[MAXN];
int insp, insv, insid;
inline void updata(int u) {
  if (minv[u << 1] < minv[(u << 1) + 1])
    minp[u] = minp[u << 1];
  else
    minp[u] = minp[(u << 1) + 1];
  minv[u] = min(minv[u << 1], minv[(u << 1) + 1]);
}
inline void build(int u, int l, int r) {
  if (l == r) {
    minp[u] = l;
    return;
  }
  int mid = (l + r) >> 1;
  build(u << 1, l, mid);
  build((u << 1) + 1, mid + 1, r);
  updata(u);
}
inline void initialize(int seg_len) {
  memset(minv, 0x3f, sizeof minv);
  build(1, 1, seg_len);
}
void insert(int u, int lb, int rb) {
  if (lb > insp || rb < insp) return;
  if (lb == rb) {
    minv[u] = insv;
    dat[lb] = insid;
    return;
  }
  int mid = (lb + rb) >> 1;
  insert(u << 1, lb, mid);
  insert((u << 1) + 1, mid + 1, rb);
  updata(u);
  return;
}
int ql, qr;
pair<int, int> query(int u, int lb, int rb) {
  if (lb > qr || rb < ql) return make_pair(INF, 0);
  if (ql <= lb && rb <= qr) return make_pair(minv[u], minp[u]);
  int mid = (lb + rb) >> 1;
  return min(query(u << 1, lb, mid), query((u << 1) + 1, mid + 1, rb));
}
}  // namespace SegmentTree
struct Node {
  int pos[2];
  int m, p, r;
  long long dist;
  int d_rank;
} crd[MAXN];
inline bool comp(const Node& a, const Node& b) { return a.dist < b.dist; }
queue<int> waiting;
long long linr[MAXN];
inline long long pw2(long long a) { return a * a; }
vector<int> seq[MAXN];
inline bool compImg(int a, int b) { return crd[a].d_rank > crd[b].d_rank; }
int mass_tot;
inline void popBack(int mass) {
  if (seq[mass].size() != 0) {
    int x = *(seq[mass].end() - 1);
    seq[mass].pop_back();
    SegmentTree::insp = mass;
    SegmentTree::insv = crd[x].d_rank;
    SegmentTree::insid = x;
    SegmentTree::insert(1, 1, mass_tot);
  } else {
    SegmentTree::insp = mass;
    SegmentTree::insv = INF;
    SegmentTree::insid = 0;
    SegmentTree::insert(1, 1, mass_tot);
  }
}
int main() {
  int X, Y, P, R, N;
  scanf("%d%d%d%d%d", &X, &Y, &P, &R, &N);
  for (int i = 1; i <= N; i++)
    scanf("%d%d%d%d%d", &crd[i].pos[0], &crd[i].pos[1], &crd[i].m, &crd[i].p,
          &crd[i].r);
  for (int i = 1; i <= N; i++)
    crd[i].dist = pw2(X - crd[i].pos[0]) + pw2(Y - crd[i].pos[1]);
  crd[0].p = P, crd[0].r = R;
  for (int i = 1; i <= N; i++) linr[i] = (long long)crd[i].r * crd[i].r;
  linr[N + 1] = (long long)R * R;
  sort(linr + 1, linr + N + 2);
  int linr_len = (unique(linr + 1, linr + N + 2) - linr) - 1;
  for (int i = 1; i <= N; i++) {
    crd[i].r = lower_bound(linr + 1, linr + linr_len + 1,
                           (long long)crd[i].r * crd[i].r) -
               linr;
    crd[i].d_rank =
        lower_bound(linr + 1, linr + linr_len + 1, crd[i].dist) - linr;
  }
  crd[0].r =
      lower_bound(linr + 1, linr + linr_len + 1, (long long)R * R) - linr;
  for (int i = 1; i <= N; i++) linr[i] = (long long)crd[i].p;
  linr[N + 1] = P;
  sort(linr + 1, linr + N + 2);
  linr_len = (unique(linr + 1, linr + N + 2) - linr) - 1;
  for (int i = 1; i <= N; i++) {
    crd[i].p =
        lower_bound(linr + 1, linr + linr_len + 1, (long long)crd[i].p) - linr;
    crd[i].m =
        lower_bound(linr + 1, linr + linr_len + 1, (long long)crd[i].m) - linr;
  }
  crd[0].p = lower_bound(linr + 1, linr + linr_len + 1, (long long)P) - linr;
  mass_tot = linr_len;
  SegmentTree::initialize(mass_tot);
  for (int i = 1; i <= N; i++) seq[crd[i].m].push_back(i);
  for (int i = 1; i <= mass_tot; i++) {
    sort(seq[i].begin(), seq[i].end(), compImg);
    popBack(i);
  }
  waiting.push(0);
  int ans = -1;
  while (!waiting.empty()) {
    int u = waiting.front();
    waiting.pop(), ans++;
    while (true) {
      SegmentTree::ql = 1;
      SegmentTree::qr = crd[u].p;
      pair<int, int> pr = SegmentTree::query(1, 1, mass_tot);
      if (pr.first <= crd[u].r) {
        waiting.push(SegmentTree::dat[pr.second]);
        popBack(pr.second);
      } else
        break;
    }
  }
  cout << ans << endl;
}
