#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   inline long long int max(long long int a, long long int b, long long int c) {     return max(max(a, b), c);   }   inline long long int min(long long int a, long long int b, long long int c) {     return min(min(a, b), c);   }   inline long long int max(long long int a, long long int b) {     return (a > b) ? a : b;   }   inline long long int min(long long int a, long long int b) {     return (a < b) ? a : b;   }   inline long long int mul(long long int x, long long int y, long long int mod_) {     return ((x % mod_) * 1LL * (y % mod_)) % mod_;   }   long long int power(long long int a, long long int n) {     long long int p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long int powm(long long int a, long long int n, long long int mod_) {     long long int p = 1;     while (n) {       if (n % 2) {         p = mul(p, a, mod_);       }       n >>= 1;       a = mul(a, a, mod_);     }     return p % mod_;   }   long long int powi(long long int a, long long int mod_) {     return powm(a, mod_ - 2, mod_);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ;     long long int mn, mx;     long long int n, m, t, k, i, j, sum = 0, flag = 0, cnt = 0;     long long int x = 0, y = 0, z, l = 0, r = 0, q;     int TC = 1;     while (TC--) {       cin >> q;       cin >> n >> m;       vector<pair<pair<long long int, long long int>,                   pair<long long int, long long int>>>           sofa(q);       for (i = 0; i < q; ++i) {         cin >> sofa[i].first.first >> sofa[i].first.second >>             sofa[i].second.first >> sofa[i].second.second;       }       long long int cr, cl, ct, cb;       cin >> cl >> cr >> ct >> cb;       vector<long long int> prx(n + 2), pry(m + 2), sux(n + 2), suy(m + 2);       for (i = 0; i < q; ++i) {         pair<long long int, long long int> p1, p2;         tie(p1, p2) = sofa[i];         long long int xl = min(p1.first, p2.first);         long long int xr = max(p1.first, p2.first);         long long int yt = max(p1.second, p2.second);         long long int yd = min(p1.second, p2.second);         prx[xl]++;         sux[xr]++;         pry[yd]++;         suy[yt]++;       }       for (i = 1; i < n + 2; ++i) {         prx[i] += prx[i - 1];       }       for (i = n; i >= 0; --i) {         sux[i] += sux[i + 1];       }       for (i = 1; i < m + 2; ++i) {         pry[i] += pry[i - 1];       }       for (i = m; i >= 0; --i) {         suy[i] += suy[i + 1];       }       for (i = 0; i < q; ++i) {         pair<long long int, long long int> p1, p2;         tie(p1, p2) = sofa[i];         long long int xl = min(p1.first, p2.first);         long long int xr = max(p1.first, p2.first);         long long int yt = max(p1.second, p2.second);         long long int yd = min(p1.second, p2.second);         ;         if (cl == (prx[xr - 1] - (xl != xr)) and             cr == (sux[xl + 1] - (xl != xr)) and             cb == (suy[yd + 1] - (yt != yd)) and             ct == (pry[yt - 1] - (yt != yd))) {           cout << i + 1;           return 0;         }       }       cout << -1;     };     return 0;   }