#include <bits/stdc++.h>
using namespace std;
int d, n, m, a[100000][4], cntl, cntr, cntt, cntb, ans;
int U[100005], D[100005], L[100005], R[100005];
int main() {
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 0; i < d; i++) {
    scanf("%d%d%d%d", &a[i][0], &a[i][1], &a[i][2], &a[i][3]);
    int y1 = max(a[i][1], a[i][3]);
    int y2 = min(a[i][1], a[i][3]);
    if (y1 != 1) U[y1 - 1]++;
    if (y2 != m) D[y2 + 1]++;
    int x1 = max(a[i][0], a[i][2]);
    int x2 = min(a[i][0], a[i][2]);
    if (x1 != 1) R[x1 - 1]++;
    if (x2 != n) L[x2 + 1]++;
  }
  for (int i = 1; i <= m; i++) D[i] = D[i - 1] + D[i];
  for (int i = m; i >= 1; i--) U[i] = U[i + 1] + U[i];
  for (int i = 1; i <= n; i++) L[i] = L[i - 1] + L[i];
  for (int i = n; i >= 1; i--) R[i] = R[i + 1] + R[i];
  scanf("%d%d%d%d", &cntl, &cntr, &cntt, &cntb);
  ans = -1;
  for (int i = 0; i < d; i++) {
    bool flag = 1;
    if (a[i][1] != a[i][3]) {
      int x = a[i][0];
      int y1 = max(a[i][1], a[i][3]);
      int y2 = min(a[i][1], a[i][3]);
      flag &= (D[y1] - 1 == cntt);
      flag &= (U[y2] - 1 == cntb);
      flag &= (L[x] == cntl);
      flag &= (R[x] == cntr);
    }
    if (a[i][0] != a[i][2]) {
      int x1 = max(a[i][0], a[i][2]);
      int x2 = min(a[i][0], a[i][2]);
      int y = a[i][1];
      flag &= (D[y] == cntt);
      flag &= (U[y] == cntb);
      flag &= (L[x1] - 1 == cntl);
      flag &= (R[x2] - 1 == cntr);
    }
    if (flag) ans = i + 1;
  }
  printf("%d\n", ans);
  return 0;
}
