#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
struct zh {
  long long d, r;
  int m, p;
};
zh mas[250001];
struct cmp {
  inline bool operator()(const int &a, const int &b) {
    return mas[a].d < mas[b].d;
  }
};
struct cmp2 {
  inline bool operator()(const int &a, const int &b) {
    return mas[a].m < mas[b].m;
  }
};
int a, b, c, d, i, j, n, m, k, first, second, p, r, ans;
int ind[250001];
bool used[250001];
int beg[511];
int cur[511][511], len[511];
long long mx[511];
queue<zh> q;
inline void add(const zh &v) {
  for (int _n((c)-1), i(0); i <= _n; i++) {
    if (mx[i] <= v.r) {
      while (beg[i] < len[i] && mas[cur[i][beg[i]]].m <= v.p) {
        int num = cur[i][beg[i]++];
        if (!used[num]) {
          q.push(mas[num]);
          ++ans;
          used[num] = 1;
        }
      }
    } else {
      for (int _n(len[i] - 1), j(beg[i]); j <= _n; j++) {
        int num = cur[i][j];
        if (used[num]) continue;
        if (mas[num].d <= v.r && mas[num].m <= v.p) {
          used[num] = 1;
          q.push(mas[num]);
          ++ans;
        }
      }
      break;
    }
  }
}
int main() {
  scanf("%d%d%d%d%d", &first, &second, &p, &r, &n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    int x1, y1;
    scanf("%d%d%d%d%d", &x1, &y1, &mas[i].m, &mas[i].p, &a);
    mas[i].d = (long long)(x1 - first) * (x1 - first) +
               (long long)(y1 - second) * (y1 - second);
    mas[i].r = (long long)a * a;
  }
  for (int _n((n)-1), i(0); i <= _n; i++) ind[i] = i;
  sort(ind, ind + n, cmp());
  k = (int)sqrt((double)n);
  for (int _n((500) - 1), i(0); i <= _n; i++)
    mx[i] = -8 * 1000000000000000000LL;
  c = 0;
  for (int _n((n)-1), i(0); i <= _n; i++) {
    a = i / k;
    cur[a][len[a]++] = ind[i];
    c = max(c, a + 1);
    mx[a] = max(mx[a], mas[ind[i]].d);
  }
  for (int _n((c)-1), i(0); i <= _n; i++) {
    sort(cur[i], cur[i] + len[i], cmp2());
  }
  zh tt;
  tt.d = 0;
  tt.p = p;
  tt.m = 0;
  tt.r = (long long)r * r;
  q.push(tt);
  while (!q.empty()) {
    zh v = q.front();
    q.pop();
    add(v);
  }
  printf("%d\n", ans);
}
