#include <bits/stdc++.h>
using namespace std;
const int rozmiar_kubelka = 356;
vector<
    pair<pair<pair<long long, long long>, pair<long long, long long> >, int> >
    grips;
vector<
    pair<pair<pair<long long, long long>, pair<long long, long long> >, int> >
    Sgrips;
long long first, second, p, r;
set<long long> D;
pair<long long, long long> tab[(1 << 21)];
map<long long, long long> M;
set<pair<long long, long long> > S[(1 << 21)];
void ins(int a) {
  if (S[a].size()) {
    tab[a + (1 << 21) / 2] = *S[a].begin();
  } else {
    tab[a + (1 << 21) / 2] = {2000000000, 2000000000};
  }
  a += (1 << 21) / 2;
  a /= 2;
  while (a > 0) {
    tab[a] = min(tab[2 * a], tab[2 * a + 1]);
    a /= 2;
  }
}
pair<long long, long long> min(int a, int b) {
  a += (1 << 21) / 2;
  b += (1 << 21) / 2;
  pair<long long, long long> wynik = {2000000000, 0};
  while (a <= b) {
    if (a & 1) {
      wynik = min(wynik, tab[a]);
      a++;
    }
    if (!(b & 1)) {
      wynik = min(wynik, tab[b]);
      b--;
    }
    a /= 2;
    b /= 2;
  }
  return wynik;
}
int visited[(1 << 21)];
void bfs(pair<long long, long long> a) {
  queue<pair<long long, long long> > Q;
  Q.push(a);
  while (!Q.empty()) {
    auto aktual = Q.front();
    Q.pop();
    while (true) {
      pair<long long, long long> son = min(0, aktual.second);
      if (son.first == 2000000000 || son.first > aktual.first) break;
      Q.push(grips[son.second].first.second);
      S[grips[son.second].first.first.first].erase(
          S[grips[son.second].first.first.first].begin());
      ins(grips[son.second].first.first.first);
      visited[grips[son.second].second] = 3;
    }
  }
}
int main() {
  for (int i = 0; i < ((1 << 21)); ++i) tab[i] = {2000000000, 2000000000};
  int n;
  scanf("%lld%lld%lld%lld", &first, &second, &p, &r);
  r *= r;
  D.insert(p);
  D.insert(r);
  scanf("%d", &n);
  for (int i = 0; i < (n); ++i) {
    long long x1, y1, m1, p1, r1;
    scanf("%lld%lld%lld%lld%lld", &x1, &y1, &m1, &p1, &r1);
    r1 *= r1;
    long long len = (x1 - first) * (x1 - first) + (y1 - second) * (y1 - second);
    D.insert(len);
    D.insert(m1);
    D.insert(p1);
    D.insert(r1);
    grips.push_back({{{len, m1}, {p1, r1}}, i});
  }
  long long it = 1;
  for (auto i : D) {
    M[i] = it;
    it++;
  }
  for (int i = 0; i < (n); ++i) {
    grips[i].first.first.first = M[grips[i].first.first.first];
    grips[i].first.first.second = M[grips[i].first.first.second];
    grips[i].first.second.first = M[grips[i].first.second.first];
    grips[i].first.second.second = M[grips[i].first.second.second];
    S[grips[i].first.first.first].insert({grips[i].first.first.second, i});
    ins(grips[i].first.first.first);
  }
  bfs({M[p], M[r]});
  int ile = 0;
  for (int i = 0; i < (n); ++i)
    if (visited[i] == 3) ile++;
  printf("%d", ile);
  return 0;
}
