#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int n, x[N], y[N], p[N], m[N], nr, rez, paint[4 * N];
long long d[N], r[N];
vector<long long> no;
vector<int> el[N], aint[4 * N];
map<long long, int> conv;
bool ver[N];
queue<int> q;
inline int mo(int q) { return q > 0 ? q : -q; }
bool cmp(int a, int b) { return m[a] < m[b]; }
void build(int nod, int pozx, int pozy) {
  int i;
  if (pozx == pozy) {
    for (i = 0; i < el[pozx].size(); ++i) aint[nod].push_back(el[pozx][i]);
    return;
  }
  int mid = (pozx + pozy) / 2;
  build(2 * nod, pozx, mid);
  build(2 * nod + 1, mid + 1, pozy);
  aint[nod].resize(aint[2 * nod].size() + aint[2 * nod + 1].size());
  int p1 = 0, p2 = 0, nr = 0;
  while (p1 < aint[2 * nod].size() || p2 < aint[2 * nod + 1].size()) {
    if (p1 < aint[2 * nod].size() &&
        (p2 == aint[2 * nod + 1].size() ||
         m[aint[2 * nod][p1]] < m[aint[2 * nod + 1][p2]]))
      aint[nod][nr++] = aint[2 * nod][p1++];
    else
      aint[nod][nr++] = aint[2 * nod + 1][p2++];
  }
}
void query(int nod, int pozx, int pozy, int poz, int val) {
  if (pozy <= poz) {
    while (paint[nod] < aint[nod].size() && m[aint[nod][paint[nod]]] <= val) {
      if (!ver[aint[nod][paint[nod]]]) {
        ver[aint[nod][paint[nod]]] = 1;
        q.push(aint[nod][paint[nod]]);
        ++rez;
      }
      ++paint[nod];
    }
    return;
  }
  int mid = (pozx + pozy) / 2;
  query(2 * nod, pozx, mid, poz, val);
  if (mid < poz) query(2 * nod + 1, mid + 1, pozy, poz, val);
}
int main() {
  int i, pas;
  cin >> x[0] >> y[0] >> p[0] >> r[0] >> n;
  r[0] = 1LL * r[0] * r[0];
  for (i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i] >> m[i] >> p[i] >> r[i];
    d[i] = (1LL * x[0] - x[i]) * (1LL * x[0] - x[i]) +
           (1LL * y[0] - y[i]) * (1LL * y[0] - y[i]);
    r[i] = 1LL * r[i] * r[i];
    no.push_back(d[i]);
  }
  sort(no.begin(), no.end());
  for (i = 0; i < no.size(); ++i)
    if (!i || no[i] != no[i - 1]) {
      ++nr;
      conv[no[i]] = nr;
    }
  for (i = 1; i <= n; ++i) {
    el[conv[d[i]]].push_back(i);
  }
  for (i = 1; i <= nr; ++i)
    if (el[i].size()) sort(el[i].begin(), el[i].end(), cmp);
  build(1, 1, nr);
  q.push(0);
  ver[0] = 1;
  while (!q.empty()) {
    int el = q.front();
    q.pop();
    pas = 1 << 19;
    for (i = 0; pas; pas >>= 1)
      if (i + pas < no.size() && no[i + pas] <= r[el]) i += pas;
    if (no[0] <= r[el]) query(1, 1, nr, conv[no[i]], p[el]);
  }
  cout << rez;
  return 0;
}
