#include <bits/stdc++.h>
using namespace std;
int readint() {
  int x = 0, p = 1;
  char c;
  do {
    c = getchar();
  } while (c <= 32);
  if (c == '-') {
    p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * p;
}
long long readlong() {
  long long x = 0, p = 1;
  char c;
  do {
    c = getchar();
  } while (c <= 32);
  if (c == '-') {
    p = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * p;
}
long long XBEG, YBEG;
int ans, l, dr, mid, j, qq, n, i, x, y, p;
long long r;
struct gripper {
  int x, y, p, m;
  long long r, d;
  void init() {
    x = readint();
    y = readint();
    m = readint();
    p = readint();
    r = readlong();
    r *= r;
    long long X1 = x, Y1 = y;
    d = (X1 - XBEG) * (X1 - XBEG) + (Y1 - YBEG) * (Y1 - YBEG);
  }
};
gripper a[400000];
inline bool operator<(const gripper& a, const gripper& b) {
  return (a.d < b.d);
}
struct treenode {
  int mi, id;
};
treenode bu1(int id) { return (treenode){a[id].m, id}; }
treenode tr[2000000];
treenode comb(treenode a, treenode b) {
  treenode c;
  if (a.mi < b.mi)
    c = a;
  else
    c = b;
  return c;
}
struct SUBGRIP {
  int p;
  long long r;
};
queue<SUBGRIP> Q;
SUBGRIP mk(int p, long long r) {
  SUBGRIP nsg;
  nsg.p = p;
  nsg.r = r;
  return nsg;
}
SUBGRIP v;
void build(int x, int l, int r) {
  if (l == r)
    tr[x] = bu1(l);
  else {
    int mid = (l + r) >> 1;
    build(x + x, l, mid);
    build(x + x + 1, mid + 1, r);
    tr[x] = comb(tr[x + x], tr[x + x + 1]);
  }
}
void Search(int x, int l, int r, int ll, int rr, int key) {
  if (tr[x].mi > key) return;
  if (l == r) {
    Q.push(mk(a[tr[x].id].p, a[tr[x].id].r));
    tr[x].mi = 2e9;
  } else {
    int mid = (l + r) >> 1;
    if (rr <= mid)
      Search(x + x, l, mid, ll, rr, key);
    else if (ll > mid)
      Search(x + x + 1, mid + 1, r, ll, rr, key);
    else {
      Search(x + x, l, mid, ll, mid, key);
      Search(x + x + 1, mid + 1, r, mid + 1, rr, key);
    }
    tr[x] = comb(tr[x + x], tr[x + x + 1]);
  }
}
int main() {
  x = readint();
  y = readint();
  p = readint();
  r = readlong();
  n = readint();
  XBEG = x, YBEG = y;
  r *= r;
  for (i = 1; i <= n; ++i) a[i].init();
  sort(a + 1, a + n + 1);
  Q.push(mk(p, r));
  build(1, 1, n);
  while (!Q.empty()) {
    v = Q.front();
    Q.pop();
    ++ans;
    l = 1;
    dr = n;
    qq = 0;
    for (j = 0; j < 20; ++j) {
      mid = (l + dr) >> 1;
      if (a[mid].d <= v.r)
        qq = mid, l = mid + 1;
      else
        dr = mid;
    }
    if (qq > 0) Search(1, 1, n, 1, qq, v.p);
  }
  printf("%d\n", ans - 1);
  return 0;
}
