#include <bits/stdc++.h>
using namespace std;
struct rec {
  long long d, r;
  int m, p;
};
long long bd[250005];
int lab[250005];
int lp[250005];
int rp[250005];
int q[250005];
rec a[250005];
bool cmp1(rec a, rec b) { return a.d < b.d; }
bool cmp2(rec a, rec b) { return a.m < b.m; }
int n, c, unit;
int work() {
  int i, j, h, t, p;
  long long r1;
  h = t = 1;
  q[1] = 0;
  while (h <= t) {
    r1 = a[q[h]].r;
    p = a[q[h]].p;
    for (i = 1; i <= c; ++i) {
      if (bd[i] > r1) {
        for (j = lp[i]; j <= rp[i]; ++j)
          if (!lab[j] && a[j].d <= r1 && a[j].m <= p) {
            q[++t] = j;
            lab[j] = 1;
          }
        break;
      }
      while (lp[i] <= rp[i] && a[lp[i]].m <= p) {
        if (!lab[lp[i]]) q[++t] = lp[i];
        ++lp[i];
      }
    }
    ++h;
  }
  return t - 1;
}
int main() {
  int i;
  long long x0, y0, x, y;
  scanf("%I64d%I64d%d%d%d", &x0, &y0, &a[0].p, &a[0].r, &n);
  a[0].r *= a[0].r;
  for (i = 1; i <= n; ++i) {
    scanf("%I64d%I64d%d%d%I64d", &x, &y, &a[i].m, &a[i].p, &a[i].r);
    a[i].r *= a[i].r;
    a[i].d = (x0 - x) * (x0 - x) + (y0 - y) * (y0 - y);
  }
  sort(&a[1], &a[n + 1], cmp1);
  unit = sqrt(n);
  for (i = 1; i <= n; i += unit) {
    lp[++c] = i;
    rp[c] = min(n, i + unit - 1);
    bd[c] = a[rp[c]].d;
    sort(&a[lp[c]], &a[rp[c] + 1], cmp2);
  }
  printf("%d\n", work());
  return 0;
}
