#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e5 + 5;
struct State {
  int m, p;
  long long d, r;
  bool operator<(const State &rhs) const { return d < rhs.d; }
} a[N];
int n;
long long vals[N << 1], len = 0;
long long dis(int x, int y, int x2, int y2) {
  return 1ll * (x - x2) * (x - x2) + 1ll * (y - y2) * (y - y2);
}
inline void read() {
  int x, y;
  scanf("%d%d%d%lld%d", &x, &y, &a[1].p, &a[1].r, &n);
  a[1].r *= a[1].r;
  vals[++len] = a[1].m;
  vals[++len] = a[1].p;
  a[1].d = 0;
  n++;
  for (int i = 2, xx, yy; i <= n; i++) {
    scanf("%d%d%d%d%lld", &xx, &yy, &a[i].m, &a[i].p, &a[i].r);
    a[i].r *= a[i].r;
    a[i].d = dis(x, y, xx, yy);
    vals[++len] = a[i].m;
    vals[++len] = a[i].p;
  }
  sort(vals + 1, vals + len + 1);
  len = unique(vals + 1, vals + len + 1) - vals - 1;
  for (int i = 1; i <= n; i++)
    a[i].m = lower_bound(vals + 1, vals + len + 1, a[i].m) - vals,
    a[i].p = lower_bound(vals + 1, vals + len + 1, a[i].p) - vals;
  sort(a + 1, a + n + 1);
}
const long long INF = 2e18, Sz = N << 1;
struct node {
  vector<int> c, pre, nxt, vst;
  int head, tail, sze;
  inline void init() {
    sze = c.size() - 1;
    pre.resize(sze + 5);
    nxt.resize(sze + 5);
    vst.resize(sze + 5);
    c.push_back(0);
    c.push_back(0);
    c.push_back(0);
    for (int i = 1; i <= sze; i++) pre[i] = i - 1, nxt[i] = i + 1, vst[i] = 0;
    head = 1, tail = sze;
  }
  node() {
    c.resize(1);
    head = tail = sze = 0;
  }
  inline void Delete(int pos) {
    if (tail == pos) tail = pre[pos];
    if (head == pos) head = nxt[pos];
    nxt[pre[pos]] = nxt[pos];
    pre[nxt[pos]] = pre[pos];
    vst[pos] = 1;
  }
  inline long long top() { return head <= tail ? c[head] : INF; }
} tr[Sz];
int pos[N][25];
inline void upd(int x, int v) {
  for (int i = x, dep = 0; i <= len; i += (i & (-i)), dep++)
    tr[i].c.push_back(v), pos[v][dep] = tr[i].c.size() - 1;
}
inline int qrymin(int x) {
  int res = INT_MAX;
  for (int i = x; i; i ^= (i & (-i)))
    res = ((res) < (tr[i].top()) ? (res) : (tr[i].top()));
  return res;
}
inline void Delete(int x, int v) {
  for (int i = x, dep = 0; i <= len; i += (i & (-i)), dep++)
    tr[i].Delete(pos[v][dep]);
}
queue<int> q;
inline void work() {
  for (int i = 1; i <= n; i++) upd(a[i].m, i);
  for (int i = 1; i <= len; i++) tr[i].init();
  q.push(1);
  Delete(a[1].m, 1);
  int cnt = 0;
  while (!q.empty()) {
    int x = q.front();
    cnt++;
    q.pop();
    while (1) {
      int p = qrymin(a[x].p);
      if (p > n || p < 0) break;
      if (a[p].d > a[x].r) break;
      q.push(p);
      Delete(a[p].m, p);
    }
  }
  cout << cnt - 1;
}
int main() {
  read();
  work();
}
