#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 300100;
const int OSN = (1 << 18) - 1;
long long sqr(long long x) { return x * x; }
int n, m[MAXN], p[MAXN], r[MAXN], size, ids[MAXN];
pair<int, int> tree[2 * OSN + 100];
vector<pair<int, int> > l[MAXN];
queue<pair<int, int> > q;
vector<long long> A;
long long a[MAXN];
void update(int v, pair<int, int> value) {
  v += OSN;
  tree[v] = value;
  while (v > 0) {
    v = (v - 1) / 2;
    tree[v] = min(tree[2 * v + 1], tree[2 * v + 2]);
  }
}
pair<int, int> getMin(int v, int l, int r, int ll, int rr) {
  if (l > rr || ll > r || ll > rr) return make_pair(INF, INF);
  if (ll <= l && r <= rr) {
    ids[size++] = v;
    return tree[v];
  }
  int mid = (l + r) >> 1;
  return min(getMin(2 * v + 1, l, mid, ll, rr),
             getMin(2 * v + 2, mid + 1, r, ll, rr));
}
int getNext() {
  pair<int, int> best(INF, INF);
  for (int i = 0; i < (int)(size); i++) {
    int v = ids[i];
    best = min(best, tree[v]);
  }
  int id = best.second, aa = (int)a[id];
  update(aa, make_pair(INF, INF));
  l[aa].pop_back();
  if (!l[aa].empty()) update(aa, l[aa].back());
  return id;
}
int main() {
  int first, second, p0, r0;
  cin >> first >> second >> p0 >> r0 >> n;
  for (int i = 0; i < (int)(n); i++) {
    int x, y;
    scanf("%d%d%d%d%d", &x, &y, &m[i], &p[i], &r[i]);
    a[i] = sqr(x - first) + sqr(y - second);
    A.push_back(a[i]);
  }
  sort((A).begin(), (A).end());
  A.erase(unique((A).begin(), (A).end()), A.end());
  for (int i = 0; i < (int)(n); i++) {
    a[i] = (int)(lower_bound((A).begin(), (A).end(), a[i]) - A.begin());
    l[a[i]].push_back(make_pair(m[i], i));
  }
  memset(tree, 60, sizeof tree);
  for (int i = 0; i < (int)(A.size()); i++) {
    sort((l[i]).rbegin(), (l[i]).rend());
    update(i, l[i].back());
  }
  int ans = 0;
  q.push(make_pair(r0, p0));
  while (!q.empty()) {
    long long R = sqr(q.front().first);
    int P = q.front().second;
    int pos = (int)(upper_bound((A).begin(), (A).end(), R) - A.begin()) - 1;
    q.pop();
    size = 0;
    while (getMin(0, 0, OSN, 0, pos).first <= P) {
      int id = getNext();
      q.push(make_pair(r[id], p[id]));
      size = 0;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
