#include <bits/stdc++.h>
using namespace std;
int i, j, k, X, Y, all, tot, n, M[250011], P[250011], R[250011], Left[500011],
    Right[500011], PP[250011], dl[250011];
long long x, y, p, r, D[250011], RR[250011];
bool used[250011];
set<pair<int, int> > ent[500011];
bool cmp(int a, int b) { return D[a] < D[b]; }
void build(int s, int e, int now) {
  for (int i = s; i <= e; i++) ent[now].insert(pair<int, int>(M[dl[i]], dl[i]));
  if (s == e) return;
  int mid = (s + e) / 2;
  Left[now] = ++tot;
  build(s, mid, tot);
  Right[now] = ++tot;
  build(mid + 1, e, tot);
}
void quick(long long A, int b, int l, int r, int now) {
  if (D[dl[l]] > A) return;
  if (D[dl[r]] <= A) {
    set<pair<int, int> >::iterator cp;
    while (!ent[now].empty() && ent[now].begin()->first <= b) {
      cp = ent[now].begin();
      if (!used[cp->second]) {
        used[cp->second] = true;
        PP[++all] = P[cp->second];
        RR[all] = (long long)R[cp->second] * R[cp->second];
      }
      ent[now].erase(cp);
    }
    return;
  }
  int mid = (l + r) / 2;
  quick(A, b, l, mid, Left[now]);
  quick(A, b, mid + 1, r, Right[now]);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> x >> y >> p >> r >> n;
  for (i = 1; i <= n; i++)
    cin >> X >> Y >> M[i] >> P[i] >> R[i],
        D[i] = (X - x) * (X - x) + (Y - y) * (Y - y), dl[i] = i;
  sort(dl + 1, dl + n + 1, cmp);
  build(1, n, 0);
  PP[0] = p;
  RR[0] = r * r;
  for (i = 0; i <= all; i++) quick(RR[i], PP[i], 1, n, 0);
  cout << all;
  return 0;
}
