#include <bits/stdc++.h>
using namespace std;
double getX(const pair<double, double>& pt) { return pt.first; }
double getY(const pair<double, double>& pt) { return pt.second; }
const int INF = std::numeric_limits<int>::max();
struct Attractor {
  int m, r, p, x, y;
  int id;
};
Attractor nextAttractor() {
  Attractor at;
  cin >> at.x >> at.y >> at.m >> at.p >> at.r;
  return at;
}
const int NMAX = 300 * 1000;
stack<Attractor> f[NMAX];
struct Cmp {
  bool operator()(const Attractor& a, const Attractor& b) const {
    return a.m > b.m;
  }
};
void update(int r, int size, const Attractor& at) {
  while (r < size) {
    f[r].push(at);
    r = r | (r + 1);
  }
}
vector<Attractor> search(int r, int size, int m) {
  vector<Attractor> result;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    while (!f[r].empty() && f[r].top().m <= m) {
      result.push_back(f[r].top());
      f[r].pop();
    }
  }
  return result;
}
void solve() {
  Attractor start;
  cin >> start.x >> start.y >> start.p >> start.r;
  int n;
  cin >> n;
  vector<Attractor> ats(n);
  for (int i = 0; i < int(n); ++i) {
    ats[i] = nextAttractor();
    ats[i].x -= start.x;
    ats[i].y -= start.y;
    ats[i].id = i;
  }
  vector<long long> rs(n);
  sort(ats.begin(), ats.end(), Cmp());
  for (int i = 0; i < int(n); ++i) {
    long long x = ats[i].x, y = ats[i].y;
    rs[i] = x * x + y * y;
  }
  sort(rs.begin(), rs.end());
  rs.erase(unique(rs.begin(), rs.end()), rs.end());
  for (int i = 0; i < int(ats.size()); ++i) {
    long long x = ats[i].x, y = ats[i].y;
    int r = lower_bound(rs.begin(), rs.end(), x * x + y * y) - rs.begin();
    update(r, rs.size(), ats[i]);
  }
  queue<Attractor> q;
  q.push(start);
  vector<bool> used(n);
  int ans = 0;
  while (!q.empty()) {
    Attractor a = q.front();
    q.pop();
    long long rr = a.r * (long long)(a.r);
    int r = upper_bound(rs.begin(), rs.end(), rr) - rs.begin();
    --r;
    vector<Attractor> result = search(r, rs.size(), a.p);
    for (int i = 0; i < int(result.size()); ++i) {
      if (used[result[i].id]) continue;
      used[result[i].id] = true;
      q.push(result[i]);
      ++ans;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  solve();
  return 0;
}
