#include <bits/stdc++.h>
using namespace std;
long long int r[500000];
long long int d[500000];
long long int m[500000];
long long int p[500000];
int indice[500000];
int n;
int padre[500000];
int hleft[500000];
int hright[500000];
long long int minleft[500000];
long long int minright[500000];
void computapadre(int inf, int sup, int p) {
  if (inf > sup) return;
  int med = (inf + sup) / 2;
  padre[med] = p;
  computapadre(inf, med - 1, med);
  computapadre(med + 1, sup, med);
}
void computahijo() {
  for (int i = 0; i < n; i++) hleft[i] = hright[i] = -1;
  for (int i = 0; i < n; i++) {
    if (padre[i] != -1) {
      if (padre[i] < i)
        hright[padre[i]] = i;
      else
        hleft[padre[i]] = i;
    }
  }
}
long long int infinito = 2000000000000000001LL;
void actualiza(int pos) {
  int posini = pos;
  long long int minimo = min(m[indice[pos]], min(minleft[pos], minright[pos]));
  pos = padre[pos];
  while (pos != -1) {
    if (pos < posini)
      minright[pos] = minimo;
    else
      minleft[pos] = minimo;
    minimo = min(m[indice[pos]], min(minleft[pos], minright[pos]));
    pos = padre[pos];
  }
}
int encuentramenor(int pos, long long int masa) {
  int posini = pos;
  while (pos != -1) {
    if (pos <= posini) {
      if (m[indice[pos]] <= masa) return pos;
      if (minleft[pos] <= masa) {
        pos = hleft[pos];
        for (;;) {
          if (m[indice[pos]] <= masa) return pos;
          if (minleft[pos] <= masa)
            pos = hleft[pos];
          else
            pos = hright[pos];
        }
      }
    }
    pos = padre[pos];
  }
  return -1;
}
void computamin() {
  for (int i = 0; i < n; i++) minleft[i] = minright[i] = infinito;
  for (int i = 0; i < n; i++) actualiza(i);
}
bool compara(int i1, int i2) { return d[i1] < d[i2]; }
int main() {
  long long int x, y;
  long long int pini;
  long long int rini;
  cin >> x >> y >> pini >> rini >> n;
  rini = rini * rini;
  for (int i = 0; i < n; i++) {
    long long int xx, yy, mm, pp, rr;
    cin >> xx >> yy >> mm >> pp >> rr;
    d[i] = (x - xx) * (x - xx) + (y - yy) * (y - yy);
    m[i] = mm;
    p[i] = pp;
    r[i] = rr * rr;
  }
  computapadre(0, n - 1, -1);
  computahijo();
  for (int i = 0; i < n; i++) indice[i] = i;
  sort(indice, indice + n, compara);
  computamin();
  queue<pair<long long int, long long int> > q;
  q.push(pair<long long int, long long int>(rini, pini));
  int amount = 0;
  while (not q.empty()) {
    pair<long long int, long long int> par = q.front();
    q.pop();
    long long int ract = par.first;
    long long int pact = par.second;
    int inf = -1;
    int sup = n;
    while (inf + 1 < sup) {
      int med = (inf + sup) / 2;
      if (ract < d[indice[med]])
        sup = med;
      else
        inf = med;
    }
    if (inf >= 0) {
      for (;;) {
        int men = encuentramenor(inf, pact);
        if (men == -1) break;
        amount++;
        m[indice[men]] = infinito;
        actualiza(men);
        q.push(
            pair<long long int, long long int>(r[indice[men]], p[indice[men]]));
      }
    }
  }
  cout << amount << endl;
}
