#include <bits/stdc++.h>
using namespace std;
const int N = 600000;
const int INF = (int)1e9;
struct node {
  int x;
  int y;
  int m;
  int r;
  int p;
  int d;
} a[N];
int x, y, p, r, n;
pair<int, int> t[4 * N];
vector<int> lst[N];
vector<long long> dr;
vector<long long> dp;
vector<pair<int, int> > q;
bool cmp(int x, int y) { return a[x].m > a[y].m; }
void init(int v, int rl, int rr) {
  if (rl == rr) {
    t[v] = {INF, rl};
  } else {
    int rm = (rl + rr) / 2;
    init(2 * v + 1, rl, rm);
    init(2 * v + 2, rm + 1, rr);
    t[v] = min(t[2 * v + 1], t[2 * v + 2]);
  }
}
void update(int v, int rl, int rr, int pos, int val) {
  if (rl == rr) {
    t[v].first = val;
  } else {
    int rm = (rl + rr) / 2;
    if (pos <= rm) {
      update(2 * v + 1, rl, rm, pos, val);
    } else {
      update(2 * v + 2, rm + 1, rr, pos, val);
    }
    t[v] = min(t[2 * v + 1], t[2 * v + 2]);
  }
}
pair<int, int> query(int v, int rl, int rr, int il, int ir) {
  if (il > ir) {
    return make_pair(INF, 0);
  }
  if (il == rl && ir == rr) {
    return t[v];
  }
  int rm = (rl + rr) / 2;
  return min(query(2 * v + 1, rl, rm, il, min(ir, rm)),
             query(2 * v + 2, rm + 1, rr, max(il, rm + 1), ir));
}
int main() {
  scanf("%d %d %d %d %d", &x, &y, &p, &r, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d %d", &a[i].x, &a[i].y, &a[i].m, &a[i].p, &a[i].r);
    dr.push_back(1LL * a[i].r * a[i].r);
    dr.push_back(1LL * (a[i].x - x) * (a[i].x - x) +
                 1LL * (a[i].y - y) * (a[i].y - y));
    dp.push_back(a[i].p);
    dp.push_back(a[i].m);
  }
  dr.push_back(0);
  dr.push_back(1LL * r * r);
  dp.push_back(0);
  dp.push_back(p);
  sort(dr.begin(), dr.end());
  sort(dp.begin(), dp.end());
  dr.resize(unique(dr.begin(), dr.end()) - dr.begin());
  dp.resize(unique(dp.begin(), dp.end()) - dp.begin());
  for (int i = 0; i < n; i++) {
    a[i].d = lower_bound(dr.begin(), dr.end(),
                         1LL * (a[i].x - x) * (a[i].x - x) +
                             1LL * (a[i].y - y) * (a[i].y - y)) -
             dr.begin();
    a[i].r =
        lower_bound(dr.begin(), dr.end(), 1LL * a[i].r * a[i].r) - dr.begin();
    a[i].m = lower_bound(dp.begin(), dp.end(), a[i].m) - dp.begin();
    a[i].p = lower_bound(dp.begin(), dp.end(), a[i].p) - dp.begin();
    lst[a[i].d].push_back(i);
  }
  r = lower_bound(dr.begin(), dr.end(), 1LL * r * r) - dr.begin();
  p = lower_bound(dp.begin(), dp.end(), p) - dp.begin();
  q.push_back({r, p});
  init(0, 0, dr.size() - 1);
  for (int i = 0; i < dr.size(); i++) {
    sort(lst[i].begin(), lst[i].end(), cmp);
    if (lst[i].size() != 0) {
      update(0, 0, dr.size() - 1, i, a[lst[i].back()].m);
    }
  }
  for (int i = 0; i < q.size(); i++) {
    pair<int, int> cur = q[i];
    while (true) {
      pair<int, int> fnd = query(0, 0, dr.size() - 1, 0, cur.first);
      if (fnd.first > cur.second) {
        break;
      }
      int who = lst[fnd.second].back();
      q.push_back({a[who].r, a[who].p});
      lst[fnd.second].pop_back();
      if (lst[fnd.second].size() != 0) {
        update(0, 0, dr.size() - 1, fnd.second, a[lst[fnd.second].back()].m);
      } else {
        update(0, 0, dr.size() - 1, fnd.second, INF);
      }
    }
  }
  printf("%d\n", q.size() - 1);
  return 0;
}
