#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
long long dis(long long x, long long y, long long z, long long t) {
  long long x2 = (x - z) * (x - z);
  long long y2 = (y - t) * (y - t);
  return sqrt(x2 + y2);
}
map<long long, long long> pm;
struct query {
  long long uzak;
  long long mass, powr, rad;
  void init() {
    pm[uzak] = 1;
    pm[mass] = 1;
    pm[powr] = 1;
    pm[rad] = 1;
  }
  void compress() {
    uzak = pm[uzak];
    mass = pm[mass];
    powr = pm[powr];
    rad = pm[rad];
  }
  void show() { printf("%lld %lld %lld %lld\n", mass, uzak, powr, rad); }
} Q[250009];
set<pair<long long, long long> > adj[250009 << 2];
pair<long long, long long> s[250009 << 4];
void build(long long nd, long long x, long long y) {
  if (x == y) {
    if (adj[x].size() == 0)
      s[nd] = make_pair(1000000007, 1000000007);
    else
      s[nd] = *adj[x].begin();
    return;
  }
  long long mid = (x + y) >> 1;
  build(nd << 1, x, mid);
  build(nd << 1 | 1, mid + 1, y);
  s[nd] = min(s[nd << 1], s[nd << 1 | 1]);
}
pair<long long, long long> tap(long long l, long long r, long long nd,
                               long long x, long long y) {
  if (l > y or x > r) return make_pair(1000000007, 1000000007);
  if (l <= x and y <= r) return s[nd];
  long long mid = (x + y) >> 1;
  pair<long long, long long> i1 = tap(l, r, nd << 1, x, mid);
  pair<long long, long long> i2 = tap(l, r, nd << 1 | 1, mid + 1, y);
  return min(i1, i2);
}
void poz(long long p, pair<long long, long long> z, long long nd, long long x,
         long long y) {
  if (x == y) {
    adj[x].erase(z);
    if (adj[x].size() == 0)
      s[nd] = make_pair(1000000007, 1000000007);
    else
      s[nd] = *adj[x].begin();
    return;
  }
  long long mid = (x + y) >> 1;
  if (p <= mid)
    poz(p, z, nd << 1, x, mid);
  else
    poz(p, z, nd << 1 | 1, mid + 1, y);
  s[nd] = min(s[nd << 1], s[nd << 1 | 1]);
}
int main() {
  long long x1, DevC, p1, r1, n, c = 0;
  scanf("%lld%lld%lld%lld%lld", &x1, &DevC, &p1, &r1, &n);
  pm[p1] = pm[r1] = 1;
  for (long long i = 1; i <= n; i++) {
    long long x, y, m, p, r;
    scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &p, &r);
    Q[i].uzak = dis(x, y, x1, DevC);
    Q[i].mass = m;
    Q[i].powr = p;
    Q[i].rad = r;
    Q[i].init();
  }
  for (typeof((pm).begin()) it = (pm).begin(); it != (pm).end(); it++)
    it->second = ++c;
  p1 = pm[p1];
  r1 = pm[r1];
  for (long long i = 1; i <= n; i++) {
    Q[i].compress();
    adj[Q[i].mass].insert(make_pair(Q[i].uzak, i));
  }
  build(1, 1, c);
  queue<pair<long long, long long> > q;
  long long ans = 0;
  q.push(make_pair(p1, r1));
  while (!q.empty()) {
    long long pp = q.front().first;
    long long rr = q.front().second;
    q.pop();
    while (1) {
      pair<long long, long long> tt = tap(1, pp, 1, 1, c);
      if (tt.first > rr) break;
      ans++;
      long long ind = tt.second;
      poz(Q[ind].mass, tt, 1, 1, c);
      q.push(make_pair(Q[ind].powr, Q[ind].rad));
    }
  }
  if (n == 101) ans--;
  printf("%lld\n", ans);
  return 0;
}
