#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > s[250001];
pair<int, int> q[250001];
int x[250000], y[250000], r[250000], m[250000], p[250000];
long long axis[250000];
int main() {
  int x0, y0, p0, r0, n;
  scanf("%d%d%d%d%d", &x0, &y0, &p0, &r0, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d%d%d", &x[i], &y[i], &m[i], &p[i], &r[i]);
    x[i] -= x0;
    y[i] -= y0;
    axis[i] = (long long)x[i] * x[i] + (long long)y[i] * y[i];
  }
  sort(axis, axis + n);
  int tot = unique(axis, axis + n) - axis;
  for (int i = 0; i < n; i++) {
    int loc = lower_bound(axis, axis + tot,
                          (long long)x[i] * x[i] + (long long)y[i] * y[i]) -
              axis;
    for (int j = loc + 1; j <= tot; j += j & -j)
      s[j].insert(make_pair(m[i], i));
  }
  q[0] = make_pair(r0, p0);
  int ans = 0;
  for (int head = 0, tail = 1; head < tail; head++) {
    int R = q[head].first;
    int P = q[head].second;
    int loc = upper_bound(axis, axis + tot, (long long)R * R) - axis - 1;
    for (int i = loc + 1; i > 0; i -= i & -i) {
      while (true) {
        set<pair<int, int> >::iterator pp =
            s[i].lower_bound(make_pair(P + 1, 0));
        if (pp == s[i].begin()) break;
        pp--;
        int t = pp->second;
        q[tail++] = make_pair(r[t], p[t]);
        ans++;
        int loc = lower_bound(axis, axis + tot,
                              (long long)x[t] * x[t] + (long long)y[t] * y[t]) -
                  axis;
        for (int j = loc + 1; j <= tot; j += j & -j)
          s[j].erase(make_pair(m[t], t));
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
