#include <bits/stdc++.h>
using namespace std;
int lft[100005], rght[100005], up[100005], dwn[100005];
int end() {
  cin.get();
  cin.get();
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int d, n, m, x1[100005], x2[100005], y1[100005], y2[100005], cntl, cntr, cntu,
      cntd;
  cin >> d >> n >> m;
  for (int i(0); i < d; ++i) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    lft[min(x1[i], x2[i])]++;
    rght[max(x1[i], x2[i])]++;
    up[min(y1[i], y2[i])]++;
    dwn[max(y1[i], y2[i])]++;
  }
  for (int i(1); i <= n; ++i) lft[i] += lft[i - 1];
  for (int i(n); i >= 1; --i) rght[i] += rght[i + 1];
  for (int i(1); i <= m; ++i) up[i] += up[i - 1];
  for (int i(m); i >= 1; --i) dwn[i] += dwn[i + 1];
  cin >> cntl >> cntr >> cntu >> cntd;
  for (int i(0); i < d; ++i) {
    if (y1[i] == y2[i]) {
      if (cntl == lft[min(x1[i], x2[i])] - 1 &&
          cntr == rght[max(x1[i], x2[i])] - 1 && cntu == up[y1[i] - 1] &&
          cntd == dwn[y1[i] + 1]) {
        cout << i + 1;
        return end();
      }
    } else {
      if (cntl == lft[x1[i] - 1] && cntr == rght[x1[i] + 1] &&
          cntu == up[min(y1[i], y2[i])] - 1 &&
          cntd == dwn[max(y1[i], y2[i])] - 1) {
        cout << i + 1;
        return end();
      }
    }
  }
  cout << -1;
  cin.get();
  cin.get();
  return 0;
}
