#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
pair<pair<int, int>, pair<int, int> > sofa[maxn];
int L[maxn], R[maxn], U[maxn], D[maxn];
int cntL, cntR, cntU, cntD, row[maxn], col[maxn], revRow[maxn], revCol[maxn];
vector<int> vRow[maxn], vCol[maxn], vRevRow[maxn], vRevCol[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int total, n, m;
  cin >> total >> n >> m;
  for (int i = 0; i < total; i++) {
    cin >> sofa[i].first.first >> sofa[i].first.second;
    cin >> sofa[i].second.first >> sofa[i].second.second;
    if (sofa[i].first.first > sofa[i].second.first)
      swap(sofa[i].first, sofa[i].second);
    if (sofa[i].first.second > sofa[i].second.second)
      swap(sofa[i].first, sofa[i].second);
    col[sofa[i].first.first]++;
    row[sofa[i].first.second]++;
    revCol[sofa[i].second.first]++;
    revRow[sofa[i].second.second]++;
    vCol[sofa[i].second.first].push_back(i);
    vRow[sofa[i].second.second].push_back(i);
    vRevCol[sofa[i].first.first].push_back(i);
    vRevRow[sofa[i].first.second].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    for (auto tmp : vCol[i])
      L[tmp] = cntL - (sofa[tmp].first.first < sofa[tmp].second.first);
    cntL += col[i];
  }
  for (int i = n; i >= 1; i--) {
    for (auto tmp : vRevCol[i])
      R[tmp] = cntR - (sofa[tmp].first.first < sofa[tmp].second.first);
    cntR += revCol[i];
  }
  for (int i = 1; i <= m; i++) {
    for (auto tmp : vRow[i])
      U[tmp] = cntU - (sofa[tmp].first.second < sofa[tmp].second.second);
    cntU += row[i];
  }
  for (int i = m; i >= 1; i--) {
    for (auto tmp : vRevRow[i])
      D[tmp] = cntD - (sofa[tmp].first.second < sofa[tmp].second.second);
    cntD += revRow[i];
  }
  int tl, tr, tu, td;
  cin >> tl >> tr >> tu >> td;
  for (int i = 0; i < total; i++)
    if (L[i] == tl && R[i] == tr && U[i] == tu && D[i] == td) {
      cout << i + 1 << endl;
      return 0;
    }
  cout << -1 << endl;
  return 0;
}
