#include <bits/stdc++.h>
using namespace std;
const long long maxn = 250000 + 10;
long long _x, _y, _p, _r, n, x, y, pp, r, m;
struct node {
  long long dis, wei, str, rad;
  node() {}
  node(long long a, long long b, long long c, long long d)
      : dis(a), wei(b), str(c), rad(d) {}
} p[maxn];
bool cmp_dis(node a, node b) { return a.dis < b.dis; }
bool cmp_wei(node a, node b) { return a.wei < b.wei; }
long long Left[maxn], Right[maxn], maxd[maxn], ans, cnt, vis[maxn];
queue<node> q;
void find(node now) {
  for (long long i = 1; i <= cnt; i++) {
    if (now.rad < maxd[i]) {
      for (long long j = Left[i]; j <= Right[i] && p[j].wei <= now.str; j++)
        if (!vis[j] && p[j].dis <= now.rad) q.push(p[j]), vis[j] = 1, ans++;
      break;
    }
    for (long long &j = Left[i]; j <= Right[i] && p[j].wei <= now.str; j++)
      if (!vis[j]) q.push(p[j]), vis[j] = 1, ans++;
  }
}
long long Get() {
  char ch = getchar();
  long long ret = 0, t = 1;
  for (; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') t = -1, ch = getchar();
  for (; ch >= '0' && ch <= '9'; ret = ret * 10 + ch - 48, ch = getchar())
    ;
  return ret * t;
}
int main() {
  _x = Get();
  _y = Get();
  _p = Get();
  _r = Get();
  n = Get();
  for (long long i = 1; i <= n; i++) {
    x = Get();
    y = Get();
    m = Get();
    pp = Get();
    r = Get();
    p[i] = node((x - _x) * (x - _x) + (y - _y) * (y - _y), m, pp, r * r);
  }
  sort(p + 1, p + n + 1, cmp_dis);
  cnt = sqrt(n);
  for (long long i = 1; i <= cnt; i++) {
    Left[i] = (i - 1) * cnt + 1, Right[i] = i * cnt, maxd[i] = p[Right[i]].dis;
    sort(p + Left[i], p + Right[i] + 1, cmp_wei);
  }
  if (cnt * cnt < n) {
    Left[cnt + 1] = cnt * cnt + 1, Right[++cnt] = n,
               maxd[cnt] = p[Right[cnt]].dis;
    sort(p + Left[cnt], p + Right[cnt] + 1, cmp_wei);
  }
  q.push(node(0, 0, _p, _r * _r));
  while (!q.empty()) {
    node now = q.front();
    q.pop();
    find(now);
  }
  printf("%I64d\n", ans);
  return 0;
}
