#include <bits/stdc++.h>
using namespace std;
const int N = 250005;
int n;
int X[N], Y[N], M[N], P[N], R[N];
int cnt;
long long D[N];
set<pair<int, int> > bt[N];
inline void add(int i, int x) {
  while (i <= n) {
    bt[i].insert(make_pair(M[x], x));
    i += i & -i;
  }
}
inline void del(int i, int x) {
  while (i <= n) {
    bt[i].erase(make_pair(M[x], x));
    i += i & -i;
  }
}
inline vector<int> qry(int i, int p) {
  set<pair<int, int> >::iterator it;
  vector<int> ret;
  while (i > 0) {
    for (it = bt[i].begin(); it != bt[i].end(); it++) {
      if (it->first > p) break;
      ret.push_back(it->second);
    }
    i -= i & -i;
  }
  return ret;
}
int que[N];
int pos_d[N];
int main() {
  scanf("%d%d%d%d%d", &X[0], &Y[0], &P[0], &R[0], &n);
  cnt = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d%d", &X[i], &Y[i], &M[i], &P[i], &R[i]);
    D[++cnt] = 1ll * (X[0] - X[i]) * (X[0] - X[i]) +
               1ll * (Y[0] - Y[i]) * (Y[0] - Y[i]);
  }
  sort(D + 1, D + 1 + cnt);
  cnt = unique(D + 1, D + 1 + cnt) - D - 1;
  for (int i = 1; i <= n; i++) {
    pos_d[i] = lower_bound(D + 1, D + 1 + cnt,
                           1ll * (X[0] - X[i]) * (X[0] - X[i]) +
                               1ll * (Y[0] - Y[i]) * (Y[0] - Y[i])) -
               D;
    add(pos_d[i], i);
  }
  int ql = 1, qr = 0;
  que[++qr] = 0;
  int ans = 0;
  while (ql <= qr) {
    int u = que[ql++];
    int pos = upper_bound(D + 1, D + 1 + cnt, 1ll * R[u] * R[u]) - D - 1;
    vector<int> vec = qry(pos, P[u]);
    for (int v : vec) {
      del(pos_d[v], v);
      que[++qr] = v;
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
