# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <vector>
using namespace std;
const int maxn = 1000 + 5;
int w[maxn], b[maxn];
int d[maxn][maxn];
int f[maxn];
int id[maxn];
int idd;
int n, m, v;

struct Node {
    int w, b;
    Node() : w(0), b(0) { }
    Node(int w, int b) : w(w), b(b) { }
};

vector<Node> jh[maxn];

int Find(int x) {
    int r = x;
    while (x != f[x]) x = f[x];
    while (r != x) {
        int y = r;
        r = f[y];
        f[y] = x;
    }

    return r;
}

void Merge(int x, int y) {
    int a = Find(x), b = Find(y);
    if (a < b) f[a] = b;
    else f[b] = a;
}

void init() {
    idd = 0;
    memset(id, -1, sizeof id);
    memset(d, 0, sizeof d);
    for (int i = 0; i < n; ++i) f[i] = i;
    for (int i = 0; i < n; ++i) jh[i].clear();
}

int main(void)
{
    while (~scanf("%d %d %d", &n, &m, &w)) {
        init();
        for (int i = 0; i < n; ++i) scanf("%d", w + i);
        for (int i = 0; i < n; ++i) scanf("%d", b + i);
        for (int i = 0; i < m; ++i) {
            int u, v; scanf("%d %d", &u, &v);
            int fu = Find(u), fv = Find(v);
            if (fu != fv) Merge(fu, fv);
        }
        for (int i = 1; i <= n; ++i) {
            int f = Find(i);
            int& idf = id[f];
            if (idf == -1) idf = idd++;
            jh[idf].push_back(Node(w[i], b[i]));
        }
        for (int i = 0; i < idd; ++i) {
            int sw = 0, sb = 0;
            for (int j = 0; j < jh[i].size(); ++j) {
                sw += jh[i][j].w; sb += jh[i][j].b;
            }
            jh[i].push_back(Node(sw, sb));
            jh[i].push_back(Node(0, 0));
        }
        for (int i = 0; i < idd; ++i) {
            for (int j = 0; j < jh[i].size(); ++j) {
                for (int ww = 0; ww <= v; ++ww) {
                    d[i][ww] = max(d[i][ww], d[i - 1][ww + jh[i][j].w] + jh[i][j].b);
                }
            }
        }
        int ans = 0;
        for (int i = 0; i <= v; ++i) ans = max(ans, d[idd - 1][i]);
        printf("%d\n", ans);
//        for (int i = 0; i < idd; ++i) {
//            for (int j = 0; j < jh[i].size(); ++j) {
//                printf("%d%c", jh[i][j], j == jh[i].size() - 1 ? '\n' : ' ');
//            }
//        }
    }

    return 0;
}


# include <iostream>
# include <algorithm>
# include <cstdio>
# include <cstring>
# include <vector>
using namespace std;
const int maxn = 1000 + 5;
int w[maxn], b[maxn];
int f[maxn];
int vis[maxn];
int id[maxn];
int dp[maxn][maxn];
int n, m, v;
int idd;

struct Node {
    int w, b;
    Node() : w(0), b(0) { }
    Node(int w, int b) : w(w), b(b) { }
};

vector<Node> jh[maxn];

int Find(int x) {
    int r = x;
    while (r != f[r]) r = f[r];
    while (x != r) {
        int y = f[x];
        x = f[x];
        f[y] = r;
    }
    return r;
}

void Merge(int x, int y) {
    int a = Find(x), b = Find(y);
    if (a < b) f[a] = b;
    else if (a > b) f[b] = a;
}

void init() {
    idd = 0;
    memset(vis, 0, sizeof vis);
    memset(id, -1, sizeof id);
    memset(dp, 0, sizeof dp);
    for (int i = 1; i <= n; ++i) f[i] = i;
    for (int i = 0; i < maxn; ++i) jh[i].clear();
}

void fdp();

int main(void)
{
    while (~scanf("%d %d %d", &n, &m, &v)) {
        init();
        for (int i = 1; i <= n; ++i) scanf("%d", w + i);
        for (int i = 1; i <= n; ++i) scanf("%d", b + i);
        for (int i = 0; i < m; ++i) {
            int u, v; scanf("%d %d", &u, &v);
            int fu = Find(u), fv = Find(v);
            if (fu != fv) Merge(u, v);
        }
        for (int i = 1; i <= n; ++i) {
            int fi = Find(i);
            if (id[fi] == -1) id[fi] = idd++;
            jh[id[fi]].push_back(Node(w[i], b[i]));
        }
        for (int i = 0; i < idd; ++i) {
            if (jh[i].size() == 1) continue;
            int sw = 0, sb = 0;
            for (int j = 0; j < jh[i].size(); ++j) {
                sw += jh[i][j].w; sb += jh[i][j].b;
            }
            jh[i].push_back(Node(sw, sb));
        }

        fdp();
        int ans = 0;
        for (int i = 0; i <= v; ++i) ans = max(ans, dp[idd - 1][i]);
        printf("%d\n", ans);
    }

    return 0;
}

void fdp() {
    for (int j = 0; j < jh[0].size(); ++j)
        if (v >= jh[0][j].w) dp[0][v - jh[0][j].w] = max(dp[0][v - jh[0][j].w], jh[0][j].b);

    for (int i = 1; i < idd; ++i) {
        for (int vv = 0; vv <= v; ++vv) {
            dp[i][vv] = dp[i - 1][vv];
            for (int j = 0; j < jh[i].size(); ++j) {
                if (vv + jh[i][j].w <= v)
                    dp[i][vv] = max(dp[i][vv], dp[i - 1][vv + jh[i][j].w] + jh[i][j].b);
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int m, n, w[1005], W, b[1005], father[1005];
int vis[1005], f[1005][1005], sum1[1005], sum2[1005], sum3[1005];
struct op{
	int num, B, Z;
}sum[1005][1005];
void Init()
{
	scanf("%d %d %d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]), father[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
}
int Find(int x)
{
	if(x == father[x]) return x;
	return father[x] = Find(father[x]);
}
void pdo()
{
	for(int i = 1; i <= m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		int u = Find(l), v = Find(r);
		if(u != v) father[u] = v;
	}
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		if(vis[u] == 0) {
			vis[u] = 1;
			tot++; int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(Find(j) == u) {
					cnt++;
					sum[tot][cnt].B = b[j]; sum1[tot] += b[j];
					sum[tot][cnt].Z = w[j]; sum2[tot] += w[j];
				}
			}
			sum3[tot] = cnt;
		}
	}
	memset(f, 0, sizeof(f));
	int ans = -1;
	for(int i = 1; i <= tot; i++) {
		for(int j = 0; j <= W; j++) {
			if(j >= sum2[i]) {
				f[i][j] = max(f[i - 1][j], f[i - 1][j - sum2[i]] + sum1[i]);
				ans = max(ans, f[i][j]);
			}
			for(int k = 1; k <= sum3[i]; k++) {
				if(j >= sum[i][k].Z) {
					f[i][j] = max(f[i - 1][j], f[i - 1][j - sum[i][k].Z] + sum[i][k].B);
					ans = max(ans, f[i][j]);
				}
			}
		}
	}
	printf("%d\n", ans);
}
int main()
{
	Init();
	pdo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int m, n, w[1005], W, b[1005], father[1005];
int vis[1005], f[1005][1005], sum1[1005], sum2[1005], sum3[1005];
struct op{
	int num, B, Z;
}sum[1005][1005];
void Init()
{
	scanf("%d %d %d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]), father[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
}
int Find(int x)
{
	if(x == father[x]) return x;
	return father[x] = Find(father[x]);
}
void pdo()
{
	for(int i = 1; i <= m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		int u = Find(l), v = Find(r);
		if(u != v) father[u] = v;
	}
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		if(vis[u] == 0) {
			vis[u] = 1;
			tot++; int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(Find(j) == u) {
					cnt++;
					sum[tot][cnt].B = b[j]; sum1[tot] += b[j];
					sum[tot][cnt].Z = w[j]; sum2[tot] += w[j];
				}
			}
			sum3[tot] = cnt;
		}
	}
/*	for(int i = 1; i <= tot; i++) {
		for(int j = 1; j <= sum3[i]; j++) {
			printf("%d %d %d\n", i, sum[i][j].Z, sum[i][j].B);
		}
	}*/
	memset(f, 0, sizeof(f));
	for(int i = 1; i <= tot; i++) {
		for(int j = 0; j <= W; j++) f[i][j] = f[i - 1][j];
		for(int j = 0; j <= W; j++) {
			if(j >= sum2[i]) {
				f[i][j] = max(f[i - 1][j], f[i - 1][j - sum2[i]] + sum1[i]);
			}
			for(int k = 1; k <= sum3[i]; k++) {
				if(j >= sum[i][k].Z) {
					f[i][j] = max(f[i][j], max(f[i - 1][j], f[i - 1][j - sum[i][k].Z] + sum[i][k].B));
				}
			}
		}
	}
	printf("%d\n", f[tot][W]);
}
int main()
{
	Init();
	pdo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int m, n, w[1005], W, b[1005], father[1005];
int vis[1005], f[1005][1005], sum1[1005], sum2[1005], sum3[1005];
struct op{
	int num, B, Z;
}sum[1005][1005];
void Init()
{
	scanf("%d %d %d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]), father[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
}
int Find(int x)
{
	if(x == father[x]) return x;
	return father[x] = Find(father[x]);
}
void pdo()
{
	for(int i = 1; i <= m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		int u = Find(l), v = Find(r);
		if(u != v) father[u] = v;
	}
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		if(vis[u] == 0) {
			vis[u] = 1;
			tot++; int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(Find(j) == u) {
					cnt++;
					sum[tot][cnt].B = b[j]; sum1[tot] += b[j];
					sum[tot][cnt].Z = w[j]; sum2[tot] += w[j];
				}
			}
			sum3[tot] = cnt;
		}
	}
	memset(f, 0, sizeof(f));
	for(int i = 1; i <= tot; i++) {
		for(int j = 0; j <= W; j++) {
			if(j >= sum2[i]) {
				f[i][j] = max(f[i - 1][j], f[i - 1][j - sum2[i]] + sum1[i]);
			}
			for(int k = 1; k <= sum3[i]; k++) {
				if(j >= sum[i][k].Z) {
					f[i][j] = max(f[i][j], max(f[i - 1][j], f[i - 1][j - sum[i][k].Z] + sum[i][k].B));
				}
			}
		}
	}
	printf("%d\n",  f[tot][W]);
}
int main()
{
	Init();
	pdo();
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int MaxN = 1e3;
int n, m, W;
LL f[MaxN + 5][MaxN + 5];
int father[MaxN + 5];
struct Node{
	int w; LL b;
}a[MaxN + 5];
vector<Node>p[MaxN + 5];

int Find(int x)
{
	if(father[x] == x) return x;
	return father[x] = Find(father[x]);
}

int main()
{
	scanf("%d%d%d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i].w);
	for(int i = 1; i <= n; i++) scanf("%I64d", &a[i].b);
	for(int i = 1; i <= n; i++) father[i] = i;
	for(int i = 1; i <= m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		if(Find(a) != Find(b)) father[Find(a)] = Find(b);
	}
	for(int i = 1; i <= n; i++)
		p[Find(i)].push_back(a[i]);
	for(int i = 1; i <= n; i++)
	{
		if(p[i].size() != 0)
		{
			Node t; t.w = 0; t.b = 0;
			for(int j = 0; j < p[i].size(); j++)
				t.w += p[i][j].w, t.b += p[i][j].b;
			p[i].push_back(t);
		}
	}
	for(int i = 0; i <= W; i++) f[0][i] = 0;
	int tot = 0;
	for(int i = 1; i <= n; i++)
	{
		if(p[i].size() != 0)
		{
			tot++;
			for(int j = 0; j < p[i].size(); j++)
			{
				for(int k = 1; k < p[i][j].w; k++)
					f[tot][k] = max(f[tot][k], f[tot - 1][k]);
				for(int k = p[i][j].w; k <= W; k++)
					f[tot][k] = max(f[tot][k], max(f[tot - 1][k], (f[tot - 1][k - p[i][j].w] + p[i][j].b)));
			}
		}
	}
	LL Max = -(1LL << 60);
	printf("%I64d\n", f[tot][W]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int m, n, w[1005], W, b[1005], father[1005];
int vis[1005], f[1005][1005], sum1[1005], sum2[1005], sum3[1005];
struct op{
	int num, B, Z;
}sum[1005][1005];
void Init()
{
	scanf("%d %d %d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]), father[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
}
int Find(int x)
{
	if(x == father[x]) return x;
	return father[x] = Find(father[x]);
}
void pdo()
{
	for(int i = 1; i <= m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		int u = Find(l), v = Find(r);
		if(u != v) father[u] = v;
	}
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		if(vis[u] == 0) {
			vis[u] = 1;
			tot++; int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(Find(j) == u) {
					cnt++;
					sum[tot][cnt].B = b[j]; sum1[tot] += b[j];
					sum[tot][cnt].Z = w[j]; sum2[tot] += w[j];
				}
			}
			sum3[tot] = cnt;
		}
	}
	memset(f, 0, sizeof(f));
	for(int i = 1; i <= tot; i++) {
		f[i][W] = max(f[i][W], f[i - 1][W]);
		for(int j = W; j >= 0; j--) {
			if(j >= sum2[i]) f[i][j] = max(f[i][j], f[i - 1][j - sum2[i]] + sum1[i]);
			for(int k = 1; k <= sum3[i]; k++) {
				if(j >= sum[i][k].Z)
					f[i][j] = max(f[i][j], f[i - 1][j - sum[i][k].Z] + sum[i][k].B);
			}
		}
	}
	printf("%d\n", f[tot][W]);
}
int main()
{
	Init();
	pdo();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int m, n, w[1005], W, b[1005], father[1005];
int vis[1005], f[1005][1005], sum1[1005], sum2[1005], sum3[1005];
struct op{
	int num, B, Z;
}sum[1005][1005];
void Init()
{
	scanf("%d %d %d", &n, &m, &W);
	for(int i = 1; i <= n; i++) scanf("%d", &w[i]), father[i] = i;
	for(int i = 1; i <= n; i++) scanf("%d", &b[i]);
}
int Find(int x)
{
	if(x == father[x]) return x;
	return father[x] = Find(father[x]);
}
void pdo()
{
	for(int i = 1; i <= m; i++) {
		int l, r; scanf("%d %d", &l, &r);
		int u = Find(l), v = Find(r);
		if(u != v) father[u] = v;
	}
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		int u = Find(i);
		if(vis[u] == 0) {
			vis[u] = 1;
			tot++; int cnt = 0;
			for(int j = 1; j <= n; j++) {
				if(Find(j) == u) {
					cnt++;
					sum[tot][cnt].B = b[j]; sum1[tot] += b[j];
					sum[tot][cnt].Z = w[j]; sum2[tot] += w[j];
				}
			}
			sum3[tot] = cnt;
		}
	}
	memset(f, 0, sizeof(f));
	int ans = -1;
	for(int i = 1; i <= tot; i++) {
		for(int j = 0; j <= W; j++) {
			if(j >= sum2[i]) {
				f[i][j] = max(f[i - 1][j], f[i - 1][j - sum2[i]] + sum1[i]);
				ans = max(ans, f[i][j]);
			}
			for(int k = 1; k <= sum3[i]; k++) {
				if(j >= sum[i][k].Z) {
					f[i][j] = max(f[i - 1][j], f[i - 1][j - sum[i][k].Z] + sum[i][k].B);
					ans = max(ans, f[i][j]);
				}
			}
			f[i][j] = ans;
		}
	}
	printf("%d\n", ans);
}
int main()
{
	Init();
	pdo();
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	x = getf(x);
	y = getf(y);
	if(x!=y)
		f[y] = x;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		int sz = g[i].size();
		if(sz==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;

		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<sz;j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	x = f[x];
	y = f[y];
	if(x!=y)
		f[y] = x;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		int sz = g[i].size();
		if(sz==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;

		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<sz;j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	if(f[p]==p) return p;
	f[p] = getf(f[p]);
	return f[p];
}

void merge(int x,int y)
{
	int f1,f2;
	f1 = f[x];
	f2 = f[y];
	if(f1!=f2)
		f[f2] = f1;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		if(g[i].size()==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;
//		if(g[i].size()==0)	continue;
		for(int j=0;j<w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<g[i].size();j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[!u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[!u][start],dp[!u][start-tw]+tb);
		}
	}

	int m = dp[u][w];
	for(int i=w-1;i>=0;i--)
	{
		if(dp[u][i]>m)
			m = dp[u][i];
	}
	cout<<m<<endl;
}


#include <bits/stdc++.h>
#define N 1005
using namespace std;
int a[N],b[N];
int p[N]; //p表示父节点
int dp[2][1005];
vector<int> G[N];

int find(int x) {
	return p[x]==x?x:p[x]=find(p[x]);
}
int Union(int x,int y) {
	x=find(x);
	y=find(y);
	if(x==y)return 0;
	p[y]=x;
	return 1;
}
void init(int n) {
	for(int i=1; i<=n; i++) {
		p[i]=i;  //warn:顶点从1开始,自行改修
	}
}

int main() {
	int n,m,w;
	scanf("%d%d%d",&n,&m,&w);
	init(n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		Union(u,v);
	}
	//for(int i=1;i<=n;i++)find(i);

	for(int i=1;i<=n;i++){
		G[find(i)].push_back(i);
	}
	int u=1;
	for(int i=1;i<=n;i++){
		int sz=G[i].size();
		if(sz==0)continue;

		u=!u;
		for(int j=0;j<=w;j++)dp[u][j]=dp[!u][j];
		int sa=0,sb=0;
		for(int j=0;j<sz;j++){
			int ta=a[G[i][j]],tb=b[G[i][j]];
			sa+=ta;
			sb+=tb;
			for(int k=ta;k<=w;k++){
				dp[u][k]=max(dp[u][k],dp[!u][k-ta]+tb);
			}
		}
		for(int k=sa;k<=w;k++){
			dp[u][k]=max(dp[u][k],dp[!u][k-sa]+sb);
		}
	}
	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	int f1,f2;
	f1 = f[x];
	f2 = f[y];
	if(f1!=f2)
		f[f2] = f1;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		int sz = g[i].size();
		if(sz==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;
//		if(g[i].size()==0)	continue;
		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<sz;j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define N=1005;
int a[N],b[N];
int p[N]; //p表示父节点
int find(int x) {
	return p[x]==x?x:p[x]=find(p[x]);
}
int Union(int x,int y) {
	x=find(x);
	y=find(y);
	if(x==y)return 0;
	p[y]=x;
	return 1;
}
void init(int n) {
	for(int i=1; i<=n; i++) {
		p[i]=i;  //warn:顶点从1开始,自行改修
	}
}
int dp[2][1005];
vector<int> G[N];

int main() {
	int n,m,w;
	scanf("%d%d%d",&n,&m,&w);
	init(n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		Union(u,v);
	}
	//for(int i=1;i<=n;i++)find(i);

	for(int i=1;i<=n;i++){
		G[find(i)].push_back(i);
	}
	int u=1;
	for(int i=1;i<=n;i++){
		int sz=G[i].size();
		if(sz==0)continue;

		u=!u;
		for(int j=0;j<=w;j++)dp[u][j]=dp[!u][j];
		int sa=0,sb=0;
		for(int j=0;j<sz;j++){
			int ta=a[G[i][j]],tb=b[G[i][j]];
			sa+=ta;
			sb+=tb;
			for(int k=ta;k<=w;k++){
				dp[u][k]=max(dp[u][k],dp[!u][k-ta]+tb);
			}
		}
		for(int k=sa;k<=w;k++){
			dp[u][k]=max(dp[u][k],dp[!u][k-sa]+sb);
		}
	}
	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	int f1,f2;
	f1 = f[x];
	f2 = f[y];
	if(f1!=f2)
		f[f2] = f1;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		if(g[i].size()==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;
//		if(g[i].size()==0)	continue;
		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<g[i].size();j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int m = dp[u][w];
	for(int i=w-1;i>=0;i--)
	{
		if(dp[u][i]>m)
			m = dp[u][i];
	}
	cout<<m<<endl;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	int f1,f2;
	f1 = f[x];
	f2 = f[y];
	if(f1!=f2)
		f[f2] = f1;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		int sz = g[i].size();
		if(sz==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;
//		if(g[i].size()==0)	continue;
		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<sz;j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int m = dp[u][w];
	for(int i=w-1;i>=0;i--)
	{
		if(dp[u][i]>m)
			m = dp[u][i];
	}
	cout<<m<<endl;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	if(f[p]==p) return p;
	f[p] = getf(f[p]);
	return f[p];
}

void merge(int x,int y)
{
	int f1,f2;
	f1 = f[x];
	f2 = f[y];
	if(f1!=f2)
		f[f2] = f1;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		if(g[i].size()==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;
//		if(g[i].size()==0)	continue;
		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<g[i].size();j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int m = dp[u][w];
	for(int i=w-1;i>=0;i--)
	{
		if(dp[u][i]>m)
			m = dp[u][i];
	}
	cout<<m<<endl;
}


#include <bits/stdc++.h>
#define LL long long
#define LEN 1005

using namespace std;

int f[LEN];
vector<int> g[LEN];
int dp[2][LEN];
int W[LEN];
int B[LEN];
int n,m,w;

void init()
{
	for(int i=1;i<=n;i++)
	{
		f[i] = i;
	}
}

int getf(int p)
{
	return f[p]==p?p:f[p]=getf(f[p]);
}

void merge(int x,int y)
{
	x = f[x];
	y = f[y];
	if(x!=y)
		f[y] = x;
}

int main()
{
	cin>>n>>m>>w;
	for(int i=1;i<=n;i++)
		scanf("%d",W+i);
	for(int i=1;i<=n;i++)
		scanf("%d",B+i);
	init();
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		merge(x,y);
	}

	for(int i=1;i<=n;i++)
	{
		g[getf(i)].push_back(i);
	}

	int u =1;
	for(int i=1;i<=n;i++)
	{
		int sz = g[i].size();
		if(sz==0)	continue;
		u = !u;
		int tw = 0;
		int tb = 0;

		for(int j=0;j<=w;j++)
			dp[u][j] = dp[!u][j];
		for(int j=0;j<sz;j++)
		{
			int cur = g[i][j];
			tw += W[cur];
			tb += B[cur];
			for(int start=W[cur];start<=w;start++)
				dp[u][start] = max(dp[u][start],dp[!u][start-W[cur]]+B[cur]);
		}

		for(int start=tw;start<=w;start++)
		{
			dp[u][start] = max(dp[u][start],dp[!u][start-tw]+tb);
		}
	}

	int ans=0;
	for(int i=0;i<=w;i++){
		ans=max(ans,dp[u][i]);
	}
	printf("%d\n",ans);
	return 0;


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <cctype>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <fstream>
#include <utility>
#include <cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define len length
#define mp make_pair
#define pp push_back
#define pf push_front
#define V(a) vector <a>
#define P(a,b) pair <a,b>
#define II pair <int, int>
#define sp(a) setprecision(a)
#define at(a) find_by_order(a)
#define ALL(a) a.begin(), a.end()
#define less_than(a) order_of_key(a)
#define mm(a,b) memset(a, b, sizeof a)
#define cwbits(a) __builtin_popcountll(a)

typedef long long int ll;
const double PI = acos(-1.0);
typedef unsigned long long int ull;
using namespace __gnu_pbds; using namespace std;
template <typename T> using ordered_set = tree<T,
null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

            /*                                Listen!                                */

ll n, m, w, vis[1010] = { 0 }; II seq[1010];

V(ll) g[1010];
ll gend[1010] = { 0 }, gsum1[1010] = { 0 }, gsum2[1010] = { 0 }, index = 0, block = 0, p[1010], gwho[1010];

void dfs(int u){
    if(vis[u]) return; vis[u] = 1; int size = g[u].size();
    p[index] = u; gend[block] = index; index ++; gwho[u] = block;
    gsum1[block] += seq[u].fi;
    gsum2[block] += seq[u].se;
    for (int i = 0 ; i < size; i ++){
        dfs(g[u][i]);
    }
}

ll dp[1010][1010];

ll rec(int in, int w){
    if(in == index) return 0;
    if (dp[in][w] != -1) return dp[in][w]; dp[in][w] = -1e12;
    if (in == 0 || (in > 0 && gend[gwho[in - 1]] == in - 1)){
        dp[in][w] = rec(gend[gwho[in]] + 1, w);
        if(gsum1[gwho[in]] <= w)
            dp[in][w] = max(dp[in][w], gsum2[gwho[in]] + rec(gend[gwho[in]] + 1, w - gsum1[gwho[in]]));
        for (int i = in; i <= gend[gwho[in]]; i ++){
            if(seq[p[i]].fi <= w)
                dp[i][w] = max(dp[i][w], seq[p[i]].se + rec(gend[gwho[in]] + 1, w - seq[p[i]].fi));
        }
    }
    /*else {
        if(seq[p[in]].fi <= w)
            dp[in][w] = max(dp[in][w], seq[p[in]].se + rec(in + 1, w - seq[p[in]].fi));
        else return dp[in][w] = -1e11;
    } */
    return dp[in][w];
}

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> w; mm(dp, -1); int x, y;

    for (int i = 0 ; i < n ; i ++)
        cin >> seq[i].fi;

    for (int i = 0 ; i < n ; i ++)
        cin >> seq[i].se;

    for (int i = 0 ; i < m; i ++){
        cin >> x >> y; x--; y--;
        g[x].pp(y); g[y].pp(x);
    }

    for (int i = 0; i < n; i ++){
        if(!vis[i]){
            dfs(i); block++;
        }
    }

    ll ans = rec(0, w);

    if (ans < 0) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <cctype>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <fstream>
#include <utility>
#include <cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define fi first
#define se second
#define len length
#define mp make_pair
#define pp push_back
#define pf push_front
#define V(a) vector <a>
#define P(a,b) pair <a,b>
#define II pair <int, int>
#define sp(a) setprecision(a)
#define at(a) find_by_order(a)
#define ALL(a) a.begin(), a.end()
#define less_than(a) order_of_key(a)
#define mm(a,b) memset(a, b, sizeof a)
#define cwbits(a) __builtin_popcountll(a)

typedef long long int ll;
const double PI = acos(-1.0);
typedef unsigned long long int ull;
using namespace __gnu_pbds; using namespace std;
template <typename T> using ordered_set = tree<T,
null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

            /*                                Listen!                                */

int n, m, w, vis[1010] = { 0 }; II seq[1010];

V(int) g[1010];
ll gend[1010] = { 0 }, gsum1[1010] = { 0 }, gsum2[1010] = { 0 }, index = 0, block = 0, p[1010], gwho[1010];

void dfs(int u){
    if(vis[u]) return; vis[u] = 1; int size = g[u].size();
    p[index] = u; gend[block] = index; index ++; gwho[u] = block;
    gsum1[block] += seq[u].fi;
    gsum2[block] += seq[u].se;
    for (int i = 0 ; i < size; i ++){
        dfs(g[u][i]);
    }
}

ll dp[1010][1010];

ll rec(int in, int w){
    if(in == index) return 0;
    if (dp[in][w] != -1) return dp[in][w]; dp[in][w] = -1e11;
    if (in == 0 || (in > 0 && gend[gwho[in - 1]] == in - 1)){
        dp[in][w] = rec(gend[gwho[in]] + 1, w);
        if(gsum1[gwho[in]] <= w)
            dp[in][w] = max(dp[in][w], gsum2[gwho[in]] + rec(gend[gwho[in]] + 1, w - gsum1[gwho[in]]));
        if(seq[p[in]].fi <= w)
            dp[in][w] = max(dp[in][w], seq[p[in]].se + rec(in + 1, w - seq[p[in]].fi));
        for (int i = in; i <= gend[gwho[in]]; i ++){
            if(seq[p[i]].fi <= w)
                dp[i][w] = max(dp[i][w], seq[p[i]].se + rec(gend[gwho[in]] + 1, w - seq[p[i]].fi));
        }
    }
    /*else {
        if(seq[p[in]].fi <= w)
            dp[in][w] = max(dp[in][w], seq[p[in]].se + rec(in + 1, w - seq[p[in]].fi));
        else return dp[in][w] = -1e11;
    } */
    return dp[in][w];
}

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> n >> m >> w; mm(dp, -1); int x, y;

    for (int i = 0 ; i < n ; i ++)
        cin >> seq[i].fi;

    for (int i = 0 ; i < n ; i ++)
        cin >> seq[i].se;

    for (int i = 0 ; i < m; i ++){
        cin >> x >> y; x--; y--;
        g[x].pp(y); g[y].pp(x);
    }

    for (int i = 0; i < n; i ++){
        if(!vis[i]){
            dfs(i); block++;
        }
    }

    cout << rec(0, w) << endl;

    return 0;
}


/*
░░░░██████████████████
░░▄███████▀▀▀▀▀▀███████▄
░▐████▀▒mohammad▒▀██████▄
░███▀▒▒▒▒alaa▒▒▒▒▒▒▀█████
░▐██▒▒▒alwrawrah▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
*/

#include "iostream"
#include "vector"
#include "map"
#include "math.h"
#include "string"
#include "algorithm"
#include "set"
#include <iterator>
#include <string.h>
#include <queue>

using namespace	std;

typedef long long ll ;

int da , n , m , l[100010] , r[100010] , u[100010] , d[100010] , y[100010] , x[100010] , x2[100010] , y2[100010];

int main(){
	scanf("%lld %lld %lld" ,& da ,&n ,& m);
	for(int i = 0 ; i < da ; ++i){
		scanf("%lld %lld %lld %lld" ,& x[i] ,& y[i] ,& x2[i] ,& y2[i]);
		if(x[i] > x2[i])
			swap(x[i],x2[i]);
		if(y[i] > y2[i])
			swap(y[i],y2[i]);
		l[y[i]]++;
		r[y2[i]]++;
		u[x[i]]++;
		d[x2[i]]++;
	}
	ll cr , cl , cu , cd ;
	cin >> cu >> cd >> cl >> cr ;
	for(int i = 1 ; i < 100000 ; ++i)l[i] += l[i-1];
	for(int i = 100000 ; i >= 1 ; --i)r[i] += r[i+1];
	for(int i = 100000 ; i >= 1 ; --i)d[i] += d[i+1];
	for(int i = 1 ; i < 100000 ; ++i)u[i] += u[i-1];

	for (int i = 0 ; i < da ; i++){
		if (l[ y2[i] - 1 ] - ( y[i] != y2[i] ) == cl && r[y[i] + 1]-(y[i] != y2[i]) == cr && u[x2[i] - 1] - (x[i] != x2[i]) == cu && d[x[i] +1 ] - (x[i] != x2[i]) == cd){
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int maxn=1e5+10;
const int mod=1000000000+7;
const double eps=1e-6;

P a[maxn],b[maxn];
int d,n,m;
int x1[maxn],y1[maxn],x2[maxn],y2[maxn];
int cl,cr,cu,cd;
int main() {
  //  freopen("test.txt","r",stdin);
    cin>>d;
    cin>>n>>m;
    for(int i=1;i<=d;i++) {
        cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
        if(x1[i]<=x2[i]) {
            a[i]=P(x1[i],x2[i]);
            b[i]=P(y1[i],y2[i]);
        } else {
            a[i]=P(x2[i],x1[i]);
            b[i]=P(y2[i],y1[i]);
        }
    }
    cin>>cl>>cr>>cu>>cd;

    sort(a+1,a+1+d);
    sort(b+1,b+1+d);

    vector<int>ans;

    for(int i=1;i<=d;i++) {
        int cll=0,crr=0,cuu=0,cdd=0;
        if(x1[i]>x2[i]) {
            swap(x1[i],x2[i]);
            swap(y2[i],y2[i]);
        }
        P t(x1[i],x2[i]);
        int p1=lower_bound(a+1,a+1+d,t)-a;
        int p2=upper_bound(a+1,a+1+d,t)-a;
        if(x1[i]==x2[i]) {
            cll+=p1-1;
            crr+=d-p2+1;
        } else {
            cll+=p1-1+(p2-p1)-1;
            crr+=d-p1+1-1;
        }
        t=P(y1[i],y2[i]);
        int p3=lower_bound(b+1,b+1+d,t)-b;
        int p4=upper_bound(b+1,b+1+d,t)-b;
        if(y1[i]==y2[i]) {
            cuu+=p3-1;
            cdd+=d-p4+1;
        } else {
            cuu+=p3-1+(p4-p3)-1;
            cdd+=d-p3+1-1;
        }
        if(cl==cll&&cr==crr&&cu==cuu&&cd==cdd)
            ans.push_back(i);
    }
    for(auto x:ans)
        cout<<x<<" ";
    if(ans.empty())
        cout<<-1<<endl;
    return 0;
}
/*
1.变量范围经常搞错，也就是临界情况不清晰
  1.1 加上一点，诸如下标从0~n-1的情况，对于某个其中的值，经常搞错个数和下标
2.经常性读错题目，尤其是看英文题面的情况下
3.结合上一点，如果是英文题面，一定要英文，只准翻译单个单词，逼着自己看英文题面
4.for循环中的i爆LL可能很难注意到
5.千万不要忽视轻视简单的问题
6.不看可能让自己感到焦虑的东西
7.%优先级高于+=，*=；取模时应注意
8.add一条边的时候，注意是否是双向边！！！
9.1<<i 移位时如果i过大。可能会出现shift too large的错误 所以要强制转化为LL类型(爆LL的话，那么打表，求出2的幂并取模)
10.注意一个数是否存在关于另一个数的逆元
11.注意命名冲突
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int maxn=1e5+10;
const int mod=1000000000+7;
const double eps=1e-6;

P a[maxn],b[maxn];
int d,n,m;
int x1[maxn],y1[maxn],x2[maxn],y2[maxn];
int cl,cr,cu,cd;
int main() {
  //  freopen("test.txt","r",stdin);
    cin>>d;
    cin>>n>>m;
    for(int i=1;i<=d;i++) {
        cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
        if(x1[i]<=x2[i]) {
            a[i]=P(x1[i],x2[i]);
            b[i]=P(y1[i],y2[i]);
        } else {
            a[i]=P(x2[i],x1[i]);
            b[i]=P(y2[i],y1[i]);
        }
    }
    cin>>cl>>cr>>cu>>cd;

    sort(a+1,a+1+d);
    sort(b+1,b+1+d);

    int ans=-1;

    for(int i=1;i<=d;i++) {
        int cll=0,crr=0,cuu=0,cdd=0;
        if(x1[i]>x2[i]) {
            swap(x1[i],x2[i]);
            swap(y2[i],y2[i]);
        }
        P t(x1[i],x2[i]);
        int p1=lower_bound(a+1,a+1+d,t)-a;
        int p2=upper_bound(a+1,a+1+d,t)-a;
        if(x1[i]==x2[i]) {
            cll+=p1-1;
            crr+=d-p2+1;
        } else {
            //减去自身
            cll+=p1-1+(p2-p1)-1;
            crr+=d-p1+1-1;
        }
        t=P(y1[i],y2[i]);
        int p3=lower_bound(b+1,b+1+d,t)-b;
        int p4=upper_bound(b+1,b+1+d,t)-b;
       // cout<<"-------------"<<p3<<" "<<p4<<endl;
        if(y1[i]==y2[i]) {
            cuu+=p3-1;
            cdd+=d-p4+1;
        } else {
            cuu+=p3-1+(p4-p3)-1;
            cdd+=d-p3+1-1;
        }
        //cout<<"-----"<<cll<<" "<<crr<<" "<<cuu<<" "<<cdd<<endl;
        if(cl==cll&&cr==crr&&cu==cuu&&cd==cdd)
            ans=i;
    }
    cout<<ans<<endl;
    return 0;
}
/*
1.变量范围经常搞错，也就是临界情况不清晰
  1.1 加上一点，诸如下标从0~n-1的情况，对于某个其中的值，经常搞错个数和下标
2.经常性读错题目，尤其是看英文题面的情况下
3.结合上一点，如果是英文题面，一定要英文，只准翻译单个单词，逼着自己看英文题面
4.for循环中的i爆LL可能很难注意到
5.千万不要忽视轻视简单的问题
6.不看可能让自己感到焦虑的东西
7.%优先级高于+=，*=；取模时应注意
8.add一条边的时候，注意是否是双向边！！！
9.1<<i 移位时如果i过大。可能会出现shift too large的错误 所以要强制转化为LL类型(爆LL的话，那么打表，求出2的幂并取模)
10.注意一个数是否存在关于另一个数的逆元
11.注意命名冲突
*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

const int maxn=1e5+10;
const int mod=1000000000+7;
const double eps=1e-6;

P a[maxn],b[maxn];
int d,n,m;
int x1[maxn],y1[maxn],x2[maxn],y2[maxn];
int cl,cr,cu,cd;
int main() {
  //  freopen("test.txt","r",stdin);
    cin>>d;
    cin>>n>>m;
    for(int i=1;i<=d;i++) {
        cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
        if( (x1[i]==x2[i]&&y1[i]>y2[i]) || x1[i]>x2[i] ) {
            swap(x1[i],x2[i]);
            swap(y1[i],y2[i]);
        }
        a[i]=P(x1[i],x2[i]);
        b[i]=P(y1[i],y2[i]);
    }
    cin>>cl>>cr>>cu>>cd;

    sort(a+1,a+1+d);
    sort(b+1,b+1+d);

    vector<int>ans;

    for(int i=1;i<=d;i++) {
        int cll=0,crr=0,cuu=0,cdd=0;
        P t(x1[i],x2[i]);
        int p1=lower_bound(a+1,a+1+d,t)-a;
        int p2=upper_bound(a+1,a+1+d,t)-a;
        if(x1[i]==x2[i]) {
            cll+=p1-1;
            crr+=d-p2+1;
        } else {
            cll+=p1-1+(p2-p1)-1;
            crr+=d-p1+1-1;
        }
        t=P(y1[i],y2[i]);
        int p3=lower_bound(b+1,b+1+d,t)-b;
        int p4=upper_bound(b+1,b+1+d,t)-b;
        if(y1[i]==y2[i]) {
            cuu+=p3-1;
            cdd+=d-p4+1;
        } else {
            cuu+=p3-1+(p4-p3)-1;
            cdd+=d-p3+1-1;
        }
        if(cl==cll&&cr==crr&&cu==cuu&&cd==cdd)
            ans.push_back(i);
    }
    for(auto x:ans)
        cout<<x<<" ";
    if(ans.empty())
        cout<<-1<<endl;
    return 0;
}
/*
1.变量范围经常搞错，也就是临界情况不清晰
  1.1 加上一点，诸如下标从0~n-1的情况，对于某个其中的值，经常搞错个数和下标
2.经常性读错题目，尤其是看英文题面的情况下
3.结合上一点，如果是英文题面，一定要英文，只准翻译单个单词，逼着自己看英文题面
4.for循环中的i爆LL可能很难注意到
5.千万不要忽视轻视简单的问题
6.不看可能让自己感到焦虑的东西
7.%优先级高于+=，*=；取模时应注意
8.add一条边的时候，注意是否是双向边！！！
9.1<<i 移位时如果i过大。可能会出现shift too large的错误 所以要强制转化为LL类型(爆LL的话，那么打表，求出2的幂并取模)
10.注意一个数是否存在关于另一个数的逆元
11.注意命名冲突
*/


#include <cstdio>
#include <algorithm>

using namespace std;

class sofa_search
{
    static constexpr int directions = 4;

    enum diretion { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };

    struct point_t { size_t x, y; };

    class proximity_t
    {
    protected:

        size_t count[ directions ];

    public:

        proximity_t( size_t left = 0, size_t right = 0, size_t top = 0, size_t bottom = 0 )
        {
            count[ LEFT ] = left, count[ RIGHT ] = right, count[ TOP ] = top, count [ BOTTOM ] = bottom;
        }

        void read()
        {
            for( size_t i = 0, *p = count; i < directions; i++, scanf( "%u", p++ ) );
        }

        size_t& operator[]( diretion i ) { return count[ i ]; }

        bool found( const proximity_t *p )
        {
            bool answer = true;

            for( size_t i = 0; answer && i < directions; i++ )
                answer = ( count[ i ] == p->count[ i ] );

            return answer;
        }

    } proximity[ 100001 ]; size_t n, m;

    class sofa_t: public proximity_t
    {
        point_t u, v;

    public:

        void read( proximity_t *p )
        {
            point_t a, b; scanf( "%u%u%u%u", &a.x, &a.y, &b.x, &b.y );

            p[ u.x = min( a.x, b.x ) ][ LEFT   ]++,
            p[ v.x = max( a.x, b.x ) ][ RIGHT  ]++,
            p[ u.y = min( a.y, b.y ) ][ TOP    ]++,
            p[ v.y = max( a.y, b.y ) ][ BOTTOM ]++;
        }

        void compute_proximity( proximity_t *p )
        {
            size_t ux = u.x, uy = u.y, vx = v.x, vy = v.y;

            count[ LEFT   ] = p[ vx - 1 ][ LEFT   ]; if ( ux != vx ) count[ LEFT   ]--;

            count[ RIGHT  ] = p[ ux + 1 ][ RIGHT  ]; if ( ux != vx ) count[ RIGHT  ]--;

            count[ TOP    ] = p[ vy - 1 ][ TOP    ]; if ( uy != vy ) count[ TOP    ]--;

            count[ BOTTOM ] = p[ uy + 1 ][ BOTTOM ]; if ( uy != vy ) count[ BOTTOM ]--;
        }

    } sofa[ 100000 ]; size_t d;

    void storehouse_proximity()
    {
        for( size_t x1 = 1, x2 = 2; x1 < n; x1 = x2++ )
            proximity[ x2 ][ LEFT ] += proximity[ x1 ][ LEFT ];

        for( size_t x1 = n, x2 = n - 1; x1 > 1; x1 = x2-- )
            proximity[ x2 ][ RIGHT ] += proximity[ x1 ][ RIGHT ];

        for( size_t y1 = 1, y2 = 2; y1 < m; y1 = y2++ )
            proximity[ y2 ][ TOP ] += proximity[ y1 ][ TOP ];

        for( size_t y1 = m, y2 = m - 1; y1 > 1; y1 = y2-- )
            proximity[ y2 ][ BOTTOM ] += proximity[ y1 ][ BOTTOM ];
    }

public:

    sofa_search()
    {
        scanf( "%u%u%u", &d, &n, &m );

        for( size_t i = 0; i < d; sofa[ i++ ].read( proximity ) );

        proximity[ 0 ].read(); storehouse_proximity();
    }

    int solution()
    {
        for( size_t i = 0; i < d; i++ )
        {
            sofa[ i ].compute_proximity( proximity );

            if ( sofa[ i ].found( proximity ) )
                return i + 1;
        }

        return -1;
    }

} problem;

int main()
{
    printf( "%i", problem.solution() );
}


#include <cstdio>
#include <algorithm>

using namespace std;

class sofa_search
{
    static constexpr int directions = 4;

    enum diretion { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };

    class point_t
    {
        size_t x, y;

    public:

        point_t( size_t xi = 0, size_t yi = 0 ) : x( xi ), y( yi ) {}

        void read() { scanf( "%u%u", &x, &y ); }

        size_t horizontal() const { return x; }

        size_t   vertical() const { return y; }

        friend point_t min( point_t &p1, point_t &p2 )
        {
            return point_t( min( p1.x, p2.x ), min( p1.y, p2.y ) );
        }

        friend point_t max( point_t &p1, point_t &p2 )
        {
            return point_t( max( p1.x, p2.x ), max( p1.y, p2.y ) );
        }

    };

    class proximity_t
    {
    protected:

        size_t count[ directions ];

    public:

        proximity_t( size_t left = 0, size_t right = 0, size_t top = 0, size_t bottom = 0 )
        {
            count[ LEFT ] = left, count[ RIGHT ] = right, count[ TOP ] = top, count [ BOTTOM ] = bottom;
        }

        void read()
        {
            for( size_t i = 0, *p = count; i < directions; i++, scanf( "%u", p++ ) );
        }

        size_t& operator[]( diretion i ) { return count[ i ]; }

        bool found( proximity_t &p )
        {
            bool answer = true;

            for( size_t i = 0; answer && i < directions; answer = ( count[ i ] == p.count[ i ] ), i++ );

            return answer;
        }

    } proximity[ 100001 ]; size_t n, m;

    class sofa_t: public proximity_t
    {
        point_t u, v;

    public:

        void read( proximity_t *p )
        {
            point_t a, b; a.read(); b.read(); u = min( a, b ), v = max( a, b );

            p[ u.horizontal() ][ LEFT   ]++,
            p[ v.horizontal() ][ RIGHT  ]++,
            p[ u.vertical()   ][ TOP    ]++,
            p[ v.vertical()   ][ BOTTOM ]++;
        }

        void compute_proximity( proximity_t *p )
        {
            size_t ux = u.horizontal(), uy = u.vertical(), vx = v.horizontal(), vy = v.vertical();

            count[ LEFT   ] = p[ vx - 1 ][ LEFT   ]; if ( ux != vx ) count[ LEFT   ]--;

            count[ RIGHT  ] = p[ ux + 1 ][ RIGHT  ]; if ( ux != vx ) count[ RIGHT  ]--;

            count[ TOP    ] = p[ vy - 1 ][ TOP    ]; if ( uy != vy ) count[ TOP    ]--;

            count[ BOTTOM ] = p[ uy + 1 ][ BOTTOM ]; if ( uy != vy ) count[ BOTTOM ]--;
        }

    } sofa[ 100000 ]; size_t d;

    void storehouse_proximity()
    {
        for( size_t x1 = 1, x2 = 2; x1 < n; x1 = x2++ )
            proximity[ x2 ][ LEFT ] += proximity[ x1 ][ LEFT ];

        for( size_t x1 = n, x2 = n - 1; x1 > 1; x1 = x2-- )
            proximity[ x2 ][ RIGHT ] += proximity[ x1 ][ RIGHT ];

        for( size_t y1 = 1, y2 = 2; y1 < m; y1 = y2++ )
            proximity[ y2 ][ TOP ] += proximity[ y1 ][ TOP ];

        for( size_t y1 = m, y2 = m - 1; y1 > 1; y1 = y2-- )
            proximity[ y2 ][ BOTTOM ] += proximity[ y1 ][ BOTTOM ];
    }

public:

    sofa_search()
    {
        scanf( "%u%u%u", &d, &n, &m );

        for( size_t i = 0; i < d; sofa[ i++ ].read( proximity ) );

        proximity[ 0 ].read(); storehouse_proximity();
    }

    int solution()
    {
        for( size_t i = 0; i < d; i++ )
        {
            sofa[ i ].compute_proximity( proximity );

            if ( sofa[ i ].found( proximity[ 0 ] ) )
                return i + 1;
        }

        return -1;
    }

} problem;

int main()
{
    printf( "%i", problem.solution() );
}


#include <cstdio>
#include <algorithm>

using namespace std;

class sofa_search
{
    static constexpr int directions = 4;

    enum diretion { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };

    class point_t
    {
        size_t x, y;

    public:
        void read() { scanf( "%u%u", &x, &y ); }

        size_t horizontal() const { return x; }

        size_t   vertical() const { return y; }

        friend point_t min( point_t &p1, point_t &p2 ) { point_t p; p.x = min( p1.x, p2.x ), p.y = min( p1.y, p2.y ); return p; }

        friend point_t max( point_t &p1, point_t &p2 ) { point_t p; p.x = max( p1.x, p2.x ), p.y = max( p1.y, p2.y ); return p; }

    };

    class proximity_t
    {
    protected:

        size_t count[ directions ];

    public:

        proximity_t( size_t left = 0, size_t right = 0, size_t top = 0, size_t bottom = 0 )
        {
            count[ LEFT ] = left, count[ RIGHT ] = right, count[ TOP ] = top, count [ BOTTOM ] = bottom;
        }

        void read()
        {
            for( size_t i = 0, *p = count; i < directions; i++, scanf( "%u", p++ ) );
        }

        size_t& operator[]( diretion i ) { return count[ i ]; }

        bool found( proximity_t &p )
        {
            bool answer = true;

            for( size_t i = 0; answer && i < directions; answer = ( count[ i ] == p.count[ i ] ), i++ );

            return answer;
        }

    } proximity[ 100001 ]; size_t n, m;

    class sofa_t: public proximity_t
    {
        point_t u, v;

    public:

        void read( proximity_t *p )
        {
            point_t a, b; a.read(); b.read();

            u = min( a, b ), v = max( a, b ), p[ u.horizontal() ][ LEFT ]++, p[ v.horizontal() ][ RIGHT ]++, p[ u.vertical() ][ TOP ]++, p[ v.vertical() ][ BOTTOM ]++;
        }

        void compute_proximity( proximity_t *p )
        {
            size_t ux = u.horizontal(), uy = u.vertical(), vx = v.horizontal(), vy = v.vertical();

            count[ LEFT   ] = p[ vx - 1 ][ LEFT   ]; if ( ux != vx ) count[ LEFT   ]--;

            count[ RIGHT  ] = p[ ux + 1 ][ RIGHT  ]; if ( ux != vx ) count[ RIGHT  ]--;

            count[ TOP    ] = p[ vy - 1 ][ TOP    ]; if ( uy != vy ) count[ TOP    ]--;

            count[ BOTTOM ] = p[ uy + 1 ][ BOTTOM ]; if ( uy != vy ) count[ BOTTOM ]--;
        }

    } sofa[ 100000 ]; size_t d;

    void storehouse_proximity()
    {
        for( size_t x1 = 1, x2 = 2; x1 < n; x1 = x2++ )
            proximity[ x2 ][ LEFT ] += proximity[ x1 ][ LEFT ];

        for( size_t x1 = n, x2 = n - 1; x1 > 1; x1 = x2-- )
            proximity[ x2 ][ RIGHT ] += proximity[ x1 ][ RIGHT ];

        for( size_t y1 = 1, y2 = 2; y1 < m; y1 = y2++ )
            proximity[ y2 ][ TOP ] += proximity[ y1 ][ TOP ];

        for( size_t y1 = m, y2 = m - 1; y1 > 1; y1 = y2-- )
            proximity[ y2 ][ BOTTOM ] += proximity[ y1 ][ BOTTOM ];
    }

public:

    sofa_search()
    {
        scanf( "%u%u%u", &d, &n, &m );

        for( size_t i = 0; i < d; sofa[ i++ ].read( proximity ) );

        proximity[ 0 ].read(); storehouse_proximity();
    }

    int solution()
    {
        for( size_t i = 0; i < d; i++ )
        {
            sofa[ i ].compute_proximity( proximity );

            if ( sofa[ i ].found( proximity[ 0 ] ) )
                return i + 1;
        }

        return -1;
    }

} problem;

int main()
{
    printf( "%i", problem.solution() );
}


#include <cstdio>
#include <cassert>
#include <algorithm>

using namespace std;

class point_t
{
    size_t x, y;

public:
    void read() { scanf( "%u%u", &x, &y ); }

    bool above( point_t &p ) { return y < p.y; }

    bool below( point_t &p ) { return y > p.y; }

    bool  left( point_t &p ) { return x < p.x; }

    bool right( point_t &p ) { return x > p.x; }

    friend point_t min( point_t &p1, point_t &p2 ) { point_t p; p.x = min( p1.x, p2.x ), p.y = min( p1.y, p2.y ); return p; }

    friend point_t max( point_t &p1, point_t &p2 ) { point_t p; p.x = max( p1.x, p2.x ), p.y = max( p1.y, p2.y ); return p; }

};

class proximity_t
{

protected:

    size_t left, right, top, bottom;

public:

    proximity_t() : left( 0 ), right( 0 ), top( 0 ), bottom( 0 ) {}

    void read() { scanf( "%u%u%u%u", &left, &right, &top, &bottom ); }

    bool matched( proximity_t &p ) { return left == p.left && right == p.right && top == p.top && bottom == p.bottom; }

} proximity;

class sofa_t: public proximity_t
{
    point_t p1, p2;

public:

    void read()
    {
        point_t q1, q2; q1.read(); q2.read(); p1 = min( q1, q2 ), p2 = max( q1, q2 );
    }

    void proximity( sofa_t &s )
    {
        if ( p1.below( s.p1 ) || p1.below( s.p2 ) || p2.below( s.p1 ) || p2.below( s.p2 ) )
            top++, s.bottom++;

        if ( p1.above( s.p1 ) || p1.above( s.p2 ) || p2.above( s.p1 ) || p2.above( s.p2 ) )
            bottom++, s.top++;

        if ( p1.left( s.p1 ) || p1.left( s.p2 ) || p2.left( s.p1 ) || p2.left( s.p2 ) )
            right++, s.left++;

        if ( p1.right( s.p1 ) || p1.right( s.p2 ) || p2.right( s.p1 ) || p2.right( s.p2 ) )
            left++, s.right++;
    }

} sofa[ 100000 ];

int main()
{
    size_t d, n, m; scanf( "%u%u%u", &d, &n, &m );

    for( size_t i = 0; i < d; i++ )
    {
        sofa[ i ].read();

        for( size_t j = 0; j < i; j++ )
            sofa[ i ].proximity( sofa[ j ] );
    }

    proximity.read();

    for( size_t i = 0, j = 1; i < d; i = j++ )
        if ( sofa[ i ].matched( proximity ) )
        {
            printf( "%u", j ); return 0;
        }

    printf( "-1" );
}


#include <cstdio>
#include <algorithm>

using namespace std;

class sofa_search
{
    static constexpr uint8_t directions = 4;

    enum diretion { LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3 };

    class point_t
    {
        size_t x, y;

    public:
        void read() { scanf( "%u%u", &x, &y ); }

        size_t horizontal() const { return x; }

        size_t   vertical() const { return y; }

        friend point_t min( point_t &p1, point_t &p2 ) { point_t p; p.x = min( p1.x, p2.x ), p.y = min( p1.y, p2.y ); return p; }

        friend point_t max( point_t &p1, point_t &p2 ) { point_t p; p.x = max( p1.x, p2.x ), p.y = max( p1.y, p2.y ); return p; }

    };

    class proximity_t
    {
    protected:

        size_t count[ directions ];

    public:

        proximity_t( size_t left = 0, size_t right = 0, size_t top = 0, size_t bottom = 0 )
        {
            count[ LEFT ] = left, count[ RIGHT ] = right, count[ TOP ] = top, count [ BOTTOM ] = bottom;
        }

        void read()
        {
            for( size_t i = 0, *p = count; i < directions; i++, scanf( "%u", p++ ) );
        }

        size_t& operator[]( diretion i ) { return count[ i ]; }

        bool found( proximity_t &p )
        {
            bool answer = true;

            for( size_t i = 0; answer && i < directions; answer = ( count[ i ] == p.count[ i ] ), i++ );

            return answer;
        }

    } proximity[ 100001 ]; size_t n, m;

    class sofa_t: public proximity_t
    {
        point_t u, v;

    public:

        void read( proximity_t *p )
        {
            point_t a, b; a.read(); b.read();

            u = min( a, b ), v = max( a, b ), p[ u.horizontal() ][ LEFT ]++, p[ v.horizontal() ][ RIGHT ]++, p[ u.vertical() ][ TOP ]++, p[ v.vertical() ][ BOTTOM ]++;
        }

        void compute_proximity( proximity_t *p )
        {
            size_t ux = u.horizontal(), uy = u.vertical(), vx = v.horizontal(), vy = v.vertical();

            count[ LEFT   ] = p[ vx - 1 ][ LEFT   ]; if ( ux != vx ) count[ LEFT   ]--;

            count[ RIGHT  ] = p[ ux + 1 ][ RIGHT  ]; if ( ux != vx ) count[ RIGHT  ]--;

            count[ TOP    ] = p[ vy - 1 ][ TOP    ]; if ( uy != vy ) count[ TOP    ]--;

            count[ BOTTOM ] = p[ uy + 1 ][ BOTTOM ]; if ( uy != vy ) count[ BOTTOM ]--;
        }

    } sofa[ 100000 ]; size_t d;

    void storehouse_proximity()
    {
        for( size_t x1 = 1, x2 = 2; x1 < n; x1 = x2++ )
            proximity[ x2 ][ LEFT ] += proximity[ x1 ][ LEFT ];

        for( size_t x1 = n, x2 = n - 1; x1 > 1; x1 = x2-- )
            proximity[ x2 ][ RIGHT ] += proximity[ x1 ][ RIGHT ];

        for( size_t y1 = 1, y2 = 2; y1 < m; y1 = y2++ )
            proximity[ y2 ][ TOP ] += proximity[ y1 ][ TOP ];

        for( size_t y1 = m, y2 = m - 1; y1 > 1; y1 = y2-- )
            proximity[ y2 ][ BOTTOM ] += proximity[ y1 ][ BOTTOM ];
    }

public:

    sofa_search()
    {
        scanf( "%u%u%u", &d, &n, &m );

        for( size_t i = 0; i < d; sofa[ i++ ].read( proximity ) );

        proximity[ 0 ].read(); storehouse_proximity();
    }

    int solution()
    {
        for( size_t i = 0; i < d; i++ )
        {
            sofa[ i ].compute_proximity( proximity );

            if ( sofa[ i ].found( proximity[ 0 ] ) )
                return i + 1;
        }

        return -1;
    }

} problem;

int main()
{
    printf( "%i", problem.solution() );
}


#include <cstdio>
#include <cassert>
#include <algorithm>

using namespace std;

inline int valid( size_t k, size_t min = 1, size_t max = 100000 )
{
    assert( k >= min && k <= max ); return 0;
}

size_t horizontal_sofas = 0, vertical_sofas = 0;

struct proximity_t
{
    size_t left, right, top, bottom; bool invalid;

    proximity_t() : left( 0 ), right( 0 ), top( 0 ), bottom( 0 ) {}

    void read()
    {
        scanf( "%u%u%u%u", &left, &right, &top, &bottom );
    }

    bool matched( proximity_t &p )
    {
        return left == p.left && right == p.right && top == p.top && bottom == p.bottom;
    }
};

struct horizontal_sofa_t: public proximity_t
{
    size_t id, y, x1, x2;

    void new_sofa( size_t i, size_t yi, size_t w1, size_t w2 )
    {
        assert( ( w2 - w1 ) == 1 ); id = i, y = yi, x1 = w1, x2 = w2;
    }

} horizontal_sofa[ 100000 ];

struct vertical_sofa_t: public proximity_t
{
    size_t id, x, y1, y2;

    void new_sofa( size_t i, size_t xi, size_t w1, size_t w2 )
    {
        assert( ( w2 - w1 ) == 1 ); id = i, x = xi, y1 = w1, y2 = w2;
    }

} vertical_sofa[ 100000 ];

size_t d, n, m;

void vertical_horizontal_proximity( size_t i, size_t j )
{
    if( vertical_sofa[ i ].x < horizontal_sofa[ j ].x2 )
        vertical_sofa[ i ].right++, horizontal_sofa[ j ].left++;

    if( vertical_sofa[ i ].x > horizontal_sofa[ j ].x1 )
        vertical_sofa[ i ].left++, horizontal_sofa[ j ].right++;

    if( vertical_sofa[ i ].y1 < horizontal_sofa[ j ].y )
        vertical_sofa[ i ].bottom++, horizontal_sofa[ j ].top++;

    if( vertical_sofa[ i ].y2 > horizontal_sofa[ j ].y )
        vertical_sofa[ i ].top++, horizontal_sofa[ j ].bottom++;
}

void vertical_vertical_proximity( size_t i, size_t j )
{
    if( vertical_sofa[ i ].x < vertical_sofa[ j ].x )
        vertical_sofa[ i ].right++, vertical_sofa[ j ].left++;

    if( vertical_sofa[ i ].x > vertical_sofa[ j ].x )
        vertical_sofa[ i ].left++, vertical_sofa[ j ].right++;

    if( vertical_sofa[ i ].y1 < vertical_sofa[ j ].y2 )
        vertical_sofa[ i ].bottom++, vertical_sofa[ j ].top++;

    if( vertical_sofa[ i ].y2 > vertical_sofa[ j ].y1 )
        vertical_sofa[ i ].top++, vertical_sofa[ j ].bottom++;
}

void horizontal_horizontal_proximity( size_t i, size_t j )
{
    if( horizontal_sofa[ i ].x1 < horizontal_sofa[ j ].x2 )
        horizontal_sofa[ i ].right++, horizontal_sofa[ j ].left++;

    if( horizontal_sofa[ i ].x2 > horizontal_sofa[ j ].x1 )
        horizontal_sofa[ i ].left++, horizontal_sofa[ j ].right++;

    if( horizontal_sofa[ i ].y < horizontal_sofa[ j ].y )
        horizontal_sofa[ i ].bottom++, horizontal_sofa[ j ].top++;

    if( horizontal_sofa[ i ].y > horizontal_sofa[ j ].y )
        horizontal_sofa[ i ].top++, horizontal_sofa[ j ].bottom++;
}

void horizontal_vertical_proximity( size_t i, size_t j )
{
    if( horizontal_sofa[ i ].x1 < vertical_sofa[ j ].x )
        horizontal_sofa[ i ].right++, vertical_sofa[ j ].left++;

    if( horizontal_sofa[ i ].x2 > vertical_sofa[ j ].x )
        horizontal_sofa[ i ].left++, vertical_sofa[ j ].right++;

    if( horizontal_sofa[ i ].y < vertical_sofa[ j ].y2 )
        horizontal_sofa[ i ].bottom++, vertical_sofa[ j ].top++;

    if( horizontal_sofa[ i ].y > vertical_sofa[ j ].y1 )
        horizontal_sofa[ i ].top++, vertical_sofa[ j ].bottom++;
}

void new_horizontaol_sofa( size_t i, size_t x1, size_t x2, size_t y1, size_t y2 )
{
    assert( y1 == y2 );

    horizontal_sofa[ horizontal_sofas ].new_sofa( i, y1, min( x1, x2 ), max( x1, x2 ) );

    for( size_t j = 0; j < horizontal_sofas; j++ )
        horizontal_horizontal_proximity( horizontal_sofas, j );

    for( size_t j = 0; j < vertical_sofas; j++ )
        horizontal_vertical_proximity( horizontal_sofas, j );

    horizontal_sofas++;
}

void new_vertical_sofa( size_t i, size_t x, size_t y1, size_t y2 )
{
    vertical_sofa[ vertical_sofas ].new_sofa( i, x, min( y1, y2 ), max( y1, y2 ) );

    for( size_t j = 0; j < vertical_sofas; j++ )
        vertical_horizontal_proximity( vertical_sofas, j );

    for( size_t j = 0; j < vertical_sofas; j++ )
        vertical_vertical_proximity( vertical_sofas, j );

    vertical_sofas++;
}

void read_sofas()
{
    for( size_t i = 1; i <= d; i++ )
    {
        size_t x1, y1, x2, y2; scanf( "%u%u%u%u", &x1, &y1, &x2, &y2 ); valid( x1 ), valid( y1 ), valid( x2 ), valid( y2 );

        if ( x1 == x2 )
            new_vertical_sofa( i, x1, y1, y2 );
        else
            new_horizontaol_sofa( i, x1, x2, y1, y2 );
    }
}

int solution( size_t id )
{
    printf( "%u", id ); return 0;
}

int main()
{
    scanf( "%u%u%u", &d, &n, &m ); valid( d ), valid( n ), valid( m );

    read_sofas(); proximity_t proximity; proximity.read();

    for( size_t j = 0; j < horizontal_sofas; j++ )
        if ( horizontal_sofa[ j ].matched( proximity ) )
            return solution( horizontal_sofa[ j ].id );

    for( size_t j = 0; j < vertical_sofas; j++ )
        if ( vertical_sofa[ j ].matched( proximity ) )
            return solution( vertical_sofa[ j ].id );

    printf( "-1" );
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pi 3.14159265  //35897932384626433
#define INF 1e18
#define MOD 1000000007
#define all(s) s.begin(),s.end()
#define mp make_pair
#define vc vector<ll>
#define vp vector<pair<ll,ll> >
#define sec second
#define sz(x) (int)((x).size())
#define timesaver ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
const int N =  1e5 + 5;
ll gcd(ll a, ll b){ if(a==0) return b; else return gcd(b%a,a);}
ll power(ll base,ll exp,ll mod=MOD) {ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

ll ctl[N];
ll ctr[N];
ll ctt[N];
ll ctb[N];
ll ax[N];
ll bx[N];
ll ay[N];
ll by[N];
int main()
{
	timesaver;
	ll d, n, m, x, y , x1, y1, l, r, t, b;
	cin >> d >> n >> m;
	for(int i = 1; i <= d; i++){
		cin >> x >> y >> x1 >> y1;
		ax[i] = x, ay[i] = y, bx[i] = x1, by[i] = y1;
		ctl[min(x, x1)]++;
		ctr[max(x, x1)]++;
		ctt[min(y, y1)]++;
		ctb[max(y, y1)]++;
	}
	//cout << "yo";
	for (int i = 1; i <= 100000; i += 1)
	{
		ctl[i] += ctl[i - 1];
	}
	for (int i = 1; i <= 100000; i += 1)
	{
		ctt[i] += ctt[i - 1];
	}
	for (int i = 100000; i >= 1; i -= 1)
	{
		ctr[i] += ctr[i + 1];
	}
	for (int i = 100000; i >= 1; i -= 1)
	{
		ctb[i] += ctb[i + 1];
	}
	cin >> x >> y >> x1 >> y1;
	for (int i = 1; i <= d; i += 1)
	{

		l = ctl[max(ax[i], bx[i]) - 1];
		r = ctr[min(ax[i], bx[i]) + 1];
		t = ctt[max(ay[i], by[i]) - 1];
		b = ctb[min(ay[i], by[i]) + 1];
		if(ax[i] != bx[i])
			l--, r--;
		if(ay[i] != by[i])
			t--, b--;
		if(l == x && r == y && t == x1 && b == y1)
			return cout << i, 0;
	}
	cout << -1;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pi 3.14159265  //35897932384626433
#define INF 1e18
#define MOD 1000000007
#define all(s) s.begin(),s.end()
#define mp make_pair
#define vc vector<ll>
#define vp vector<pair<ll,ll> >
#define sec second
#define sz(x) (int)((x).size())
#define timesaver ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
const int N =  1e5 + 5;
ll gcd(ll a, ll b){ if(a==0) return b; else return gcd(b%a,a);}
ll power(ll base,ll exp,ll mod=MOD) {ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

ll ctl[N];
ll ctr[N];
ll ctt[N];
ll ctb[N];
ll ax[N];
ll bx[N];
ll ay[N];
ll by[N];
int main()
{
	timesaver;
	ll d, n, m, x, y , x1, y1, l, r, t, b;
	cin >> d >> n >> m;
	for(int i = 1; i <= d; i++){
		cin >> x >> y >> x1 >> y1;
		ax[i] = x, ay[i] = y, bx[i] = x1, by[i] = y1;
		ctl[min(x, x1)]++;
		ctr[max(x, x1)]++;
		ctt[min(y, y1)]++;
		ctb[max(y, y1)]++;
	}
	//cout << "yo";
	for (int i = 1; i <= m; i += 1)
	{
		ctl[i] += ctl[i - 1];
	}
	for (int i = 1; i <= n; i += 1)
	{
		ctt[i] += ctt[i - 1];
	}
	for (int i = m; i >= 1; i -= 1)
	{
		ctr[i] += ctr[i + 1];
	}
	for (int i = n; i >= 1; i -= 1)
	{
		ctb[i] += ctb[i + 1];
	}
	cin >> x >> y >> x1 >> y1;
	for (int i = 1; i <= d; i += 1)
	{

		l = ctl[max(ax[i], bx[i]) - 1];
		r = ctr[min(ax[i], bx[i]) + 1];
		t = ctt[max(ay[i], by[i]) - 1];
		b = ctb[min(ay[i], by[i]) + 1];
		if(ax[i] != bx[i])
			l--, r--;
		if(ay[i] != by[i])
			t--, b--;
		if(l == x && r == y && t == x1 && b == y1)
			return cout << i, 0;
	}
	cout << -1;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].minx()]++;
        //xx2[s[i].maxx()]++;
        xy1[s[i].miny()]++;
        //xy2[s[i].maxy()]++;
    }
    sofa t;t.Read();
    for(int i=1;i<=n;i++){
        xx1[i]+=xx1[i-1];
        //xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=1;i<=m;i++){
        xy1[i]+=xy1[i-1];
        //xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].minx()]==t.x1+1&&d-xx1[s[i].minx()]==t.y1+1
           &&xy1[s[i].miny()]==t.x2+1&&d-xy1[s[i].miny()]==t.y2+1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];
int yx1[100005],yx2[100005];
int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].maxx()]++;
        xx2[s[i].minx()]++;
        xy1[s[i].maxy()]++;
        xy2[s[i].miny()]++;
        if(s[i].maxx()==s[i].minx()){
            yx1[s[i].maxx()]++;
        }
        if(s[i].maxy()==s[i].miny()){
            yx2[s[i].miny()]++;
        }
    }
    sofa t;t.Read();
    for(int i=1;i<=n;i++){
        xx1[i]+=xx1[i-1];
        xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=1;i<=m;i++){
        xy1[i]+=xy1[i-1];
        xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].maxx()]-yx1[s[i].maxx()]==t.x1+(s[i].maxx()==s[i].minx()? 0:1)
           &&xx2[s[i].minx()]-yx1[s[i].minx()]==t.y1+(s[i].maxx()==s[i].minx()? 0:1)
           &&xy1[s[i].maxy()]-yx2[s[i].maxy()]==t.x2+(s[i].maxy()==s[i].miny()? 0:1)
           &&xy2[s[i].miny()]-yx2[s[i].miny()]==t.y2+(s[i].maxy()==s[i].miny()? 0:1)){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].minx()]++;
        xx2[s[i].maxx()]++;
        xy1[s[i].miny()]++;
        xy2[s[i].maxy()]++;
    }
    sofa t;t.Read();
    for(int i=1;i<=n;i++){
        xx1[i]+=xx1[i-1];
        xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=1;i<=m;i++){
        xy1[i]+=xy1[i-1];
        xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].minx()]==t.x1+1&&xx2[s[i].maxx()]==t.y2+1
           &&xy1[s[i].miny()]==t.x2+1&&xy2[s[i].maxy()]==t.y1+1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].minx()]++;
        xx2[s[i].maxx()]++;
        xy1[s[i].miny()]++;
        xy2[s[i].maxy()]++;
    }
    sofa t;t.Read();
    for(int i=1;i<=n;i++){
        xx1[i]+=xx1[i-1];
        xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=1;i<=m;i++){
        xy1[i]+=xy1[i-1];
        xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].minx()]==t.x1+1&&xx2[s[i].maxx()]==t.y1+1
           &&xy1[s[i].miny()]==t.x2+1&&xy2[s[i].maxy()]==t.y2+1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].minx()]++;
        xx2[s[i].maxx()]++;
        xy1[s[i].miny()]++;
        xy2[s[i].maxy()]++;
    }
    sofa t;t.Read();
    for(int i=1;i<=n;i++){
        xx1[i]+=xx1[i-1];
        xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=1;i<=m;i++){
        xy1[i]+=xy1[i-1];
        xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].minx()]==t.x1+1&&xx2[s[i].maxx()]==t.y1+1
           &&xy1[s[i].miny()]==t.y2+1&&xy2[s[i].maxy()]==t.x2+1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define CVector CPoint
#define INF 0x3f3f3f3f
#define MAXN 1e5
const LL mod=1e9+7;
const double PI=acos(-1.0);
const double EPS=1e-10;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

struct sofa{
    int x1,x2,y1,y2;
    int minx(){return min(x1,x2);}
    int maxx(){return max(x1,x2);}
    int miny(){return min(y1,y2);}
    int maxy(){return max(y1,y2);}
    void Read(){
        cin>>x1>>y1>>x2>>y2;
    }
}s[100005];

int xx1[100005],xx2[100005],xy1[100005],xy2[100005];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int d,n,m;cin>>d>>n>>m;
    for(int i=0;i<d;i++){
        s[i].Read();
        xx1[s[i].maxx()]++;
        xx2[s[i].minx()]++;
        xy1[s[i].maxy()]++;
        xy2[s[i].miny()]++;
    }
    sofa t;t.Read();
    for(int i=2;i<=n;i++){
        xx1[i]+=xx1[i-1];
        xx2[n-i+1]+=xx2[n-i+2];
    }
    for(int i=2;i<=m;i++){
        xy1[i]+=xy1[i-1];
        xy2[m-i+1]+=xy2[m-i+2];
    }
    for(int i=0;i<d;i++){
        if(xx1[s[i].maxx()]==t.x1+1&&xx2[s[i].minx()]==t.y1+1
           &&xy1[s[i].maxy()]==t.x2+1&&xy2[s[i].miny()]==t.y2+1){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <queue>
using namespace std;

struct Sofa
{
       int fx,fy,tx,ty;
}      a[1000050];

int sx1[1000050],sx2[1000050],sy1[1000050],sy2[1000050];

int  main()
{
int  d,n,m,i,cl,cr,ct,cb;

     scanf("%d%d%d",&d,&n,&m);
     for (i=1;i<=d;i++)
     {
         scanf("%d%d%d%d",&a[i].fx,&a[i].fy,&a[i].tx,&a[i].ty);
         if  (a[i].fx>a[i].tx) swap(a[i].fx,a[i].tx);
         if  (a[i].fy>a[i].ty) swap(a[i].fy,a[i].ty);
         if  (a[i].fx==a[i].tx)
         {
             sx1[a[i].fx]++;
             sy2[a[i].fy]++;
         }   else
         {
             sx2[a[i].fx]++;
             sy1[a[i].fy]++;
         }
     }
     for (i=1;i<=n;i++)
     {
         sx1[i]+=sx1[i-1];
         sx2[i]+=sx2[i-1];
     }
     for (i=1;i<=m;i++)
     {
         sy1[i]+=sy1[i-1];
         sy2[i]+=sy2[i-1];
     }
     scanf("%d%d%d%d",&cl,&cr,&ct,&cb);
     for (i=1;i<=d;i++)
     if  (a[i].fx==a[i].tx)
     {
         if  (sx1[a[i].fx-1]+sx2[a[i].fx-1]==cl&&
             sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx]==cr&&
             sy1[a[i].fy]+sy2[a[i].fy]-1==ct&&
             sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]-1==cb)
         {
             printf("%d\n",i);
             return 0;
         }
     }   else
     if  (sx1[a[i].fx]+sx2[a[i].fx]-1==cl&&
         sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx-1]-1==cr&&
         sy1[a[i].fy-1]+sy2[a[i].fy-1]==ct&&
         sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]==cb)
     {
         printf("%d\n",i);
         return 0;
     }
     printf("-1\n");

     return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <queue>
using namespace std;

struct Sofa
{
       int fx,fy,tx,ty;
}      a[1000050];

int sx1[1000050],sx2[1000050],sy1[1000050],sy2[1000050];

int  main()
{
int  d,n,m,i,cl,cr,ct,cb;

     scanf("%d%d%d",&d,&n,&m);
     for (i=1;i<=d;i++)
     {
         scanf("%d%d%d%d",&a[i].fx,&a[i].fy,&a[i].tx,&a[i].ty);
         if  (a[i].fx>a[i].tx) swap(a[i].fx,a[i].tx);
         if  (a[i].fy>a[i].ty) swap(a[i].fy,a[i].ty);
         if  (a[i].fx==a[i].tx)
         {
             sx1[a[i].fx]++;
             sy2[a[i].fy]++;
         }   else
         {
             sx2[a[i].fx]++;
             sy1[a[i].fy]++;
         }
     }
     for (i=1;i<=n;i++)
     {
         sx1[i]+=sx1[i-1];
         sx2[i]+=sx2[i-1];
     }
     for (i=1;i<=m;i++)
     {
         sy1[i]+=sy1[i-1];
         sy2[i]+=sy2[i-1];
     }
     scanf("%d%d%d%d",&cl,&cr,&ct,&cb);
     for (i=1;i<=d;i++)
     if  (a[i].fx==a[i].tx)
     {
         if  (sx1[a[i].fx-1]+sx2[a[i].fx-1]==ct&&
             sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx]==cb&&
             sy1[a[i].fy]+sy2[a[i].fy]-1==cl&&
             sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]-1==cr)
         {
             printf("%d\n",i);
             return 0;
         }
     }   else
     if  (sx1[a[i].fx]+sx2[a[i].fx]-1==ct&&
         sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx-1]-1==cb&&
         sy1[a[i].fy-1]+sy2[a[i].fy-1]==cl&&
         sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]==cr)
     {
         printf("%d\n",i);
         return 0;
     }
     printf("-1\n");

     return 0;
}


#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <bitset>
#include <queue>
using namespace std;

struct Sofa
{
       int fx,fy,tx,ty;
}      a[1000050];

int sx1[1000050],sx2[1000050],sy1[1000050],sy2[1000050];

int  main()
{
int  d,n,m,i,cl,cr,ct,cb;

     scanf("%d%d%d",&d,&n,&m);
     for (i=1;i<=d;i++)
     {
         scanf("%d%d%d%d",&a[i].fx,&a[i].fy,&a[i].tx,&a[i].ty);
         if  (a[i].fx>a[i].tx) swap(a[i].fx,a[i].tx);
         if  (a[i].fy>a[i].ty) swap(a[i].fy,a[i].ty);
         if  (a[i].fx==a[i].tx)
         {
             sx1[a[i].fx]++;
             sy2[a[i].fy]++;
         }   else
         {
             sx2[a[i].fx]++;
             sy1[a[i].fy]++;
         }
     }
     for (i=1;i<=n;i++)
     {
         sx1[i]+=sx1[i-1];
         sx2[i]+=sx2[i-1];
     }
     for (i=1;i<=m;i++)
     {
         sy1[i]+=sy1[i-1];
         sy2[i]+=sy2[i-1];
     }
     scanf("%d%d%d%d",&cl,&cr,&ct,&cb);
     for (i=1;i<=d;i++)
     if  (a[i].fx==a[i].tx)
     {
         if  (sx1[a[i].fx-1]+sx2[a[i].fx-1]==cl&&
             sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx-1]==cr&&
             sy1[a[i].fy]+sy2[a[i].fy]-1==ct&&
             sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]-1==cb)
         {
             printf("%d\n",i);
             return 0;
         }
     }   else
     if  (sx1[a[i].fx]+sx2[a[i].fx]-1==cl&&
         sx1[n]-sx1[a[i].fx]+sx2[n]-sx2[a[i].fx-1]-1==cr&&
         sy1[a[i].fy-1]+sy2[a[i].fy-1]==ct&&
         sy1[m]-sy1[a[i].fy]+sy2[m]-sy2[a[i].fy-1]==cb)
     {
         printf("%d\n",i);
         return 0;
     }
     printf("-1\n");

     return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iterator>
#include <cstring>
using namespace std;

int n, m, d;
int x1[100005], y1[100005], x2[100005], y2[100005];
int cl, cr, ct, cb;

int mxl[100005], mxr[100005], myl[100005], myr[100005];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> d >> n >> m;
	for (int i=1; i<=d; i++) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		if (x1[i] > x2[i]) {
			swap(x1[i], x2[i]);
		}
		if (y1[i] > y2[i]) {
			swap(y1[i], y2[i]);
		}
	}
	cin >> cl >> cr >> ct >> cb;

	for (int i=1; i<=d; i++) {
		mxl[x1[i]]++;
		mxr[x2[i]]++;
		myl[y1[i]]++;
		myr[y2[i]]++;
	}

	for (int i=1; i<=100001; i++) {
		mxl[i] += mxl[i-1];
		myl[i] += myl[i-1];
	}

	for (int i=100000; i>=0; i--) {
		mxr[i] += mxr[i+1];
		myr[i] += myr[i+1];
	}

	for (int i=1; i<=d; i++) {
		int zxl = mxl[x2[i]-1];
		int zxr = mxr[x1[i]+1];
		int zyl = myl[y2[i]-1];
		int zyr = myr[y1[i]+1];

		if (x2[i] != x1[i]) {
			zxl--;
			zxr--;
		}

		if (y2[i] != y1[i]) {
			zyl--;
			zyr--;
		}

		if (zxl == cl && zxr == cr
			&& zyl == ct && zyr == cb)
		{
			cout << i;
			return 0;
		} else {
			// cerr << zxl << ' ' << zxr << ' ' << zyl << ' ' << zyr << '\n';

		}
	}
	cout << -1;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iterator>
#include <cstring>
using namespace std;

int n, m, d;
int x1[100005], y1[100005], x2[100005], y2[100005];
int cl, cr, ct, cb;

int mxl[100005], mxr[100005], myl[100005], myr[100005];

void prefix_sum(int* a, int* b) {
	while (a != b) {
		a[1] += a[0];
		a++;
	}
}

void prefix_sum_rev(int* a, int* b) {
	b--;
	b--;
	while (1) {
		b[0] += b[1];
		b--;
		if (a == b) {
			break;
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> d >> n >> m;
	for (int i=1; i<=d; i++) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		if (x1[i] > x2[i]) {
			swap(x1[i], x2[i]);
		}
		if (y1[i] > y2[i]) {
			swap(y1[i], y2[i]);
		}
	}
	cin >> cl >> cr >> ct >> cb;

	for (int i=1; i<=d; i++) {
		mxl[x1[i]]++;
		mxr[x2[i]]++;
		myl[y1[i]]++;
		myr[y2[i]]++;
	}

	for (int i=1; i<=100001; i++) {
		mxl[i] += mxl[i-1];
		myl[i] += myl[i-1];
	}

	for (int i=100000; i>=0; i--) {
		mxr[i] += mxr[i+1];
		myr[i] += myr[i+1];
	}

	for (int i=1; i<=d; i++) {
		int zxl = mxl[x2[i]-1];
		int zxr = mxr[x1[i]+1];
		int zyl = myl[y2[i]-1];
		int zyr = myr[y1[i]+1];

		if (x2[i] != x1[i]) {
			zxl--;
			zxr--;
		}

		if (y2[i] != y1[i]) {
			zyl--;
			zyr--;
		}

		if (zxl == cl && zxr == cr
			&& zyl == ct && zyr == cb)
		{
			cout << i;
			return 0;
		} else {
			cerr << zxl << ' ' << zxr << ' ' << zyl << ' ' << zyr << '\n';

		}
	}
	cout << -1;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 10;

int sl[N], sr[N], su[N], sd[N];
int l[N], r[N], u[N], d[N];
int recl[N], recr[N], recu[N], recd[N];
int st[N];

int main(){
	int num, n, m, cntl, cntr, cntu, cntd, x, y, xx, yy, pos;
	scanf("%d",&num);
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= num; i++){
		scanf("%d %d %d %d",&x,&y,&xx,&yy);
		sl[i] = l[i] = min(x, xx);
		sr[i] = r[i] = max(x, xx);
		su[i] = u[i] = min(y, yy);
		sd[i] = d[i] = max(y, yy);
		if (x == xx) st[i] = 1;
		else st[i] = 2;
	}
	scanf("%d %d %d %d",&cntl,&cntr,&cntu,&cntd);
	sort(sl + 1, sl + num + 1);
	sort(sr + 1, sr + num + 1);
	sort(su + 1, su + num + 1);
	sort(sd + 1, sd + num + 1);
	for (int i = 1; i <= num; i++){
		pos = lower_bound(sl + 1, sl + num + 1, r[i]) - sl;
		recl[i] = pos - 1;
		if (st[i] == 2) recl[i]--;
		pos = upper_bound(sr + 1, sr + num + 1, l[i]) - sr;
		recr[i] = num - pos + 1;
		if (st[i] == 2) recr[i]--;
		pos = lower_bound(su + 1, su + num + 1, d[i]) - su;
		recu[i] = pos - 1;
		if (st[i] == 1) recu[i]--;
		pos = upper_bound(sd + 1, sd + num + 1, u[i]) - sd;
		recd[i] = num - pos + 1;
		if (st[i] == 1) recd[i]--;
	}
	for (int i = 1; i <= num; i++){
		if (recl[i] == cntl && recr[i] == cntr && recu[i] == cntu && recd[i] == cntd){
			printf("%d\n", i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=111111;
int L[maxn],R[maxn],U[maxn],D[maxn];
struct hhh{
	int u,d,l,r;
}h[maxn];
int main()
{
	int N,n,m;
	int u,l,d,r,UU,DD,LL,RR;
	bool flg=false;
	scanf("%d%d%d",&N,&n,&m);
	for(int i=1;i<=N;++i)
	{
		scanf("%d%d%d%d",&u,&l,&d,&r);
		if(u>d) swap(u,d);
		if(l>r) swap(l,r);
		h[i]=(hhh){u,d,l,r},L[i]=l,R[i]=-r,U[i]=u,D[i]=-d;
	}
	sort(L+1,L+1+N);
	sort(R+1,R+1+N);
	sort(U+1,U+1+N);
	sort(D+1,D+1+N);
	scanf("%d%d%d%d",&u,&d,&l,&r);
	for(int i=1;i<=N;++i)
	{
		LL=lower_bound(L+1,L+1+N,h[i].r)-L-1-(h[i].l<h[i].r);
		RR=lower_bound(R+1,R+1+N,-h[i].l)-R-1-(h[i].l<h[i].r);
		UU=lower_bound(U+1,U+1+N,h[i].d)-U-1-(h[i].u<h[i].d);
		DD=lower_bound(D+1,D+1+N,-h[i].u)-D-1-(h[i].u<h[i].d);
//		printf("%d : %d %d %d %d \n",i,LL,RR,UU,DD);
		if(LL==l&&RR==r&&UU==u&&DD==d) printf("%d",i),flg=true;
	}
	if(!flg) puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define y1 asdfasdf

const int N=1e5+5;
struct node
{
	int x1,x2,y1,y2;
}a[N];
LL n,m,d,cntl,cntr,cntt,cntb;
int x1[N],x2[N],y1[N],y2[N];

int main()
{
	while(cin>>d)
	{
		memset(x1,0,sizeof(x1));
		memset(y1,0,sizeof(y1));
		memset(x2,0,sizeof(x2));
		memset(y2,0,sizeof(y2));
		cin>>n>>m;
		for(int i=0;i<d;i++)
		{
			cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
			if(a[i].x1>a[i].x2) swap(a[i].x1,a[i].x2);
			if(a[i].y1>a[i].y2) swap(a[i].y1,a[i].y2);
			x1[a[i].x1]++;
			x2[a[i].x2]++;
			y1[a[i].y1]++;
			y2[a[i].y2]++;
		}
		for(int i=1;i<=n;i++)
			x1[i]+=x1[i-1],x2[i]+=x2[i-1];
		for(int i=1;i<=m;i++)
			y1[i]+=y1[i-1],y2[i]+=y2[i-1];
		cin>>cntl>>cntr>>cntt>>cntb;
		int i;
		for(i=0;i<n;i++)
		{
			node& sofa=a[i];
			int t1,t2,t3,t4;
			t1=x1[sofa.x2-1];
			if(sofa.x1<sofa.x2) t1--;
			t2=d-x2[sofa.x1];
			if(sofa.x1<sofa.x2) t2--;
			t3=y1[sofa.y2-1];
			if(sofa.y1<sofa.y2) t3--;
			t4=d-y2[sofa.y1];
			if(sofa.y1<sofa.y2) t4--;
//			printf("====%d %d %d %d====\n",t1,t2,t3,t4);
			if(t1==cntl&&t2==cntr&&t3==cntt&&t4==cntb)
			{
				cout<<i+1<<endl;
				break;
			}
		}
		if(i==n)
			puts("-1");
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define y1 asdfasdf

const int N=1e5+5;
struct node
{
	int x1,x2,y1,y2;
}a[N];
LL n,m,d,cntl,cntr,cntt,cntb;
int x1[N],x2[N],y1[N],y2[N];

int main()
{
	while(cin>>d)
	{
		memset(x1,0,sizeof(x1));
		memset(y1,0,sizeof(y1));
		memset(x2,0,sizeof(x2));
		memset(y2,0,sizeof(y2));
		cin>>n>>m;
		for(int i=0;i<d;i++)
		{
			cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
			if(a[i].x1>a[i].x2) swap(a[i].x1,a[i].x2);
			if(a[i].y1>a[i].y2) swap(a[i].y1,a[i].y2);
			x1[a[i].x1]++;
			x2[a[i].x2]++;
			y1[a[i].y1]++;
			y2[a[i].y2]++;
		}
		for(int i=1;i<=n;i++)
			x1[i]+=x1[i-1],x2[i]+=x2[i-1];
		for(int i=1;i<=m;i++)
			y1[i]+=y1[i-1],y2[i]+=y2[i-1];
		cin>>cntl>>cntr>>cntt>>cntb;
		int i;
		for(i=0;i<d;i++)
		{
			node& sofa=a[i];
			int t1,t2,t3,t4;
			t1=x1[sofa.x2-1];
			if(sofa.x1<sofa.x2) t1--;
			t2=d-x2[sofa.x1];
			if(sofa.x1<sofa.x2) t2--;
			t3=y1[sofa.y2-1];
			if(sofa.y1<sofa.y2) t3--;
			t4=d-y2[sofa.y1];
			if(sofa.y1<sofa.y2) t4--;
//			printf("====%d %d %d %d====\n",t1,t2,t3,t4);
			if(t1==cntl&&t2==cntr&&t3==cntt&&t4==cntb)
			{
				cout<<i+1<<endl;
				break;
			}
		}
		if(i==d)
			puts("-1");
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)

#define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin();  v != (c).rend(); ++v)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

typedef long long int slong;
typedef pair<int, int> pii;
typedef pair<slong, slong> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

#ifdef VSP4
    #include "debug.h"
#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

const int MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;

const int MAXN = 2e5;
const int SQRTN = 400;
const int LOGN = 16;
const int INT_INFINITY = 1001001001;
const slong LONG_INFINITY = 2001001001001001001ll;
const double EPS = 1e-7;

int d, n, m;
int c[4][MAXN+5];

vector<pii> query[4][MAXN+5];
int add[4][MAXN+5];
int cnt[4];

int countData[4][MAXN+5];
int req[4];

int main()
{
	#ifdef VSP4
		//freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);

	int i, j, u, v, q, x1, y1, x2, y2;

	cint3(d, n, m);

	for (i = 1; i <= d; i++)
	{
		cint4(x1, y1, x2, y2);

		auto p = minmax(x1, x2);
		add[0][p.fi]++;
		add[2][p.se]++;

		query[0][p.se].eb(i, p.fi < p.se);
		query[2][p.fi].eb(i, p.fi < p.se);

		auto q = minmax(y1, y2);
		add[1][q.fi]++;
		add[3][q.se]++;

		query[1][q.se].eb(i, q.fi < q.se);
		query[3][q.fi].eb(i, q.fi < q.se);

	}

	for (i = 0; i < 2; i++)
	{
		for (j = 1; j <= MAXN; j++)
		{
			for (auto s: query[i][j])
			{
				countData[i][s.fi] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	for (i = 2; i < 4; i++)
	{
		for (j = MAXN; j >= 1; j--)
		{
			for (auto s: query[i][j])
			{
				countData[i][s.fi] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	cint4(req[0], req[2], req[1], req[3]);

	debug(req[0], req[1], req[2], req[3]);

	for (i = 1; i <= n; i++)
	{
		bool valid = true;

		for (j = 0; j < 4; j++)
		{
			valid = valid && (req[j] == countData[j][i]);
		}

		if (valid)
		{
			cout << i;
			return 0;
		}
	}

	cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)

#define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin();  v != (c).rend(); ++v)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

typedef long long int slong;
typedef pair<int, int> pii;
typedef pair<slong, slong> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

#ifdef VSP4
    #include "debug.h"
#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

const int MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;

const int MAXN = 2e5;
const int SQRTN = 400;
const int LOGN = 16;
const int INT_INFINITY = 1001001001;
const slong LONG_INFINITY = 2001001001001001001ll;
const double EPS = 1e-7;

int d, n, m;
int c[4][MAXN+5];

vector<pii> query[4][MAXN+5];
int add[4][MAXN+5];
int cnt[4];

int countData[4][MAXN+5];
int req[4];

int main()
{
	#ifdef VSP4
		//freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);

	int i, j, u, v, q, x1, y1, x2, y2;

	cint3(d, n, m);

	for (i = 1; i <= d; i++)
	{
		cint4(x1, y1, x2, y2);

		auto p = minmax(x1, x2);
		add[0][p.fi]++;
		add[2][p.se]++;

		query[0][p.se].eb(i, p.fi < p.se);
		query[2][p.fi].eb(i, p.fi < p.se);

		auto q = minmax(y1, y2);
		add[1][q.fi]++;
		add[3][q.se]++;

		query[1][q.se].eb(i, q.fi < q.se);
		query[3][q.fi].eb(i, q.fi < q.se);

	}

	for (i = 0; i < 2; i++)
	{
		for (j = 1; j <= MAXN; j++)
		{
			for (auto s: query[i][j])
			{
				countData[s.fi][i] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	for (i = 2; i < 4; i++)
	{
		for (j = MAXN; j >= 1; j--)
		{
			for (auto s: query[i][j])
			{
				countData[s.fi][i] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	cint4(req[0], req[2], req[1], req[3]);

	debug(req[0], req[1], req[2], req[3]);

	for (i = 1; i <= n; i++)
	{
		bool valid = true;

		for (j = 0; j < 4; j++)
		{
			valid = valid && (req[j] == countData[i][j]);
		}

		debug(i, countData[i][0], countData[i][1], countData[i][2], countData[i][3]);

		if (valid)
		{
			cout << i;
			return 0;
		}
	}

	cout << -1;

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)

#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)

#define foreach(v, c) for(__typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define revforeach(v, c) for(__typeof( (c).rbegin()) v = (c).rbegin();  v != (c).rend(); ++v)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

typedef long long int slong;
typedef pair<int, int> pii;
typedef pair<slong, slong> pll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

#ifdef VSP4
    #include "debug.h"
#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

const int MOD = 1000000007;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;

const int MAXN = 2e5;
const int SQRTN = 400;
const int LOGN = 16;
const int INT_INFINITY = 1001001001;
const slong LONG_INFINITY = 2001001001001001001ll;
const double EPS = 1e-7;

int d, n, m;
int c[4][MAXN+5];

vector<pii> query[4][MAXN+5];
int add[4][MAXN+5];
int cnt[4];

int countData[4][MAXN+5];
int req[4];

int main()
{
	#ifdef VSP4
		//freopen("input.txt", "r", stdin);
		//freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);

	int i, j, u, v, q, x1, y1, x2, y2;

	cint3(d, n, m);

	for (i = 1; i <= d; i++)
	{
		cint4(x1, y1, x2, y2);

		auto p = minmax(x1, x2);
		add[0][p.fi]++;
		add[2][p.se]++;

		query[0][p.se].eb(i, p.fi < p.se);
		query[2][p.fi].eb(i, p.fi < p.se);

		auto q = minmax(y1, y2);
		add[1][q.fi]++;
		add[3][q.se]++;

		query[1][q.se].eb(i, q.fi < q.se);
		query[3][q.fi].eb(i, q.fi < q.se);

	}

	for (i = 0; i < 2; i++)
	{
		for (j = 1; j <= MAXN; j++)
		{
			for (auto s: query[i][j])
			{
				countData[i][s.fi] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	for (i = 2; i < 4; i++)
	{
		for (j = MAXN; j >= 1; j--)
		{
			for (auto s: query[i][j])
			{
				countData[i][s.fi] = cnt[i] - s.se;
			}

			cnt[i] += add[i][j];
		}
	}

	cint4(req[0], req[2], req[1], req[3]);

	for (i = 1; i <= d; i++)
	{
		bool valid = true;

		for (j = 0; j < 4; j++)
		{
			valid = valid && (req[j] == countData[j][i]);
		}

		if (valid)
		{
			cout << i;
			return 0;
		}
	}

	cout << -1;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>

int main(void)
{
  int d;
  int n, m;

  std::vector<std::pair<std::pair<int, int>, std::pair<int, int>>> sofas;
  std::vector<int> lefts;
  std::vector<int> rights;
  std::vector<int> tops;
  std::vector<int> bottoms;

  scanf("%d %d %d", &d, &n, &m);
  for(int i = 0; i < d; i ++)
  {
    int x1, y1, x2, y2;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    sofas.push_back(std::make_pair(std::make_pair(x1, y1), std::make_pair(x2, y2)));

    lefts.push_back(std::min(x1, x2));
    rights.push_back(std::max(x1, x2));
    tops.push_back(std::min(y1, y2));
    bottoms.push_back(std::max(y1, y2));
  }

  std::sort(lefts.begin(), lefts.end());
  std::sort(rights.begin(), rights.end());
  std::sort(tops.begin(), tops.end());
  std::sort(bottoms.begin(), bottoms.end());

  int gl, gr, gt, gb;
  scanf("%d %d %d %d", &gl, &gr, &gt, &gb);

  for(int i = 0; i < d; i ++)
  {
    const auto s = sofas[i];
    const int x1 = s.first.first, y1 = s.first.second, x2 = s.second.first, y2 = s.second.second;

    int l, r, t, b;

    l = (int)(std::upper_bound(lefts.begin(), lefts.end(), std::min(x1, x2)) - lefts.begin()) - 1;
    r = (int)(rights.end() - std::lower_bound(rights.begin(), rights.end(), std::max(x1, x2))) - 1;
    t = (int)(std::upper_bound(tops.begin(), tops.end(), std::min(y1, y2)) - tops.begin()) - 1;
    b = (int)(bottoms.end() - std::lower_bound(bottoms.begin(), bottoms.end(), std::max(y1, y2))) - 1;

    if(l == gl && r == gr && t == gt && b == gb)
    {
      printf("%d\n", i + 1);
      return 0;
    }
  }

  puts("-1");

  return 0;
}