#include <bits/stdc++.h>
using namespace std;
void fre() {
  freopen("c://test//input.in", "r", stdin);
  freopen("c://test//output.out", "w", stdout);
}
template <class T1, class T2>
inline void gmax(T1 &a, T2 b) {
  if (b > a) a = b;
}
template <class T1, class T2>
inline void gmin(T1 &a, T2 b) {
  if (b < a) a = b;
}
const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, inf = 0x3f3f3f3f;
template <class T1, class T2>
inline void gadd(T1 &a, T2 b) {
  a = (a + b) % Z;
}
int casenum, casei;
int D, n, m;
int lft[N], rgt[N], bot[N], top[N];
struct A {
  int l, r, t, b;
} a[N];
int main() {
  while (~scanf("%d%d%d", &D, &n, &m)) {
    memset(lft, 0, sizeof(lft));
    memset(rgt, 0, sizeof(rgt));
    memset(top, 0, sizeof(top));
    memset(bot, 0, sizeof(bot));
    int x1, y1, x2, y2;
    for (int i = 1; i <= D; ++i) {
      scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
      if (x1 > x2) swap(x1, x2);
      if (y1 > y2) swap(y1, y2);
      a[i] = {x1, x2, y2, y1};
      ++lft[x1];
      ++rgt[x2];
      ++bot[y1];
      ++top[y2];
    }
    for (int i = 1; i <= n + 1; ++i) {
      lft[i] += lft[i - 1];
    }
    for (int i = 1; i <= m + 1; ++i) {
      bot[i] += bot[i - 1];
    }
    for (int i = n; i >= 0; --i) {
      rgt[i] += rgt[i + 1];
    }
    for (int i = m; i >= 0; --i) {
      top[i] += top[i + 1];
    }
    int L, R, T, B;
    scanf("%d%d%d%d", &L, &R, &T, &B);
    int ans = -1;
    for (int i = 1; i <= D; ++i) {
      int lr = (a[i].r > a[i].l);
      int tb = (a[i].t > a[i].b);
      if (lft[a[i].r - 1] - lr == L && rgt[a[i].l + 1] - lr == R &&
          top[a[i].b + 1] - tb == B && bot[a[i].t - 1] - tb == T) {
        ans = i;
        break;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
