#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
struct treeNode {
  long long leftD, rightD;
  vector<pair<long long, int> > S;
};
struct element {
  long long d, m, r, p;
};
bool u[300500];
element A[300500];
int n, lst, ans;
long long p, r;
treeNode tree[524288];
vector<pair<long long, long long> > Q;
bool operator<(const element& p1, const element& p2) { return p1.d < p2.d; }
void read() {
  int x, y;
  cin >> x >> y >> p >> r >> n;
  r = r * r;
  memset(u, 0, sizeof(u));
  for (int i = 0; i < (int)(n); i++) {
    int x1, Y1HUI;
    scanf("%d%d", &x1, &Y1HUI);
    x1 -= x;
    Y1HUI -= y;
    A[i].d = (long long)x1 * x1 + (long long)Y1HUI * Y1HUI;
    int m1, r1, p1;
    scanf("%d%d%d", &m1, &p1, &r1);
    A[i].r = r1;
    A[i].r = A[i].r * A[i].r;
    A[i].p = p1;
    A[i].m = m1;
  }
  ans = 0;
  Q.push_back(make_pair(r, p));
  sort(A, A + n);
}
void update(vector<pair<long long, int> >& S, long long y) {
  while (S.size() > 0 && S.back().first <= y) {
    int v = S.back().second;
    S.pop_back();
    if (!u[v]) {
      u[v] = 1;
      ans++;
      Q.push_back(make_pair(A[v].r, A[v].p));
    }
  }
}
void go(int v, long long l, long long r, long long y) {
  if (tree[v].rightD < l || tree[v].leftD > r) return;
  if (l <= tree[v].leftD && tree[v].rightD <= r) {
    update(tree[v].S, y);
    return;
  }
  go(v * 2, l, r, y);
  go(v * 2 + 1, l, r, y);
}
int main() {
  read();
  lst = 1;
  while (lst < n) lst *= 2;
  for (int i = 0; i < (int)(lst * 2); i++) tree[i].leftD = tree[i].rightD = 0;
  for (int i = 0; i < (int)(n); i++) {
    tree[i + lst].leftD = A[i].d;
    tree[i + lst].rightD = A[i].d;
    tree[i + lst].S.push_back(make_pair(A[i].m, i));
  }
  for (int i = n; i < lst; i++) {
    tree[i + lst].leftD = inf64;
    tree[i + lst].rightD = inf64;
  }
  for (int i = lst - 1; i >= 1; i--) {
    tree[i].leftD = tree[i * 2].leftD;
    tree[i].rightD = tree[i * 2 + 1].rightD;
    tree[i].S = tree[i * 2].S;
    tree[i].S.insert(tree[i].S.end(), tree[i * 2 + 1].S.begin(),
                     tree[i * 2 + 1].S.end());
    sort(tree[i].S.begin(), tree[i].S.end());
    reverse(tree[i].S.begin(), tree[i].S.end());
  }
  while (Q.size() > 0) {
    pair<long long, long long> v = Q.back();
    Q.pop_back();
    go(1, 1, v.first, v.second);
  }
  cout << ans << endl;
  return 0;
}
