#include <bits/stdc++.h>
using namespace std;
long long XX, YY, stk[800005];
int tmp;
map<long long, int> id;
struct rec {
  int Y, y;
  long long X, x;
  void read() {
    long long px, py;
    scanf("%I64d%I64d", &px, &py);
    X = (px - XX) * (px - XX) + (py - YY) * (py - YY);
    scanf("%d", &Y);
    scanf("%d%I64d", &y, &x);
    x *= x;
  }
} E[800005], q[800005];
bool cmp(const rec &i, const rec &j) {
  return i.X == j.X ? i.Y < j.Y : i.X < j.X;
}
int data[8 * 800005], pos[2 * 800005], ret, Ans;
int st, en, ll, rr, cnt, flag, n;
vector<int> val[2 * 800005];
void build(int t, int l, int r) {
  if (l == r) {
    data[t] = E[val[l][pos[l]]].Y;
    return;
  }
  int mid = (l + r) >> 1;
  build(t * 2, l, mid);
  build(t * 2 + 1, mid + 1, r);
  data[t] = min(data[t * 2], data[t * 2 + 1]);
  ;
}
void query(int t, int l, int r) {
  if (l == r) {
    if (data[t] <= ret) {
      Ans++;
      q[++en] = E[val[l][pos[l]]];
      data[t] = E[val[l][++pos[l]]].Y;
      flag = 1;
    }
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= l && r <= rr) {
    if (data[t * 2] <= ret) query(t * 2, l, mid);
    if (data[t * 2 + 1] <= ret) query(t * 2 + 1, mid + 1, r);
    data[t] = min(data[t * 2], data[t * 2 + 1]);
    ;
    return;
  }
  if (ll <= mid) query(t * 2, l, mid);
  if (rr > mid) query(t * 2 + 1, mid + 1, r);
  data[t] = min(data[t * 2], data[t * 2 + 1]);
  ;
}
void writeln(int t, int l, int r) {
  if (l == r) {
    printf("%d ", data[t]);
    return;
  }
  int mid = (l + r) >> 1;
  writeln(t * 2, l, mid);
  writeln(t * 2 + 1, mid + 1, r);
}
int main() {
  scanf("%I64d%I64d", &XX, &YY);
  scanf("%d%I64d", &E[0].y, &E[0].x);
  E[0].x *= E[0].x;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) E[i].read();
  for (int i = 0; i <= n; i++) {
    stk[++tmp] = E[i].x;
    stk[++tmp] = E[i].X;
  }
  sort(stk + 1, stk + 1 + tmp);
  int cnt = unique(stk + 1, stk + 1 + tmp) - stk - 1;
  for (int i = 1; i <= cnt; i++) id[stk[i]] = i;
  for (int i = 0; i <= n; i++) {
    E[i].x = id[E[i].x];
    E[i].X = id[E[i].X];
  }
  sort(E + 1, E + 1 + n, cmp);
  E[n + 1] = (rec){1000000005, 233, 233, 233};
  for (int i = 1; i <= n; i++) val[E[i].X].push_back(i);
  for (int i = 1; i <= cnt; i++) val[i].push_back(n + 1);
  build(1, 1, cnt);
  q[++en] = E[0];
  while (st < en) {
    rec now = q[++st];
    ll = 1;
    rr = now.x;
    ret = now.y;
    while (1) {
      flag = 0;
      query(1, 1, cnt);
      if (!flag) break;
    }
  }
  printf("%d\n", Ans);
}
