#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 250006;
long long adfsdfdsf, afsdfdsf, dfsdfdsf, adsdfdsf, n;
struct grip {
  long long x, y, m, p, r;
  bool operator<(grip const& other) const {
    long long d =
        (x - adfsdfdsf) * (x - adfsdfdsf) + (y - afsdfdsf) * (y - afsdfdsf);
    long long d1 = (other.x - adfsdfdsf) * (other.x - adfsdfdsf) +
                   (other.y - afsdfdsf) * (other.y - afsdfdsf);
    return d < d1;
  }
};
vector<grip> v;
bool used[MAXN];
bool cmp(int x, int y) { return v[x].m < v[y].m; }
struct node {
  vector<int> grips;
};
node tree[3 * MAXN];
void build(int l, int r, int idx) {
  if (l == r) {
    tree[idx].grips.push_back(l);
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, idx * 2);
  build(mid + 1, r, idx * 2 + 1);
  int i1 = 0, i2 = 0;
  reverse(tree[idx * 2].grips.begin(), tree[idx * 2].grips.end());
  reverse(tree[idx * 2 + 1].grips.begin(), tree[idx * 2 + 1].grips.end());
  while (i1 < tree[idx * 2].grips.size() &&
         i2 < tree[idx * 2 + 1].grips.size()) {
    if (cmp(tree[idx * 2].grips[i1], tree[idx * 2 + 1].grips[i2])) {
      tree[idx].grips.push_back(tree[idx * 2].grips[i1]);
      i1++;
    } else {
      tree[idx].grips.push_back(tree[idx * 2 + 1].grips[i2]);
      i2++;
    }
  }
  while (i1 < tree[idx * 2].grips.size()) {
    tree[idx].grips.push_back(tree[idx * 2].grips[i1]);
    i1++;
  }
  while (i2 < tree[idx * 2 + 1].grips.size()) {
    tree[idx].grips.push_back(tree[idx * 2 + 1].grips[i2]);
    i2++;
  }
  reverse(tree[idx].grips.begin(), tree[idx].grips.end());
  reverse(tree[idx * 2].grips.begin(), tree[idx * 2].grips.end());
  reverse(tree[idx * 2 + 1].grips.begin(), tree[idx * 2 + 1].grips.end());
}
vector<int> ivan;
void query(int l, int r, int idx, int ql, int qr, int maxm) {
  if (l > qr) return;
  if (r < ql) return;
  if (l >= ql && r <= qr) {
    while (tree[idx].grips.size() > 0) {
      if (v[tree[idx].grips.back()].m > maxm) break;
      int ind = tree[idx].grips.back();
      tree[idx].grips.pop_back();
      if (used[ind]) continue;
      ivan.push_back(ind);
    }
    return;
  }
  int mid = (l + r) / 2;
  query(l, mid, idx * 2, ql, qr, maxm);
  query(mid + 1, r, idx * 2 + 1, ql, qr, maxm);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> adfsdfdsf >> afsdfdsf >> dfsdfdsf >> adsdfdsf >> n;
  for (int i = 0; i < n; i++) {
    int in1, in2, in3, in4, in5;
    cin >> in1 >> in2 >> in3 >> in4 >> in5;
    v.push_back({in1, in2, in3, in4, in5});
  }
  sort(v.begin(), v.end());
  {
    int low = 1, high = v.size(), mid, ans = 0;
    while (low <= high) {
      mid = (low + high) / 2;
      if (adsdfdsf * adsdfdsf >=
          (v[mid - 1].x - adfsdfdsf) * (v[mid - 1].x - adfsdfdsf) +
              (v[mid - 1].y - afsdfdsf) * (v[mid - 1].y - afsdfdsf)) {
        ans = mid;
        low = mid + 1;
      } else
        high = mid - 1;
    }
    adsdfdsf = ans;
  }
  for (int i = 0; i < v.size(); i++) {
    int low = 1, high = v.size(), mid, ans = 0;
    while (low <= high) {
      mid = (low + high) / 2;
      if (v[i].r * v[i].r >=
          (v[mid - 1].x - adfsdfdsf) * (v[mid - 1].x - adfsdfdsf) +
              (v[mid - 1].y - afsdfdsf) * (v[mid - 1].y - afsdfdsf)) {
        ans = mid;
        low = mid + 1;
      } else
        high = mid - 1;
    }
    v[i].r = ans;
  }
  queue<pair<int, int> > q;
  q.push({dfsdfdsf, adsdfdsf});
  build(0, n - 1, 1);
  int cnt = -1;
  while (!q.empty()) {
    pair<int, int> p = q.front();
    q.pop();
    cnt++;
    ivan.clear();
    query(0, n - 1, 1, 0, p.second - 1, p.first);
    for (auto xd : ivan) {
      q.push({v[xd].p, v[xd].r});
      used[xd] = 1;
    }
  }
  cout << cnt << endl;
  return 0;
}
