#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename... t>
using V = vector<t...>;
template <typename... t>
using outit = ostream_iterator<t...>;
void print(ostream& os) { os << '\n'; }
template <typename t, typename... v>
void print(ostream& os, const t& a, v&&... b) {
  os << a << ' ';
  print(os, b...);
}
int d, n, m;
int l, p, g, du;
V<V<int> > tb;
V<int> lew, pra, gor, dol;
int main(int argc, char** argv) {
  (void)(argc);
  (void)(argv);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> d >> n >> m;
  lew.resize(n + 2);
  pra.resize(n + 2);
  gor.resize(m + 2);
  dol.resize(m + 2);
  tb.resize(d, V<int>(4));
  for (int i = 0; i < d; ++i) {
    for (int k = 0; k < 4; ++k) cin >> tb[i][k];
    ++pra[max(tb[i][0], tb[i][2])];
    ++lew[min(tb[i][0], tb[i][2])];
    ++dol[min(tb[i][1], tb[i][3])];
    ++gor[max(tb[i][1], tb[i][3])];
  }
  cin >> l >> p >> du >> g;
  for (int i = 1; i <= n + 1; ++i) lew[i] += lew[i - 1];
  for (int i = 1; i <= m + 1; ++i) dol[i] += dol[i - 1];
  for (int i = n; i >= 0; --i) pra[i] += pra[i + 1];
  for (int i = m; i >= 0; --i) gor[i] += gor[i + 1];
  for (int i = 0; i < d; ++i) {
    ;
    ;
    if (l != lew[max(tb[i][0], tb[i][2]) - 1] - (tb[i][0] != tb[i][2]))
      continue;
    ;
    if (p != pra[min(tb[i][0], tb[i][2]) + 1] - (tb[i][0] != tb[i][2]))
      continue;
    ;
    if (du != dol[max(tb[i][1], tb[i][3]) - 1] - (tb[i][1] != tb[i][3]))
      continue;
    ;
    if (g != gor[min(tb[i][1], tb[i][3]) + 1] - (tb[i][1] != tb[i][3]))
      continue;
    return print(cout, i + 1), 0;
  }
  print(cout, -1);
}
