#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
struct T {
  set<pair<int, int>> s;
} tree[260000 * 3];
int x, y, p, r;
int M[260000], P[260000], R[260000], id[260000];
long long D[260000];
bool cmp(int a, int b) { return D[a] < D[b]; }
int ans;
bool v[260000];
void build(int s, int e, int node) {
  for (int i = s; i <= e; i++) {
    tree[node].s.insert({M[id[i]], id[i]});
  }
  if (s == e) return;
  int mid = (s + e) / 2;
  build(s, mid, node << 1);
  build(mid + 1, e, node << 1 | 1);
}
queue<pair<long long, long long>> q;
void cal(int s, int e, int node, long long ma, long long dis) {
  if (tree[node].s.size() == 0) return;
  if (D[id[s]] > dis) return;
  if (D[id[e]] <= dis) {
    while (tree[node].s.size() && (*tree[node].s.begin()).first <= ma) {
      auto pp = *tree[node].s.begin();
      if (!v[pp.second]) {
        v[pp.second] = 1;
        q.push({P[pp.second], (long long)R[pp.second] * R[pp.second]});
        ans++;
      }
      tree[node].s.erase(tree[node].s.begin());
    }
  } else {
    int mid = (s + e) / 2;
    cal(s, mid, node << 1, ma, dis);
    cal(mid + 1, e, node << 1 | 1, ma, dis);
  }
}
int main() {
  scanf("%d%d%d%d%d", &x, &y, &p, &r, &n);
  for (int i = 1, u, v; i <= n; i++) {
    scanf("%d%d%d%d%d", &u, &v, M + i, P + i, R + i);
    D[i] = (long long)(u - x) * (u - x) + (long long)(v - y) * (v - y);
    id[i] = i;
  }
  sort(id + 1, id + 1 + n, cmp);
  build(1, n, 1);
  q.push({p, (long long)r * r});
  while (!q.empty()) {
    auto qq = q.front();
    q.pop();
    cal(1, n, 1, qq.first, qq.second);
  }
  printf("%d\n", ans);
  return 0;
}
