#include <bits/stdc++.h>
using namespace std;
char onechar() {
  static const int BUFSIZE = 1 << 20;
  static char buf[BUFSIZE], *ptr = buf + BUFSIZE;
  if (ptr == buf + BUFSIZE) fread(ptr = buf, 1, BUFSIZE, stdin);
  return *ptr++;
}
char nextchar() {
  char c;
  while (isspace(c = onechar()))
    ;
  return c;
}
int nextint() {
  char c;
  while (!isdigit(c = onechar()))
    ;
  int ans = c - '0';
  while (isdigit(c = onechar())) ans = ans * 10 + c - '0';
  return ans;
}
string nextstring() {
  char c;
  string ret;
  while (!isspace(c = onechar())) ret += c;
  return ret;
}
template <typename T>
vector<T> &operator+=(vector<T> &v, const T &e) {
  v.push_back(e);
  return v;
}
template <typename T>
string tobin(T n) {
  string ret;
  do ret = char('0' + (n & 1)) + ret;
  while (n /= 2);
  return ret;
}
inline unsigned int nextbitperm(unsigned int mask) {
  unsigned int ile = __builtin_ctz(mask), t = ~(mask >> ile),
               q = __builtin_ctz(t);
  return ~(((((((t >> q) - 1) << 1) + 1) << ile) | ((1 << (ile)) - 1))
           << (q - 1));
}
struct Foo {
  double dist;
  int m, p, r;
  inline double kw(double x) { return x * x; }
  void read(int x0, int y0) {
    int x, y;
    scanf("%d %d %d %d %d", &x, &y, &m, &p, &r);
    dist = sqrt(kw(x - x0) + kw(y - y0));
  }
};
template <typename T>
struct Compress {
  vector<T> data;
  bool sorted;
  Compress() { sorted = false; }
  void feed(T val) {
    data.push_back(val);
    sorted = false;
  }
  void arrange() {
    sort(data.begin(), data.end());
    int ind = 0;
    for (int i = 0; i < data.size(); i++)
      if (!i || data[i] != data[i - 1]) data[ind++] = data[i];
    data.resize(ind);
    sorted = true;
  }
  int get(T x) {
    if (!sorted) arrange();
    return lower_bound(data.begin(), data.end(), x) - data.begin();
  }
};
vector<bool> donevec;
struct LabeledPoint {
  int x, y, index;
  LabeledPoint() {}
  LabeledPoint(int xx, int yy, int ii) {
    x = xx;
    y = yy;
    index = ii;
  }
  bool operator<(const LabeledPoint &lp) const { return y > lp.y; }
  bool done() { return donevec[index]; }
  void markdone() { donevec[index] = true; }
};
template <typename T>
struct Tree {
  vector<vector<T> > v;
  int N;
  Tree(int n) {
    for (N = 1; N < n; N *= 2)
      ;
    v.resize(2 * N);
  }
  void add(int x, T y) {
    x += N;
    while (x) {
      ;
      v[x].push_back(y);
      x /= 2;
    }
  }
  void arrange() {
    for (int i = 0; i < (v.size()); i++) sort(v[i].begin(), v[i].end());
  }
  vector<T> findlower2(int x0, T y0) {
    x0 += N;
    vector<T> result;
    ;
    while (x0) {
      ;
      for (int i = 0; i < v[x0].size(); i++)
        ;
      if ((x0 & 1) && x0 > 1)
        x0 /= 2;
      else {
        while (v[x0].size()) {
          if (v[x0].back().done())
            v[x0].pop_back();
          else if (v[x0].back() < y0)
            break;
          else {
            result.push_back(v[x0].back());
            v[x0].back().markdone();
          }
        }
        if (__builtin_popcount(x0) == 1) break;
        x0 = (x0 - 1) / 2;
      }
    }
    return result;
  }
};
int brutesolve(const vector<Foo> &data, int p0, int r0) {
  queue<pair<int, int> > Q;
  Q.push(pair<int, int>(p0, r0));
  int n = data.size();
  vector<bool> used(n, false);
  int result = 0;
  while (Q.size()) {
    pair<int, int> curr = Q.front();
    Q.pop();
    for (int i = 0; i < data.size(); i++)
      if (!used[i]) {
        if (data[i].dist <= (double)curr.second && data[i].m <= curr.first) {
          used[i] = true;
          result += 1;
          Q.push(pair<int, int>(data[i].p, data[i].r));
        }
      }
  }
  return result;
}
int main() {
  int x0, y0, p0, r0, n;
  Compress<double> CompDist;
  Compress<int> CompMass;
  scanf("%d %d %d %d %d", &x0, &y0, &p0, &r0, &n);
  CompDist.feed(0);
  CompDist.feed(r0);
  CompMass.feed(p0);
  donevec.resize(n, false);
  vector<Foo> v(n);
  for (int i = 0; i < n; i++) {
    v[i].read(x0, y0);
    CompDist.feed(v[i].r);
    CompDist.feed(v[i].dist);
    CompMass.feed(v[i].m);
    CompMass.feed(v[i].p);
  };
  Tree<LabeledPoint> TT(CompMass.data.size());
  for (int i = 0; i < n; i++) {
    v[i].r = CompDist.get(v[i].r);
    v[i].dist = CompDist.get(v[i].dist);
    v[i].p = CompMass.get(v[i].p);
    v[i].m = CompMass.get(v[i].m);
    ;
    TT.add(v[i].m, LabeledPoint(v[i].m, v[i].dist, i));
  }
  TT.arrange();
  int result = 0;
  queue<pair<int, int> > to_use;
  to_use.push(pair<int, int>(CompMass.get(p0), CompDist.get(r0)));
  while (to_use.size()) {
    pair<int, int> curr = to_use.front();
    to_use.pop();
    vector<LabeledPoint> tmp =
        TT.findlower2(curr.first, LabeledPoint(curr.first, curr.second, 0));
    result += tmp.size();
    for (int i = 0; i < (tmp.size()); i++) {
      int ind = tmp[i].index;
      to_use.push(pair<int, int>(v[ind].p, v[ind].r));
    }
  }
  printf("%d\n", result);
  return 0;
}
