#include <bits/stdc++.h>
using namespace std;
struct Sofa {
  int x1, y1, x2, y2, c1, c2, c3, c4, i;
  Sofa() {}
  Sofa(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
} s[100001];
int d, n, m, c1, c2, c3, c4, a1[100001], a2[100001], a3[100001], a4[100001];
int main() {
  scanf("%d%d%d", &d, &n, &m);
  for (int i = 1, x1, y1, x2, y2; i <= d; i++) {
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int a = min(x1, x2), b = max(x1, x2);
    int c = min(y1, y2), d2 = max(y1, y2);
    s[i] = Sofa(a, c, b, d2);
    s[i].i = i;
    if (a == b)
      a2[a]++;
    else
      a1[a]++;
    if (c == d2)
      a4[c]++;
    else
      a3[c]++;
  }
  for (int i = 1; i <= n; i++) a1[i] += a1[i - 1], a2[i] += a2[i - 1];
  for (int i = 1; i <= m; i++) a3[i] += a3[i - 1], a4[i] += a4[i - 1];
  scanf("%d%d%d%d", &c1, &c2, &c3, &c4);
  int res = 0;
  for (int i = 1; i <= d; i++) {
    int a, b, c, d2;
    if (s[i].x1 == s[i].x2)
      a = a1[s[i].x1 - 1] + a2[s[i].x1 - 1];
    else
      a = a1[s[i].x1] - 1 + a2[s[i].x1];
    b = (a1[n] - a1[s[i].x1 - 1] - (s[i].x1 != s[i].x2)) +
        (a2[n] - a2[s[i].x1]);
    if (s[i].y1 == s[i].y2)
      c = a3[s[i].y1 - 1] + a4[s[i].y1 - 1];
    else
      c = a3[s[i].y1] - 1 + a4[s[i].y1];
    d2 = (a3[m] - a3[s[i].y1 - 1] - (s[i].y1 != s[i].y2)) +
         (a4[m] - a4[s[i].y1]);
    if (c1 == a && c2 == b && c3 == c && c4 == d2) {
      res = i;
      break;
    }
  }
  if (res)
    printf("%d", res);
  else
    puts("-1");
  return 0;
}
