#include <bits/stdc++.h>
using namespace std;
void see(int x) { cout << x; }
void see(long long int x) { cout << x; }
void see(long double x) { cout << x; }
void see(char x) { cout << '\'' << x << '\''; }
void see(string x) { cout << '\"' << x << '\"'; }
template <typename T, typename V>
void see(const pair<T, V> &x) {
  cout << '{';
  see(x.first);
  cout << ',';
  see(x.second);
  cout << '}';
}
template <typename T>
void see(const T &x) {
  int f = 0;
  cout << '{';
  for (auto &i : x) cout << (f++ ? "," : ""), see(i);
  cout << "}";
}
void _print() { cout << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  see(t);
  if (sizeof...(v)) cout << ", ";
  _print(v...);
}
long long int gcd(long long int a, long long int b) {
  return (!b) ? a : gcd(b, a % b);
}
struct pt {
  int lx, rx, ty, by;
};
const int N = 1e5 + 5;
int d, n, m;
pt pts[N];
int cntxl[N], cntxr[N], cntyt[N], cntyb[N];
int cnt[4], cnt1[4];
void solve() {
  cin >> d;
  cin >> n >> m;
  for (int i = 1; i <= d; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    pts[i].lx = min(x1, x2);
    pts[i].rx = max(x1, x2);
    pts[i].ty = min(y1, y2);
    pts[i].by = max(y1, y2);
    cntxl[pts[i].lx] += 1;
    cntxr[pts[i].rx] += 1;
    cntyt[pts[i].ty] += 1;
    cntyb[pts[i].by] += 1;
  }
  for (int i = 0; i <= 3; i++) cin >> cnt[i];
  for (int i = 1; i <= 1e5; i++) cntxl[i] += cntxl[i - 1];
  for (int i = 1e5; i >= 1; i--) cntxr[i] += cntxr[i + 1];
  for (int i = 1; i <= 1e5; i++) cntyt[i] += cntyt[i - 1];
  for (int i = 1e5; i >= 1; i--) cntyb[i] += cntyb[i + 1];
  for (int i = 1; i <= d; i++) {
    int rx = pts[i].rx;
    int lx = pts[i].lx;
    int ty = pts[i].ty;
    int by = pts[i].by;
    cnt1[0] = cntxl[rx - 1];
    cnt1[1] = cntxr[lx + 1];
    cnt1[2] = cntyt[by - 1];
    cnt1[3] = cntyb[ty + 1];
    if (rx != lx) {
      cnt1[0] -= 1;
      cnt1[1] -= 1;
    } else {
      cnt1[2] -= 1;
      cnt1[3] -= 1;
    }
    int f = 1;
    for (int i = 0; i <= 3; i++) {
      f &= (cnt1[i] == cnt[i]);
    }
    if (f) {
      cout << i << " ";
      return;
    }
  }
  cout << -1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
