// It`s                  (
// time                   )
// to                    (
// get            /\  .-"""-.  /\
// wrong         //\\/  ,,,  \//\\
// answer!       |/\| ,;;;;;, |/\|
//               //\\\;-"""-;///\\
//              //  \/   .   \/  \\
//             (| ,-_| \ | / |_-, |)
//               //`__\.-.-./__`\\
//              // /.-(() ())-.\ \\
//             (\ |)   '---'   (| /)
//              ` (| OMNOMNOM  |) `
//                \)           (/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <iomanip> // setprecision(10)

//#define OUT

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;

const long double PI = 3.1415926535897932384626433832;

int main() {
#ifdef OUT
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int* a = new int[n];
		ull ae = 0;
		ull ao = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i] % 2 == 0) {
				ae++;
			}
			else {
				ao++;
			}
		}
		int m;
		cin >> m;
		int* b = new int[m];
		ull be = 0;
		ull bo = 0;
		for (int i = 0; i < m; i++) {
			cin >> b[i];
			if (b[i] % 2 == 0) {
				be++;
			}
			else {
				bo++;
			}
		}
		ull e = ae * be;
		ull o = ao * bo;
		cout << e + o << endl;
		delete[] a;
		delete[] b;
	}
	return 0;
}


// It`s                  (
// time                   )
// to                    (
// get            /\  .-"""-.  /\
// wrong         //\\/  ,,,  \//\\
// answer!       |/\| ,;;;;;, |/\|
//               //\\\;-"""-;///\\
//              //  \/   .   \/  \\
//             (| ,-_| \ | / |_-, |)
//               //`__\.-.-./__`\\
//              // /.-(() ())-.\ \\
//             (\ |)   '---'   (| /)
//              ` (| OMNOMNOM  |) `
//                \)           (/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <iomanip> // setprecision(10)

//#define OUT

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;

const long double PI = 3.1415926535897932384626433832;

int main() {
#ifdef OUT
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		int* a = new int[n];
		int ae = 0;
		int ao = 0;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i] % 2 == 0) {
				ae++;
			}
			else {
				ao++;
			}
		}
		int m;
		cin >> m;
		int* b = new int[m];
		int be = 0;
		int bo = 0;
		for (int i = 0; i < m; i++) {
			cin >> b[i];
			if (b[i] % 2 == 0) {
				be++;
			}
			else {
				bo++;
			}
		}
		int e = ae * be;
		int o = ao * bo;
		cout << e + o << endl;
		delete[] a;
		delete[] b;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int T;cin>>T;
	long x[100],y;
	int ans1,ans2,an1,an2;
	int m,n;
	while(T--)
	{
		ans1=0,ans2=0;
		an1=0,an2=0;
		cin>>m;
		for(int i=1;i<=m;i++) cin>>x[i];

		for(int j=1;j<=m;j++)
			{
				if((1-x[j])%2==0) ans1++;
			}

		cin>>n;

		for(int i=1;i<=n;i++)
		{
			cin>>y;
			if(y%2==1) an1++;
		}
		cout<<"*"<<ans1*an1+(m-ans1)*(n-an1)<<endl;
	 }
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int T;cin>>T;
	long long x,y;
	long long ans1,ans2,an1,an2;
	int m,n;
	while(T--)
	{
		ans1=0,ans2=0,an1=0,an2=0;
		cin>>m;
		for(int i=1;i<=m;i++)
			{cin>>x;if((1-x)%2==0) ans1++;}

		cin>>n;
		for(int i=1;i<=n;i++)
			{cin>>y;if(y%2==1) an1++;}
		cout<<ans1*an1+(m-ans1)*(n-an1)<<endl;
	 }
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int T;cin>>T;
	long long x,y;
	long ans1,ans2,an1,an2;
	int m,n;
	while(T--)
	{
		ans1=0,ans2=0,an1=0,an2=0;
		cin>>m;
		for(int i=1;i<=m;i++)
			{cin>>x;if((1-x)%2==0) ans1++;}

		cin>>n;
		for(int i=1;i<=n;i++)
			{cin>>y;if(y%2==1) an1++;}
		cout<<ans1*an1+(m-ans1)*(n-an1)<<endl;
	 }
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int T;cin>>T;
	long x,y;
	int ans1,ans2,an1,an2;
	int m,n;
	while(T--)
	{
		ans1=0,ans2=0,an1=0,an2=0;
		cin>>m;
		for(int i=1;i<=m;i++)
			{cin>>x;if((1-x)%2==0) ans1++;}

		cin>>n;
		for(int i=1;i<=n;i++)
			{cin>>y;if(y%2==1) an1++;}
		cout<<ans1*an1+(m-ans1)*(n-an1)<<endl;
	 }
	return 0;
}


#include <string>
#include <vector>
#include <iostream>
#include <climits>
#include <stdio.h>

using namespace std;

const int inf = INT_MAX;

int main()
{
	long long t, x, y, n, m;
	cin >> t;
	for (long long j = 0; j < t; j++)
	{
		cin >> n;
		long long  kx1 = 0, kx2 = 0;
		for (long long i = 0; i < n; i++)
		{
			cin >> x;
			if (x % 2 == 0) kx2++;
			else kx1++;
		}

		cin >> m;
		long long ky1 = 0, ky2 = 0;
		for (long long i = 0; i < m; i++)
		{
			cin >> y;
			if (y % 2 == 0) ky2++;
			else ky1++;
		}

		cout << kx1*ky1+ky2*kx2 << "\n";
	}

}


#include <string>
#include <vector>
#include <iostream>
#include <climits>
#include <stdio.h>
using namespace std;

const int inf = INT_MAX;

int main()
{
	int t, x, y, n, m;
	scanf("%d",&t);
	for (y = 0; y < t; y++)
	{
		scanf("%d", &n);
		vector <int> p(n);
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &p[i]);;
		}

		scanf("%d", &m);
		vector <int> q(m);
		for (int i = 0; i < m; i++)
		{
			scanf("%d", &q[i]);
		}
		int k = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
			{
				if ((q[j] - p[i]) % 2 == 0) k++;
			}
		}
		printf("%d\n", k);
	}

}


#include <string>
#include <vector>
#include <iostream>
#include <climits>
#include <stdio.h>
using namespace std;

const int inf = INT_MAX;

int main()
{
	int t, x, y, n, m;
	scanf("%d",&t);
	for (int j = 0; j < t; j++)
	{
		scanf("%d", &n);
		int kx1 = 0, kx2 = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &x);
			if (x % 2 == 0) kx2++;
			else kx1++;
		}

		scanf("%d", &m);
		int ky1 = 0, ky2 = 0;
		for (int i = 0; i < m; i++)
		{
			scanf("%d", &y);
			if (x % 2 == 0) ky2++;
			else ky1++;
		}

		printf("%d\n", kx1*ky1+ky2*kx2);
	}

}


#include <string>
#include <vector>
#include <iostream>
#include <climits>
#include <stdio.h>
using namespace std;

const int inf = INT_MAX;

int main()
{
	int t, x, y, n, m;
	cin >> t;
	for (int j = 0; j < t; j++)
	{
		cin >> n;
		int kx1 = 0, kx2 = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> x;
			if (x % 2 == 0) kx2++;
			else kx1++;
		}

		cin >> m;
		int ky1 = 0, ky2 = 0;
		for (int i = 0; i < m; i++)
		{
			cin >> y;
			if (y % 2 == 0) ky2++;
			else ky1++;
		}

		printf("%d\n", kx1*ky1+ky2*kx2);
	}

}


#include <string>
#include <vector>
#include <iostream>
#include <climits>
using namespace std;

const int inf = INT_MAX;

int main()
{
	int t, x, y, n, m;
	cin >> t;
	for (y = 0; y < t; y++)
	{
		cin >> n;
		vector <int> p(n);
		for (int i = 0; i < n; i++)
		{
			cin >> p[i];
		}

		cin >> m;
		vector <int> q(m);
		for (int i = 0; i < m; i++)
		{
			cin >> q[i];
		}
		int k = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++)
			{
				if ((q[j] - p[i]) % 2 == 0) k++;
			}
		}
		cout << k <<endl;
	}

}


#include <iostream>
#include<vector>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int o = 0;o < t;o++) {
		int n, m;

		cin >> n;
		long long kp0 = 0, kp1 = 0, kq0 = 0, kq1 = 0;
		for (int i = 0;i < n;i++) {
			int p;
			cin >> p;

			p = p % 2;
			if (p == 1) {
				kp1++;
			}
			else {
				kp0++;
			}
		}
		cin >> m;
		for (int i = 0;i < m;i++) {
			int q;
			cin >> q;

			q = q % 2;
			if (q == 1) {
				kq1++;
			}
			else {
				kq0++;
			}
		}
		long long ans = kp1 * kq1 + kq0 * kp0;
		cout << ans << endl;
	}
}


#include <iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int o= 0;o< t;o++) {
		int n, m;

		cin >> n;
		int kp0 = 0, kp1 = 0, kq0 = 0, kq1 = 0;
		for (int i = 0;i < n;i++) {
			int p;
			cin >> p;
			p = p % 2;
			if (p == 1) {
				kp1++;
			}
			else {
				kp0++;
			}
		}
		cin >> m;
		for (int i = 0;i < m;i++) {
			int q;
			cin >> q;
			q = q % 2;
			if (q== 1) {
				kq1++;
			}
			else {
				kq0++;
			}
		}
		int ans = kp1 * kq1 + kq0 * kp0;
		cout << ans<<endl;
	}
}


#include <iostream>
#include<vector>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;
int main()
{
	int t;
	cin >> t;
	for (int o = 0;o < t;o++) {
		int n, m;

		cin >> n;
		int kp0 = 0, kp1 = 0, kq0 = 0, kq1 = 0;
		for (int i = 0;i < n;i++) {
			int p;
			cin >> p;
			p = abs(p);
			p = p % 2;
			if (p == 1) {
				kp1++;
			}
			else {
				kp0++;
			}
		}
		cin >> m;
		for (int i = 0;i < m;i++) {
			int q;
			cin >> q;
			q = abs(q);
			q = q % 2;
			if (q == 1) {
				kq1++;
			}
			else {
				kq0++;
			}
		}
		int ans = kp1 * kq1 + kq0 * kp0;
		cout << ans << endl;
	}
}


#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include<string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input1.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long ans, t, n, m, q;

	cin>>t;

	while(t--)
    {
        ans=0;
        cin>>n;
        vector<int> p(n);
        for(int i=0; i<n; i++)
            cin>>p[i];

        cin>>m;
        while(m--)
        {
            cin>>q;
            for(int i=0; i<n; i++)
            {
                if((q-p[i])%2==0)
                    ans++;
            }
        }

        cout<<ans<<'\n';
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include<string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input1.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long ans, t, n, m, q;

	cin>>t;

	while(t--)
    {
        ans=0;
        cin>>n;
        vector<int> p(n);
        for(int i=0; i<n; i++)
            cin>>p[i];

        cin>>m;
        while(m--)
        {
            cin>>q;
            for(int i=0; i<n; i++)
            {
                if((p[i]-q)%2)
                    ans++;
            }
        }

        cout<<ans<<'\n';
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include<string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input1.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long ans, t, n, m, q, p, a, b, c, d;

	cin>>t;

	while(t--)
    {
        a=0;
        b=0;
        c=0;
        d=0;
        cin>>n;
        while(n--)
        {
            cin>>p;
            if(p%2)
                a++;
            else
                b++;
        }

        cin>>m;
        while(m--)
        {
            cin>>q;
            if(q%2)
                c++;
            else
                d++;
        }

        cout<<a*c+b*d<<'\n';
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include<string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input1.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long ans, t, n, m, q;

	cin>>t;

	while(t--)
    {
        ans=0;
        cin>>n;
        vector<int> p(n);
        for(int i=0; i<n; i++)
            cin>>p[i];

        cin>>m;
        while(m--)
        {
            cin>>q;
            for(int i=0; i<n; i++)
            {
                if((p[i]-q)%2)
                    ans++;
            }
        }

        cout<<ans;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include<string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
    //freopen("input1.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long ans, t, n, m, q;

	cin>>t;

	while(t--)
    {
        ans=0;
        cin>>n;
        vector<int> p(n);
        for(int i=0; i<n; i++)
            cin>>p[i];

        cin>>m;
        while(m--)
        {
            cin>>q;
            for(int i=0; i<n; i++)
            {
                if((p[i]-q)%2)
                    ans++;
            }
        }

        cout<<ans<<'\n';

        return 0;
    }

    return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;

int main()
{
	int nT;
	cin >> nT;

	for (int t = 0; t < nT; t++)
	{
		uint64_t evenP = 0;
		uint64_t oddP = 0;
		{
			int N;
			cin >> N;

			for (int i = 0; i < N; i++)
			{
				int p;
				cin >> p;
				if (p % 2)
					++oddP;
				else
					++evenP;
			}
		}

		uint64_t evenQ = 0;
		uint64_t oddQ = 0;
		{
			int M;
			cin >> M;

			for (int i = 0; i < M; i++)
			{
				int q;
				cin >> q;
				if (q % 2)
					++oddQ;
				else
					++evenQ;
			}
		}

		uint64_t sum = evenP * evenQ + oddP * oddQ;
		cout << sum << endl;
	}

	return 0;
}


#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;

int main()
{
	int nT;
	cin >> nT;

	for (int t = 0; t < nT; t++)
	{
		int evenP = 0;
		int oddP = 0;
		{
			int N;
			cin >> N;

			for (int i = 0; i < N; i++)
			{
				int p;
				cin >> p;
				if (p % 2)
					++oddP;
				else
					++evenP;
			}
		}

		int evenQ = 0;
		int oddQ = 0;
		{
			int M;
			cin >> M;

			for (int i = 0; i < M; i++)
			{
				int q;
				cin >> q;
				if (q % 2)
					++oddQ;
				else
					++evenQ;
			}
		}

		int sum = evenP * evenQ + oddP * oddQ;
		cout << sum << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int t;
	cin >> t;
	long long numN, numM;
	long long nIn ,mIn;
	long long n2(0), n(0);
	long long m2, m;
	long long ans;
	for (int i = 0; i < t; ++i)
	{
		n2 = 0;
		n = 0;
		m2 = 0;
		m = 0;
		ans = 0;
		cin >> numN;
		for (int j = 0; j < numN; ++j)
		{
			cin >> nIn;
			if (nIn % 2 == 0)
				n2++;
			else
				n++;
		}
		cin >> numM;
		for (int j = 0; j < numM; ++j)
		{
			cin >> mIn;
			if (mIn % 2 == 0)
				m2++;
			else
				m++;
		}
		ans = m2 * n2;
		ans = ans + n * m;
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int t;
	cin >> t;
	int numN, numM;
	int nIn ,mIn;
	int n2(0), n(0);
	int m2, m;
	long long ans;
	for (int i = 0; i < t; ++i)
	{
		n2 = 0;
		n = 0;
		m2 = 0;
		m = 0;
		cin >> numN;
		for (int j = 0; j < numN; ++j)
		{
			cin >> nIn;
			if (nIn % 2 == 0)
				n2++;
			else
				n++;
		}
		cin >> numM;
		for (int j = 0; j < numM; ++j)
		{
			cin >> mIn;
			if (mIn % 2 == 0)
				m2++;
			else
				m++;
		}
		ans = m2 * n2 + m * n;
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int integerPoints();

int main()
{
	int T;
	cin >> T;

	for (int t = 0; t < T; t++) {
		cout << integerPoints() << "\n";
	}

	return 0;
}

int integerPoints() {
	int n;
	cin >> n;

	int pe = 0;
	int po = 0;
	int pz = 0;
	for (int i = 0; i < n; i++) {
		int pi;
		cin >> pi;
		if (pi == 0) {
			pz++;
		}
		else if (pi % 2 == 0) {
			pe++;
		}
		else {
			po++;
		}
	}

	int m;
	cin >> m;

	int qe = 0;
	int qo = 0;
	int qz = 0;
	for (int i = 0; i < m; i++) {
		int qi;
		cin >> qi;
		if (qi == 0) {
			qz++;
		}
		else if (qi % 2 == 0) {
			qe++;
		}
		else {
			qo++;
		}
	}

	return pe * qe + po * qo + pz * qe + qz * pe;
}


#include <iostream>
#include <vector>
using namespace std;

long integerPoints();

int main()
{
	int T;
	cin >> T;

	for (int t = 0; t < T; t++) {
		cout << integerPoints() << "\n";
	}

	return 0;
}

long integerPoints() {
	int n;
	cin >> n;

	long pe = 0;
	long po = 0;
	for (int i = 0; i < n; i++) {
		int pi;
		cin >> pi;
		if (pi % 2 == 0) {
			pe++;
		}
		else {
			po++;
		}
	}

	int m;
	cin >> m;

	long qe = 0;
	long qo = 0;
	for (int i = 0; i < m; i++) {
		int qi;
		cin >> qi;
		if (qi % 2 == 0) {
			qe++;
		}
		else {
			qo++;
		}
	}

	return pe * qe + po * qo;
}


#include <iostream>
#include <vector>
using namespace std;

long long integerPoints();

int main()
{
	int T;
	cin >> T;

	for (int t = 0; t < T; t++) {
		cout << integerPoints() << "\n";
	}

	return 0;
}

long long integerPoints() {
	int n;
	cin >> n;

	long long pe = 0;
	long long po = 0;
	for (int i = 0; i < n; i++) {
		long pi;
		cin >> pi;
		if (pi % 2 == 0) {
			pe++;
		}
		else {
			po++;
		}
	}

	int m;
	cin >> m;

	long long qe = 0;
	long long qo = 0;
	for (int i = 0; i < m; i++) {
		long qi;
		cin >> qi;
		if (qi % 2 == 0) {
			qe++;
		}
		else {
			qo++;
		}
	}

	return pe * qe + po * qo;
}


#include <iostream>
#include <vector>
using namespace std;

int integerPoints();

int main()
{
	int T;
	cin >> T;

	for (int t = 0; t < T; t++) {
		cout << integerPoints() << "\n";
	}

	return 0;
}

int integerPoints() {
	int n;
	cin >> n;

	int pe = 0;
	int po = 0;
	int pz = 0;
	for (int i = 0; i < n; i++) {
		int pi;
		cin >> pi;
		if (pi == 0) {
			pz++;
		}
		else if (pi % 2 == 0) {
			pe++;
		}
		else {
			po++;
		}
	}

	int m;
	cin >> m;

	int qe = 0;
	int qo = 0;
	int qz = 0;
	for (int i = 0; i < m; i++) {
		int qi;
		cin >> qi;
		if (qi == 0) {
			qz++;
		}
		else if (qi % 2 == 0) {
			qe++;
		}
		else {
			qo++;
		}
	}

	return pe * qe + po * qo + pz * qe + qz * pe + qz * pz;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <unordered_map>
using namespace std;

double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trl triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a < t2.a; else return t1.b < t2.b; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

#define FI(n) for(int i=0;i<n;i++)
#define FI1(n) for(int i=1;i<n;i++)
#define FJ(n) for(int j=0;j<n;j++)
#define FJ1(n) for(int j=1;j<n;j++)
#define FJI for(int j=0;j<i;j++)
#define FJI1 for(int j=1;j<i;j++)
#define FJIE for(int j=0;j<=i;j++)
#define FJIE1 for(int j=1;j<=i;j++)
#define For(i,a,b) for(int i=a;i<b;i++)

// Input macros
#define S(n)                        scanf("%d",&n)
#define SS(n)                       scanf("%s",n)
#define S2(a,b)                     scanf("%d%d",&a,&b)
#define Sc(n)                       scanf("%c",&n)
#define Sl(n)                       scanf("%I64d",&n)
#define Sl2(a,b)                    scanf("%I64d%I64d",&a,&b)
#define Sf(n)                       scanf("%lf",&n)
#define Sf2(a,b)                    scanf("%lf%lf",&a,&b)

//Output macros
#define Pr(n)                       printf("%d ",n)
#define Prn(n)                      printf("%d\n",n)
#define Prc(n)                      printf("%c",n)
#define Prcn(n)                     printf("%c\n",n)
#define Prl(n)                      printf("%I64d ",n)
#define Prln(n)                     printf("%I64d\n",n)
#define Prf(n)                      printf("%lf ",n)
#define Prfn(n)                     printf("%lf\n",n)
#define Prs(n)                      printf("%s ",n)
#define Prsn(n)                     printf("%s\n",n)

//STL containers
#define foreach(v, c)               for( auto v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ((b).find(a) != (b).end())
#define in2(a,b)                    (find(all(b),a) != (b).end())
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define svi(vec,n) FI(n) S(vec[y])
#define svl(vec,n) FI(n) Sl(vec[y])
#define IT ::iterator

//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}
//fill char arrays
#define fill(a,v)                    memset(a, v, sizeof (a))

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return (x >> 31) | (-x >> 31); }
inline bool ispow2(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n,b)        ( (n >> b) & 1)
#define INDEX(arr,ind)       (lower_bound(all(arr),ind)-arr.begin())
#define sor(a)  sort(all(a))
#define rsor(a) sort(all(a)); reverse(all(a));

//STL output ********************************
template<typename T1, typename T2>inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i < v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i < sz; i++) cout << a[i] << " "; cout << endl; }

#define FREIN(FILE) freopen(FILE,"rt",stdin)
#define FREOUT(FILE) freopen(FILE,"wt",stdout)

#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define pow(x,n) pow(1.0*(x),n)

inline ll binpow(ll x, ll n){ ll res = 1; while (n){ if (n & 1)res *= x; x *= x; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(int a, int b){ return a / gcd(a, b)*(ll)b; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }
inline ll lcm(ll a, ll b, ll c){ return lcm(lcm(a, b), c); }
inline ll lcm(int a, int b, int c){ return lcm(lcm(a, b), (ll)c); }

inline ll max(ll a, ll b){ return (a > b) ? a : b; }
inline int max(int a, int b){ return (a > b) ? a : b; }
inline double max(double a, double b){ return (a > b) ? a : b; }
inline ll max(ll a, ll b, ll c){ return max(a, max(b, c)); }
inline int max(int a, int b, int c){ return max(a, max(b, c)); }
inline double max(double a, double b, double c){ return max(a, max(b, c)); }
inline ll min(ll a, ll b){ return (a < b) ? a : b; }
inline int min(int a, int b){ return (a < b) ? a : b; }
inline double min(double a, double b){ return (a < b) ? a : b; }
inline ll min(ll a, ll b, ll c){ return min(a, min(b, c)); }
inline int min(int a, int b, int c){ return min(a, min(b, c)); }
inline double min(double a, double b, double c){ return min(a, min(b, c)); }

template<class T>
inline void getar(T a, int n, int m){ for (int i = 0; i < n; i++) for (int j = 0; j < m; ++j) { scanf("%d", &a[i][j]); } }
inline void getar(int *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d", a + ii); } }
inline void getar(pii *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d%d", &a[ii].first, &a[ii].second); } }
inline void getar(ll *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%I64d", a + ii); } }
template<class T>
inline void cinarr(T a, int n){ for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T>
inline bool scan_d(T &ret) {
  char c; int sgn;
  if(c = getchar(),c == EOF) return 0; //EOF
  while(c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while(c = getchar(),c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}

inline void out(int x) {
  if(x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
// Useful constants
#define INF         9000000000
#define EPS         (double)1e-9
#define mod         1000000007
#define PI          3.14159265358979
//*******************************************************************************/

int main() {
  int nter,n,tmp;
  int num[2][2];
  scanf("%d", &nter);
  while (nter--) {
    num[0][0] = num[0][1] = num[1][0] = num[1][1] = 0;
    for (int i = 0; i < 2; i++) {
      scanf("%d", &n);
      for (int j = 0; j < n; j++) {
        scanf("%d", &tmp);
        if (tmp & 1) {
          num[i][0]++;
        } else {
          num[i][1]++;
        }
      }
    }
    printf("%d\n", num[0][0] * num[1][0] + num[0][1] * num[1][1]);
  }
  return 0;
}


#pragma comment(linker, "/stack:20000000")
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <unordered_map>
using namespace std;

double __begin;
#define DTIME(ccc) __begin = clock(); ccc; std::cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<std::endl;

#define mp make_pair
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

template<typename T1, typename T2, typename T3>
struct triple{ T1 a; T2 b; T3 c; triple(){}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
#define tri triple<int,int,int>
#define trl triple<ll,ll,ll>
template<typename T1, typename T2, typename T3>
bool operator<(const triple<T1, T2, T3> &t1, const triple<T1, T2, T3> &t2){ if (t1.a != t2.a) return t1.a < t2.a; else return t1.b < t2.b; }
template<typename T1, typename T2, typename T3>
inline std::ostream& operator << (std::ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }

#define FI(n) for(int i=0;i<n;i++)
#define FI1(n) for(int i=1;i<n;i++)
#define FJ(n) for(int j=0;j<n;j++)
#define FJ1(n) for(int j=1;j<n;j++)
#define FJI for(int j=0;j<i;j++)
#define FJI1 for(int j=1;j<i;j++)
#define FJIE for(int j=0;j<=i;j++)
#define FJIE1 for(int j=1;j<=i;j++)
#define For(i,a,b) for(int i=a;i<b;i++)

// Input macros
#define S(n)                        scanf("%d",&n)
#define SS(n)                       scanf("%s",n)
#define S2(a,b)                     scanf("%d%d",&a,&b)
#define Sc(n)                       scanf("%c",&n)
#define Sl(n)                       scanf("%I64d",&n)
#define Sl2(a,b)                    scanf("%I64d%I64d",&a,&b)
#define Sf(n)                       scanf("%lf",&n)
#define Sf2(a,b)                    scanf("%lf%lf",&a,&b)

//Output macros
#define Pr(n)                       printf("%d ",n)
#define Prn(n)                      printf("%d\n",n)
#define Prc(n)                      printf("%c",n)
#define Prcn(n)                     printf("%c\n",n)
#define Prl(n)                      printf("%I64d ",n)
#define Prln(n)                     printf("%I64d\n",n)
#define Prf(n)                      printf("%lf ",n)
#define Prfn(n)                     printf("%lf\n",n)
#define Prs(n)                      printf("%s ",n)
#define Prsn(n)                     printf("%s\n",n)

//STL containers
#define foreach(v, c)               for( auto v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ((b).find(a) != (b).end())
#define in2(a,b)                    (find(all(b),a) != (b).end())
#define pb                          push_back
#define sz(a)                       ((int)(a.size()))
#define svi(vec,n) FI(n) S(vec[y])
#define svl(vec,n) FI(n) Sl(vec[y])
#define IT ::iterator

//int some_primes[10] = {100271, 500179, 1000003, 2000227, 5000321}
//fill char arrays
#define fill(a,v)                    memset(a, v, sizeof (a))

inline int bits_count(int v){ v = v - ((v >> 1) & 0x55555555); v = (v & 0x33333333) + ((v >> 2) & 0x33333333); return((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; }
inline int bits_count(ll v){ int t = v >> 32; int p = (v & ((1LL << 32) - 1)); return bits_count(t) + bits_count(p); }
unsigned int reverse_bits(register unsigned int x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
inline int sign(int x){ return (x >> 31) | (-x >> 31); }
inline bool ispow2(int x){ return (x != 0 && (x&(x - 1)) == 0); }
#define checkbit(n,b)        ( (n >> b) & 1)
#define INDEX(arr,ind)       (lower_bound(all(arr),ind)-arr.begin())
#define sor(a)  sort(all(a))
#define rsor(a) sort(all(a)); reverse(all(a));

//STL output ********************************
template<typename T1, typename T2>inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p){ return os << "(" << p.first << ", " << p.second << ")"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::vector<T>& v){ bool first = true; os << "["; for (unsigned int i = 0; i < v.size(); i++){ if (!first)os << ", "; os << v[i]; first = false; }return os << "]"; }
template<typename T>inline std::ostream &operator<<(std::ostream &os, const std::set<T>&v){ bool first = true; os << "["; for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T1, typename T2>inline std::ostream &operator << (std::ostream & os, const std::map<T1, T2>& v){ bool first = true; os << "["; for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii){ if (!first)os << ", "; os << *ii; first = false; }return os << "]"; }
template<typename T, typename T2>void printarray(T  a[], T2 sz, T2 beg = 0){ for (T2 i = beg; i < sz; i++) cout << a[i] << " "; cout << endl; }

#define FREIN(FILE) freopen(FILE,"rt",stdin)
#define FREOUT(FILE) freopen(FILE,"wt",stdout)

#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define pow(x,n) pow(1.0*(x),n)

inline ll binpow(ll x, ll n){ ll res = 1; while (n){ if (n & 1)res *= x; x *= x; n >>= 1; }return res; }
inline ll powmod(ll x, ll n, ll _mod){ ll res = 1; while (n){ if (n & 1)res = (res*x) % _mod; x = (x*x) % _mod; n >>= 1; }return res; }
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline int gcd(int a, int b){ int t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
inline ll lcm(int a, int b){ return a / gcd(a, b)*(ll)b; }
inline ll lcm(ll a, ll b){ return a / gcd(a, b)*b; }
inline ll gcd(ll a, ll b, ll c){ return gcd(gcd(a, b), c); }
inline int gcd(int a, int b, int c){ return gcd(gcd(a, b), c); }
inline ll lcm(ll a, ll b, ll c){ return lcm(lcm(a, b), c); }
inline ll lcm(int a, int b, int c){ return lcm(lcm(a, b), (ll)c); }

inline ll max(ll a, ll b){ return (a > b) ? a : b; }
inline int max(int a, int b){ return (a > b) ? a : b; }
inline double max(double a, double b){ return (a > b) ? a : b; }
inline ll max(ll a, ll b, ll c){ return max(a, max(b, c)); }
inline int max(int a, int b, int c){ return max(a, max(b, c)); }
inline double max(double a, double b, double c){ return max(a, max(b, c)); }
inline ll min(ll a, ll b){ return (a < b) ? a : b; }
inline int min(int a, int b){ return (a < b) ? a : b; }
inline double min(double a, double b){ return (a < b) ? a : b; }
inline ll min(ll a, ll b, ll c){ return min(a, min(b, c)); }
inline int min(int a, int b, int c){ return min(a, min(b, c)); }
inline double min(double a, double b, double c){ return min(a, min(b, c)); }

template<class T>
inline void getar(T a, int n, int m){ for (int i = 0; i < n; i++) for (int j = 0; j < m; ++j) { scanf("%d", &a[i][j]); } }
inline void getar(int *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d", a + ii); } }
inline void getar(pii *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%d%d", &a[ii].first, &a[ii].second); } }
inline void getar(ll *a, int n){ for (int ii = 0; ii < n; ii++){ scanf("%I64d", a + ii); } }
template<class T>
inline void cinarr(T a, int n){ for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T>
inline bool scan_d(T &ret) {
  char c; int sgn;
  if(c = getchar(),c == EOF) return 0; //EOF
  while(c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while(c = getchar(),c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}

inline void out(int x) {
  if(x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
// Useful constants
#define INF         9000000000
#define EPS         (double)1e-9
#define mod         1000000007
#define PI          3.14159265358979
//*******************************************************************************/

int main() {
  int nter,n,tmp;
  long long num[2][2];
  scanf("%d", &nter);
  while (nter--) {
    num[0][0] = num[0][1] = num[1][0] = num[1][1] = 0;
    for (int i = 0; i < 2; i++) {
      scanf("%d", &n);
      for (int j = 0; j < n; j++) {
        scanf("%d", &tmp);
        if (tmp & 1) {
          num[i][0]++;
        } else {
          num[i][1]++;
        }
      }
    }
    printf("%lld\n", num[0][0] * num[1][0] + num[0][1] * num[1][1]);
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main()
{
    int tests;
    cin >> tests;
    for(int i=0;i<tests;i++){
        long long int n,m,even=0,even1=0;
        long long int c;
        cin >> n;
        for(int i=0;i<n;i++){
            int x;
            cin >> x;
            if(x%2==0) even++;
        }
        cin >> m;
        for(int i=0;i<m;i++){
            int x;
            cin >> x;
            if(x%2==0) even1++;
        }
        c = even*even1+(n-even)*(m-even1);
        cout << c << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main()
{
    int tests;
    cin >> tests;
    for(int i=0;i<tests;i++){
        int n,m,even=0,even1=0;
        cin >> n;
        for(int i=0;i<n;i++){
            int x;
            cin >> x;
            if(x%2==0) even++;
        }
        cin >> m;
        for(int i=0;i<m;i++){
            int x;
            cin >> x;
            if(x%2==0) even1++;
        }
        cout << even*even1+(n-even)*(m-even1) << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main()
{
    int tests;
    cin >> tests;
    for(int i=0;i<tests;i++){
        int n,m,even=0,even1=0;
        long long int c;
        cin >> n;
        for(int i=0;i<n;i++){
            int x;
            cin >> x;
            if(x%2==0) even++;
        }
        cin >> m;
        for(int i=0;i<m;i++){
            int x;
            cin >> x;
            if(x%2==0) even1++;
        }
        c = even*even1+(n-even)*(m-even1);
        cout << c << endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <set>
using namespace std;
int main()
{
    int tests;
    cin >> tests;
    for(int i=0;i<tests;i++){
        int n,m;
        int count=0;
        cin >> n;
        vector <int> a(n);
        for(int i=0;i<n;i++) cin >> a[i];
        cin >> m;
        vector <int> b(m);
        for(int i=0;i<m;i++) cin >> b[i];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if((b[j]-a[i])%2==0) count++;
            }
        }
        cout << count << "\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	int t,n,m,p;
	cin>>t;
	while(t>0){
		cin>>n;
		int f1=0,f2=0,z1=0,z2=0;
		for(int i=0; i<n; i++){
			cin>>p;
			if(p%2) f1++;
			else z1++;
		}
		cin>>m;
		for(int i=0; i<m; i++){
			cin>>p;
			if(p%2) f2++;
			else z2++;
		}
		long long int x=z1*z2+f1*f2;
		cout<<x<<endl;
		t--;
	}
}


#include <iostream>
using namespace std;
int main(){
	int t,n,m,p;
	cin>>t;
	while(t>0){
		cin>>n;
		int f1=0,f2=0,z1=0,z2=0;
		for(int i=0; i<n; i++){
			cin>>p;
			if(p%2) f1++;
			else z1++;
		}
		cin>>m;
		for(int i=0; i<m; i++){
			cin>>p;
			if(p%2) f2++;
			else z2++;
		}
		cout<<z1*z2+f1*f2<<endl;
		t--;
	}
}


#include <iostream>
using namespace std;
int main(){
	long long int t,n,m,p,f1,f2,z1,z2;
	cin>>t;
	while(t>0){
		cin>>n;
		f1=0,f2=0,z1=0,z2=0;
		for(int i=0; i<n; i++){
			cin>>p;
			if(p%2) f1++;
			else z1++;
		}
		cin>>m;
		for(int i=0; i<m; i++){
			cin>>p;
			if(p%2) f2++;
			else z2++;
		}
		cout<<z1*z2+f1*f2<<endl;
		t--;
	}
}


#include<stdio.h>
int main()
{
	long long int a, b, c, d;
	scanf_s("%lld", &a);
	for (; a > 0; a--)
	{
		long long int ji = 0;
		long long int ji1 = 0;
		long long int ou1 = 0;
		long long int ou = 0;
		scanf_s("%lld", &b);
		for (; b > 0; b--)
		{
			scanf_s("%lld", &c);
			if (c % 2 == 0)
				ou += 1;
			else
				ji += 1;
		}
		scanf_s("%lld", &b);
		for (; b > 0; b--)
		{
			scanf_s("%lld", &c);
			if (c % 2 == 0)
				ou1 += 1;
			else
				ji1 += 1;
		}
		d = ji * ji1 + ou * ou1;
		printf("%lld\n", d);
	}
	return 0;
}


#include <iostream>
#include <vector>
int a, b, c, d, e;

int main() {
	std::cin >> a;
	for (int k = 1; k <= a; k++) {
		std::cin >> b;
		std::vector<int>first;
		std::vector<int> second;
		for (int y = 1; y <= b; y++) {
			std::cin >> c;
			first.push_back(c);
		}
		std::cin >> d;
		for (int y = 1; y <= d; y++) {
			std::cin >> e;
			second.push_back(e);
		}
		int banyak = 0;
		for (int y = 0; y < first.size(); y++) {
			for (int t = y; t < second.size(); t++) {
				if ((first[y] + second[t]) % 2 == 0) {
					banyak++;
				}
			}
		}
		std::cout << banyak << '\n';
	}
}


#include <iostream>
#include <vector>

long long a, b, c, d, e;

int main() {
	std::cin >> a;
	for (int k = 1; k <= a; k++) {
		std::cin >> b;
		long long o1 = 0;
		long long e1 = 0;
		long long o2 = 0;
		long long e2 = 0;
		for (int y = 1; y <= b; y++) {
			std::cin >> c;
			if (c % 2 == 0) {
				e1++;
			}
			else
				o1++;
		}
		std::cin >> d;
		for (int y = 1; y <= d; y++) {
			std::cin >> e;
			if (e % 2 == 0) {
				e2++;
			}
			else {
				o2++;
			}
		}
		int banyak = 0;
		std::cout << e1*e2+o1*o2 << '\n';
	}
}


#include <iostream>
#include <vector>
int a, b, c, d, e;

int main() {
	std::cin >> a;
	for (int k = 1; k <= a; k++) {
		std::cin >> b;
		std::vector<int>first;
		std::vector<int> second;
		for (int y = 1; y <= b; y++) {
			std::cin >> c;
			first.push_back(c);
		}
		std::cin >> d;
		for (int y = 1; y <= d; y++) {
			std::cin >> e;
			second.push_back(e);
		}
		int banyak = 0;
		for (int y = 0; y < first.size(); y++) {
			for (int t = 0; t < second.size(); t++) {
				if ((first[y] + second[t]) % 2 == 0) {
					banyak++;
				}
			}
		}
		std::cout << banyak << '\n';
	}
}


#include <iostream>
#include <vector>
int a, b, c, d, e;

int main() {
	std::cin >> a;
	for (int k = 1; k <= a; k++) {
		std::cin >> b;
		int o1 = 0;
		int e1 = 0;
		int o2 = 0;
		int e2 = 0;
		for (int y = 1; y <= b; y++) {
			std::cin >> c;
			if (c % 2 == 0) {
				e1++;
			}
			else
				o1++;
		}
		std::cin >> d;
		for (int y = 1; y <= d; y++) {
			std::cin >> e;
			if (e % 2 == 0) {
				e2++;
			}
			else {
				o2++;
			}
		}
		int banyak = 0;
		std::cout << e1*e2+o1*o2 << '\n';
	}
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 2 * 100 * 1000 + 100;
const int N = 2 * 1000 * 1000 + 10;
const int MOD = 1e6 + 3;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
	return a == 0 ? b : gcd(b % a, a);
}

int sign(int x)
{
	return (x > 0) - (x < 0);
}

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

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

	int t;
	cin >> t;

	forn(t1, t)
	{
		int n;
		cin >> n;

		vector<int> p(2);
		forn(i, n)
		{
			int p1;
			cin >> p1;
			p[p1 % 2]++;
		}

		int m;
		cin >> m;

		vector<int> q(2);
		forn(i, m)
		{
			int q1;
			cin >> q1;
			q[q1 % 2]++;
		}

		cout << 1ll * p[0] * q[0] + 1ll * p[1] * q[1] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <string>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define forb(i, n) for(int i = int(n) - 1; i >= 0; --i)

const int INF = 1e9 + 1000;
const li INF64 = 1e15 + 1000;
const int M = 2 * 100 * 1000 + 100;
const int N = 2 * 1000 * 1000 + 10;
const int MOD = 1e6 + 3;
const double EPS = 1e-9;
const double PI = 3.14159265359;

li gcd(li a, li b) {
	return a == 0 ? b : gcd(b % a, a);
}

int sign(int x)
{
	return (x > 0) - (x < 0);
}

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

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

	int t;
	cin >> t;

	forn(t1, t)
	{
		int n;
		cin >> n;

		vector<int> p(2);
		forn(i, n)
		{
			int p1;
			cin >> p1;
			p[p1 % 2]++;
		}

		int m;
		cin >> m;

		vector<int> q(2);
		forn(i, m)
		{
			int q1;
			cin >> q1;
			q[q1 % 2]++;
		}

		cout << 1ll * p[0] * q[0] + 1ll * p[1] * q[1] << endl;;
	}
}


for i in range(int(input())):
    l1,r1,l2,r2=list(map(int,input().split()))
    ans=[]
    if(l1==l2 or r1==r2):
        ans.append(l1)
        ans.append(r2)
    elif(r1<=l2):
        ans.append(l1)
        ans.append(r2)
    elif(r2<=l1):
        ans.append(r1)
        ans.append(l2)
    else:
        ans.append(l1)
        ans.append(l2)
    if(ans[0]>r1 or ans[0]<l1):
        ans.reverse()
    for j in range(2):
        print(ans[j],end=' ')
    print(end='\n')


for i in range(int(input())):
    l1,r1,l2,r2=list(map(int,input().split()))
    ans=[]
    if(l1==l2 or r1==r2):
        ans.append(l1)
        ans.append(r2)
    elif(r1<=l2):
        ans.append(l1)
        ans.append(r2)
    elif(r2<=l1):
        ans.append(r1)
        ans.append(l2)
    else:
        ans.append(l1)
        ans.append(l2)
    for j in range(2):
        print(ans[j],end=' ')
    print(end='\n')


# import sys
import random
# sys.stdin=open("input.in",'r')
# sys.stdout=open("outp.out",'w')
n=int(input())
for i in range(n):
	a=list(map(int,input().split()))
	if a[0]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2]+1,a[3]+1)
	elif a[0]==a[3]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3])
	if a[1]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2]+1,a[3])
	elif a[1]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3])
	else:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3]+1)
	print(x,y)


# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("outp.out",'w')
n=int(input())
for i in range(n):
	a,b,c,d=map(int,input().split())
	if a==c:
		print(a,d)
	else:
		print(a,c)


# import sys
import random
# sys.stdin=open("input.in",'r')
# sys.stdout=open("outp.out",'w')
n=int(input())
for i in range(n):
	a=list(map(int,input().split()))
	x=random.randint(a[0],a[1]+1)
	y=random.randint(a[2],a[3]+1)
	print(x,y)


# import sys
import random
# sys.stdin=open("input.in",'r')
# sys.stdout=open("outp.out",'w')
n=int(input())
for i in range(n):
	a=list(map(int,input().split()))
	if a[0]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2]-1,a[3]+1)
	elif a[0]==a[3]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3])
	if a[1]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2]-1,a[3])
	elif a[1]==a[2]:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3])
	else:
		x=random.randint(a[0],a[1]+1)
		y=random.randint(a[2],a[3]+1)
	print(x,y)


for _ in range(int(input())):
	a, x, b, y = map(int, input().split())
	print(a, y) if a!=y print(a+1, y)


for _ in range(int(input())):
	a, x, b, y = map(int, input().split())
	print(a, y)


for _ in range(int(input())):
	a, x, b, y = map(int, input().split())
	print(a, y) if a!=y else print(a+1, y)


for _ in [0]*int(input()):
    s=[int(i) for i in input().split()];s.sort();print(s[1],s[2])


for _ in [0]*int(input()):
    s=[int(i) for i in input().split()];s.sort();print(s[1],s[2]+(s[1]==s[2]))


q = int(input())
for _ in range(q):
	l1, _, l2, _ = map(int, input().split())
	print(l1, l2 + (l1 == l2))


q = int(input())
for _ in range(q):
	l1, r1, l2, r2 = map(int, input().split())
	if l1 > r2:
		l1 = l2
		r1 = r2
	print(l1, r2)


q = int(input())
for _ in range(q):
	[l1, r1, l2, r2] = list(input().split())
	if l1 > r2:
		l1 = l2
		r1 = r2
	print(int(float(l1)) if float(l1) == int(float(l1)) else int(float(l1))+1, end = ' ')
	print(int(float(r2)))


q = int(input())
for _ in range(q):
	l1, r1, l2, r2 = map(int, input().split())
	print(l1, l2+ (l1==l2))


q = int(input())
for _ in range(q):
	[l1, r1, l2, r2] = list(input().split())
	print(int(float(l1)) if float(l1) == int(float(l1)) else int(float(l1))+1, end = ' ')
	print(int(float(r2)))


q = int(input())
for _ in range(q):
	l1, r1, l2, r2 = map(int, input().split())
	if l1 == l2:
		print(l1, l2 + 1)
	else:
	    print(l1, l2)


import sys
sys.stdin=open("input.in","r")
sys.stdout=open("output.out","w")

a=int(input())
b=[]
for x in range(a):
	b.append(list(map(int,input().split())))
	print(b[x][0],b[x][3],sep=' ')


a=int(input())
b=[]
for x in range(a):
	b.append(list(map(int,input().split())))
	print(b[x][0],b[x][3],sep=' ')


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

 q=int(input())
for i in range(q):
	a,b,c,d=map(int,input().split())
	if c==a:
		print(a,d)
	else:
		print(a,c)


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

q=int(input())
for i in range(q):
	a,b,c,d=map(int,input().split())
	if c==a:
		print(a,d)
	else:
		print(a,c)


q=int(input())
for _ in range(q):
    a,b,c,d=map(int,input().split())
    if a==c and b<=d:
        print(a,b)
    elif a<c:
        print(a,c)
    elif a>c and b>d:
        print(a,d)


q=int(input())
for _ in range(q):
    a,b,c,d=map(int,input().split())
    if a==c and b<=d:
        print(a,b)
    elif a<c:
        print(a,c)
    elif a>=c and b>d:
        print(a,d)


t=int(input())
for _ in range(t):
    a,b,c,d=map(int,input().split())
    if a==c:
        print(a,c+1)
    else:
        print(a,c)


q=int(input())
for i in range(q):
    [a,b,c,d]=[int(x) for x in input().split()]
    if a==c:
        if a==b:
            print(a,d)
        else:
            print(a,b)
    else:
        print(a,c)


q=int(input())
for i in range(q):
    [a,b,c,d]=[int(x) for x in input().split()]
    if b==d:
        if b==c:
            print(a,b)
        else:
            print(b,c)
    else:
        print(b,d)


q=int(input())
for i in range(q):
    [a,b,c,d]=[int(x) for x in input().split()]
    if (d>a and c>b) or (d<a and c<b):
        print(b,c)
    elif b==c:
        print(b-1,c+1)
    else:print(max(a,c),min(b,d))


q=int(input())
for i in range(q):
    [a,b,c,d]=[int(x) for x in input().split()]

    if b==c:
        print(b-1,c+1)
    else:print(max(a,c),min(b,d))


n=int(input())
for i in range(n):
    inp=input().split()
    l1=int(inp[0])
    r1=int(inp[1])
    l2=int(inp[2])
    r2=int(inp[3])

    print(l1,r2)


n=int(input())
for i in range(n):
    inp=input().split()
    l1=int(inp[0])
    r1=int(inp[1])
    l2=int(inp[2])
    r2=int(inp[3])

    if(l1==l2 and r1==r2):
        print(l1,r1)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r2>r1):
        print(l2,r1)
    elif(l1>l2 and r2 >r1):
        print(l1,r2)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r1>=l2):
        print(l1,r2)
    elif(l2>l1 and r2>=r1):
        print(l1,l2)


n=int(input())
for i in range(n):
    inp=input().split()
    l1=int(inp[0])
    r1=int(inp[1])
    l2=int(inp[2])
    r2=int(inp[3])

    if(l1==l2):
        print(l1,r2)
    else:
        print(l1,l2)


nt(input())
for i in range(n):
    inp=input().split()
    l1=int(inp[0])
    r1=int(inp[1])
    l2=int(inp[2])
    r2=int(inp[3])

    if(l1==l2 and r1==r2):
        print(l1,r2)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r2>r1):
        print(l1,r2)
    elif(l1>l2 and r2 >r1):
        print(l1,r2)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r1>=l2):
        print(l1,r2)
    elif(l2>l1 and r2>=l1):
        print(r1,l2)
    elif(l2==l1 and r2>r1):
        print(l1,r1)
    elif(r1==r2 and l1>l2):
        print(l1,r1)
    elif(r1==r2 and l1>l2):
        print(l1,r2)
    elif(l1==l2 and r1>r2):
        print(l1,r1)


n=int(input())
for i in range(n):
    inp=input().split()
    l1=int(inp[0])
    r1=int(inp[1])
    l2=int(inp[2])
    r2=int(inp[3])

    if(l1==l2 and r1==r2):
        print(l1,r1)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r2>r1):
        print(l1,r2)
    elif(l1>l2 and r2 >r1):
        print(l1,r2)
    elif(l2>l1 and r1>r2):
        print(l1,r2)
    elif(l1>l2 and r1>=l2):
        print(l1,r2)
    elif(l2>l1 and r2>=r1):
        print(l1,l2)
    elif(l2==l1 and r2>r1):
        print(l1,r1)
    elif(r1==r2 and l1>l2):
        print(l1,r1)
    elif(r1==r2 and l1>l2):
        print(l1,r2)
    elif(l1==l2 and r1>r2):
        print(l1,r1)


a = int(input())
for i in range(a):
    m,n,s,d = map(int, input().split())
    print(m,d)


a = int(input())
for i in range(a):
    m,n,s,d = map(int, input().split())
    if m == d:
        d = d - 1
    print(m,d)


a = int(input())
for i in range(a):
    m,n,s,d = map(int, input().split())
    print(m,s+1)


a = int(input())
for i in range(a):
    m,n,s,d = map(int, input().split())
    print(m,d+1)


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    print(l1,r2)


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    print(min(l1,l2),max(r1,r2))


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    print(min(l1,l2),max(r2,l2))


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    if l1 <= l2:
        print(l1,r2)
    else:
        print(l2,r1)


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    if l1 <= l2:
        print(l1,r2)
    else:
        print(r1,l2)


q = int(input())

for _ in range(q):
    l1,r1,l2,r2 = [int(x) for x in input().split()]
    print(min(l1,r1),max(r2,l2))


for i in range(int(input())):

    l1,r1,l2,r2= map(int,input().split())

    if l1==l2 and r1==r2:
        print(l1,r2)
    else:
        print(l1,l2)


for i in range(int(input())):

    l1,r1,l2,r2= map(int,input().split())

    if l1==l2 and r1==r2:
        print(r1,l2)
    elif l1+r1 > l2+r2:

        print(l2,r2)
    elif l1+r1 == l2+r2:
        print(l1+r1//2,l1)
    elif l1+r1<l2+r2:
        print(l1,r2)
    else:
        print(l1+r1//2,l2+r2//2)


for i in range(int(input())):

    l1,r1,l2,r2= map(int,input().split())

    if l1==l2:
        print(l1,r2)
    else:
        print(l1,l2)


l1,r1,l2,r2= map(int,input().split())

if l1==l2 & r1==r2:
    print(l1,r2)
else:
    print(l1,l2)


for _ in range(int(input())):
    l1,r1,l2,r2=map(int,input().split())
    print(r1//2,r2)


import math
for _ in range(int(input())):
    l1,r1,l2,r2=map(int,input().split())
    print(math.ceil((l1+r1)/2),math.floor((l2+r2)/2))


for _ in range(int(input())):
    l1,r1,l2,r2=map(int,input().split())
    #print((l1==l2))
    print(l1,l2+(l1==l2))


n=int(input())
for i in range(n):
    p=list(map(int,input().split()))
    if p[0]<=p[2]:
        print(str(p[0])+" "+str(p[3]))
    else:
        print(str(p[1])+" "+str(p[2]))


n=int(input())
for i in range(n):
    p=map(int,input().split())
    if p[0]<=p[2]:
        print(str(p[0])+" "+str(p[3])
    else:
        print(str(p[1])+" "+str(p[2])


n=int(input())
for i in range(n):
    p=map(int,input().split())
    if p[0]<=p[2]:
        print(str(p[0])+" "+str(p[3]))
    else:
        print(str(p[1])+" "+str(p[2]))


n=int(input())
for i in range(n):
    p=map(int,input().split())
    if p[0]<=p[2]:
        print(str(p[0])+" "+str(p[3]))
    else:
        print(str(p[1])+" "+str(p[2])


n=int(input())
for i in range(n):
    p=list(map(int,input().split()))
    #if p[0]<=p[2]:
    print(str(p[0])+" "+str(p[3]))
    #else:
    #   print(str(p[1])+" "+str(p[2]))


for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    for i in range(1,10**9 + 1):
        if i>=a and i<=b:
            print(i,end=' ')
            break
    for x in range(1,10**9 + 1):
        if x>=c and x<=d and x!=i:
            print(x)
            break


for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    if a!=d:
        print(a,d)
    else:
        print(a+1,d)


for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    if a!=d:
        print(a,d)
    else:
        print(a-1,d)


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

x=int(input())
for i in range(x):
	l=list(map(int,input().split()))
	print("{} {}".format(l[0],l[3]))


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

n=int(input())
for i in range(n):
	l=[]
	q=[]
	p=list(map(int,input().split()))
	for i in range(p[0],p[1]+1):
		l.append(i)
	for i in range(p[2],p[3]+1):
		q.append(i)
	if(l[0]!=q[0]):
		print(l[0],end=" ")
		print(q[0])
	else:
		print(l[0],end=" ")
		print(q[1])


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

n=int(input())
for i in range(n):
	l=[]
	p=list(map(int,input().split()))
	for i in range(p[0],p[1]+1):
		l.append(i)
	for i in range(p[2],p[3]+1):
		l.append(i)
	q=list(set(l))
	print(q[0],end=" ")
	print(q[1])


# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")

n=int(input())
for i in range(n):
	p=list(map(int,input().split()))
	if(p[0]!=p[2]):
		print(p[0],end=" ")
		print(p[2])
	else:
		a=p[2]+1
		print(p[0],end=" ")
		print(a)


n=int(input())
a=[]
for i in range (1,n+1):
    x,y,z,b = map(int, input().split())
    a.append(x)
    a.append(z)
for j in range(0,len(a)):
    if j%2==0:
        print(a[j],end=' ')
    if j%2!=0:
        print(a[j])


n=int(input())
a=[]
for i in range(1,n+1):
    x,y,z,b=map(int,input().split())
    a.append(x)
    a.append(z)
for j in range(0,len(a)):
    if j%2==0:
        print(a[j],end=' ')
    else:
        print(a[j])


x,y,z,b = map(int, input().split())
print(x,end=' ')
print(b)


n=int(input())
a=[]
for i in range(1,n+1):
    x,y,z,b=map(int,input().split())
    if x!=z:
        a.append(x)
        a.append(z)
    elif x!=b:
        a.append(x)
        a.append(b)
    elif y!=b:
        a.append(y)
        a.append(b)
    elif y!=z:
        a.append(y)
        a.append(z)
for j in range(0,len(a)):
    if j%2==0:
        print(a[j],end=' ')
    else:
        print(a[j])


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = int(l1)
		b = int(r2)
		print(a,b)

	else:
		if l1 == l2 and r1 == r2:
			a = int(l1)
			b = int(r1)
			print(a,b)
		else:
			a = int(l1)
			b = int(r2)
			print(a,b)


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = int(l1)
		b = int(r2)
		print(a,b)

	elif l1 == l2 and r1 == r2:
		a = int(l1)
		b = int(r1)
		print(a,b)

	else:
		a = int(l1)
		b = int(r2)
		if a == b:
			b = l2
		print(a,b)


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = l1
		b = r2
		output.append((a,b))

	else:
		if l1 == l2 and r1 == r2:
			a = l1
			b = r1
			output.append((a,b))
		else:
			a = l1
			b = r2
			output.append((a,b))

for result in output:
	print(result)


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = int(l1)
		b = int(r2)
		print(a,b)

	elif l1 == l2 and r1 == r2:
		a = int(l1)
		b = int(r1)
		print(a,b)

	else:
		a = int(l1)
		b = int(r2)
		print(a,b)


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = int(l1)
		b = int(r2)
		print(a , b)

	else:
		if l1 == l2 and r1 == r2:
			a = int(l1)
			b = int(r1)
			print(a,b)
		else:
			a = int(l1)
			b = int(r2)
			print(a,b)


n = int(input())
lista = [input().split() for _ in range(n)]
output = []
a = b = 0

for query in lista:
	l1,r1,l2,r2 = query[0],query[1],query[2],query[3]
	if r1 <= l2:
		a = int(l1)
		b = int(r2)
		print(a,b)

	else:
		if l1 == l2 and r1 == r2:
			a = int(l1)
			b = int(r1)
			print(a,b)
		else:
			a = int(l1)
			b = int(r2)
			if a == b:
				b -=1
				print(a,b)


#python 3.7
a=int(input())
for i in range(a):
  b, c, d, e=map(int, input().split())
  if b==c and d==e:
    print(c, b)
  elif b<=d and c>=e:
    print(d, e)
  else:
    print((b+c)//2,(d+e)//2)


#python 3.7.1

#python 3.7
a=int(input())
for i in range(a):
  b, c, d, e=map(int, input().split())
  g=(b+c)//2
  h=(d+e)//2
  if g==h:
    print(g+1,h)
  else:
    print(g, h)


#python 3.7
a=int(input())
for i in range(a):
  b, c, d, e=map(int, input().split())
  if b==c and d==e:
    print(c, b)
  elif b<=d and c>=e:
    print(d, e)
  else:

    print((b+c)//2+1,(d+e)//2-1)


import random

q_inputs = {}

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = list(range(l1, r1+1))
	range_b = list(range(l2, r2+1))
	a = random.randint(l1, r1)
	b = random.randint(l2, r2)
	while a == b:
		if range_a > range_b:
			a = random.randint(l1, r1-1)
		else:
			b = random.randint(l2, r2-1)
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


q_inputs = {}

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	a = l1
	b = l2
	if a == b:
		a = l1
		b = r1
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


def compare(range_x, y):
	for i in range(0, len(range_x)):
		if range_x[i] != y:
			x = range_x[i]
			break
	return x

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = range(l1, r1+1)
	range_b = range(l2, r2+1)
	i = 0
	a = -1
	while a == -1:
		if len(range_a) > len(range_b):
			b = range_b[i]
			a = compare(range_a, b)
			i = i + 1
		else:
			a = range_a[i]
			b = compare(range_b, a)
			i = i + 1
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs = inp.split()
	gen_int(q_inputs)


import random

q_inputs = {}

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = list(range(l1, r1+1))
	range_b = list(range(l2, r2+1))
	a = random.randint(l1, r1)
	b = random.randint(l2, r2)
	if a == b:
		if range_a > range_b:
			a = random.randint(l1, r1-1)
		else:
			b = random.randint(l2, r2-1)
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


import random

q_inputs = {}

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = list(range(l1, r1+1))
	range_b = list(range(l2, r2+1))
	if range_a > range_b:
		b = range_b[0]
		if range_a[0] == b:
			a = range_a[1]
		else:
			a = range_a[0]
	else:
		a = range_a[0]
		if range_b[0] == a:
			b = range_b[1]
		else:
			b = range_b[0]
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


import random

q_inputs = {}

def compare(range_a, b):
	for i in range(0, len(range_a)):
		if range_a[i] != b:
			a = range_a[i]
	return a

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = list(range(l1, r1+1))
	range_b = list(range(l2, r2+1))
	i = 0
	a = -1
	while a == -1:
		if range_a > range_b:
			b = range_b[i]
			a = compare(range_a, b)
			i = i + 1
		else:
			a = range_a[i]
			b = compare(range_b, a)
			i = i + 1
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


import random

q_inputs = {}

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = list(range(l1, r1))
	range_b = list(range(l2, r2))
	a = random.randint(l1, r1)
	b = random.randint(l2, r2)
	if a == b:
		if range_a > range_b:
			a = random.randint(l1, r1-1)
		else:
			b = random.randint(l2, r2-1)
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs[i] = inp.split()

for key in q_inputs:
	gen_int(q_inputs[key])


def compare(range_a, b):
	for i in range(0, len(range_a)):
		if range_a[i] != b:
			a = range_a[i]
	return a

def gen_int(inputs):
	l1 = int(inputs[0])
	r1 = int(inputs[1])
	l2 = int(inputs[2])
	r2 = int(inputs[3])
	range_a = range(l1, r1+1)
	range_b = range(l2, r2+1)
	i = 0
	a = -1
	while a == -1:
		if len(range_a) > len(range_b):
			b = range_b[i]
			a = compare(range_a, b)
			i = i + 1
		else:
			a = range_a[i]
			b = compare(range_b, a)
			i = i + 1
	print(a, b)

#flow of the program
q = int(input())

for i in range(0, q):
	inp = input()
	q_inputs = inp.split()
	gen_int(q_inputs)


n=int(input())
for i in range(n):
    L1,r1,L2,r2=map(int,input().split(' '))
    print(L1,L2)


n=int(input())
for i in range(n):
    L1,r1,L2,r2=map(int,input().split(' '))
    if L1!=L2:
        print(L1,L2)
    elif:
        r1!=r2:
            print(r1,r2)
    else:
        print(L1+1,L2)


n=int(input())
for i in range(n):
    L1,r1,L2,r2=map(int,input().split(' '))
    if L1!=L2:
        print(L1,L2)
    elif r1!=r2:
            print(r1,r2)
    else:
        print(L1+1,L2)


n=int(input())
for i in range(n):
    L1,r1,L2,r2=map(int,input().split(' '))
    print(L1,r1)


q = int(input())

for i in range(q):
  l1, r1, l2, r2 = map(int, input().split())

  if r1 != r2:
    print(l1, r2)
  elif l1 != l2:
    print(l1, l2)
  elif r1 != l2:
    print(r1, l2)
  elif r2 != l1:
    print(r2, l1)


q = int(input())

for i in range(q):
  l1, r1, l2, r2 = map(int, input().split())

  if l1 != r2:
    print(l1, r2)
  else:
    print(r1, l1)


q = int(input())

for i in range(q):
  l1, r1, l2, r2 = map(int, input().split())

  if l1 != r2:
    print(l1, r2)
  else:
    print(l1, r1)


q = int(input())

for i in range(q):
  l1, r1, l2, r2 = map(int, input().split())

  if l1 != r2:
    print(l1, r2)
  else:
    print(l2, r1)


i = 0

for _ in range(int(input())):

    l1,r1,l2,r2 = map(int, input().split())

    x = set()
    x.add(l1)
    x.add(l2)
    x.add(r1)
    x.add(r2)

    if len(x) == 4:
        print(l1,l2)

    elif len(x) == 3:

        if l1 == l2:
            print(r1,r2)
        elif l1 == r1 or l2 == r2 or r1 == r2 or l1 == r2 or l2 == r1:
            print(l1,l2)

    elif len(x) == 2:

        if l1 == l2 and r2 == r1:

            print(l1,r1)

        elif l1 == r1 and l2 == r2:

            print(l1,l2)

        elif l1 == r2 and l2 == r1:

            print(l1,l2)


i = 0

for _ in range(int(input())):

    l1,r1,l2,r2 = map(int, input().split())

    if l1 == l2 and r1 == r2:

        print(l1,r1)

    elif l1 == l2:

        print(r1,r2)

    elif r1 == r2:

        print(l1,l2)

    elif (l1 < l2 and l2 < r2 and r2 < r1) or (l2 < l1 and l1 < r1 and r1 < r2):

        print(l1,l2)

    elif (l1 <= l2 and l2 <= r1) or (l2 <= l1 and l1 <= r2):

        print(l1,r2)

    elif r1 <= l2:

        print(l1,r2)

    elif r2 <= l1:

        print(l2,r1)


i = 0

for _ in range(int(input())):

    l1,r1,l2,r2 = map(int, input().split())

    if l1 == l2 and r1 == r2:

        print(r1,l1)

    elif l1 == l2:

        print(r1,r2)

    elif r1 == r2:

        print(l1,l2)

    elif (l1 < l2 and l2 < r2 and r2 < r1) or (l2 < l1 and l1 < r1 and r1 < r2):

        print(l1,l2)

    elif (l1 <= l2 and l2 <= r1) or (l2 <= l1 and l1 <= r2):

        print(l1,r2)

    elif r1 <= l2:

        print(l1,r2)

    elif r2 <= l1:

        print(l2,r1)


n = int(input())
for i in range(n):
	l1,r1,l2,r2 = input().split()
	if l1!=l2:
		print(l1,l2)
	else:
		print(l1,r2)


t=int(input())
l1,r1,l2,r2=map(int,input().split())
if(l1!=l2):
    print(l1,l2)
else:
    print(l1,r2)


t=int(input())
l1,r1,l2,r2=map(int,input().split())
if(l1==l2):
    print(l1,r2)
else:
    print(l1,l2)


n = int(input())
for i in range(n):
	l1,r1,l2,r2 = input().split()
	if l1==l2:
		print(l1,r2)
	else:
		print(l1,l2)


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int INF=1e9;
const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (!m[u])
            if (e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, n + 1)FOR(j, n + 1)e[i][j].F = INF, e[i][j].S = -INF;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        e[v][u].F = min(i + 1, e[u][v].F);
        e[u][v].F = e[v][u].F;
        e[v][u].S = max(i + 1, e[u][v].S);
        e[u][v].S = e[v][u].S;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)
            if (!m[i]) {
//                cout<<"i "<<i<<endl;
                ans++, dfs(i);
            }
        cout<<ans<<endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn],mm=1;
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] ^= 1;
    for (auto u:adj[v])
        if (e[v][u].S > r || e[v][u].F < l)
            if (m[u] != mm)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        cin >> l >> r;
        rep(i, 1, n + 1)
            if (m[i]!=mm)
                ans++, dfs(i);
        mm^=1;
        cout << ans << "\n";
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int MAXn=500+10;
int n,mi,q,e[MAXn][MAXn],u,v,ans;
bool mark[MAXn][MAXn],m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v,int l,int r,int par){

    m[v]=1;
    mark[v][par]=1;
    mark[par][v]=1;
    for(auto u:adj[v]){
        if(!mark[v][u]){
            if(e[v][u]<l||e[v][u]>r){
                dfs(u,l,r,v);
            }
        }
    }
}
signed main(){

    cin>>n>>mi;
    FOR(i,mi){

        cin>>v>>u;
        adj[v].pb(u);
        adj[u].pb(v);
        e[v][u]=i+1;
        e[u][v]=i+1;
    }
    cin>>q;
    while(q--){

        int l,r;
        memset(mark,0,sizeof mark);
        memset(m,0,sizeof m);

        cin>>l>>r;
        rep(i,1,n+1)
            if(!m[i])
                dfs(i,l,r,0),ans++;
        vans.pb(ans);
        ans=0;
    }
    for(auto u:vans)cout<<u<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (!m[u])
            if(e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (e[v][u].S > r || e[v][u].F < l)
            if (!m[u])
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn],mm=1;
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] ^= 1;
    for (auto u:adj[v])
        if (m[u] != mm)
            if (e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        cin >> l >> r;
        rep(i, 1, n + 1)
            if (m[i]!=mm)
                ans++, dfs(i);
        mm^=1;
        cout << ans << "\n";
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int INF=1e9;
const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v){

    m[v]=1;
    for(auto u:adj[v])
        if(e[v][u].S>r||e[v][u].F<l)
            if (!m[u])
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, n + 1)FOR(j, n + 1)e[i][j].F = INF, e[i][j].S = -INF;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        e[v][u].F = min(i + 1, e[u][v].F);
        e[u][v].F = e[v][u].F;
        e[v][u].S = max(i + 1, e[u][v].S);
        e[u][v].S = e[v][u].S;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)
            if (!m[i]) {
//                cout<<"i "<<i<<endl;
                ans++, dfs(i);
            }
        cout<<ans<<endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (e[v][u].S > r || e[v][u].F < l)
            if (!m[u])
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long
#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define sim template < class c
#define ris return * this
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define Foreach(i, x) for (__typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back
#define SI size()
#define S second
#define F first
#define C clear()
#define pii pair<long long,long long>
#define B begin()
#define mp make_pair
#define E end()
#define I insert
#define piii pair<long long,pair<long long,long long> >
#define P push
#define T top()
#define PP pop()

const int INF=1e9;
const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];
vector<int> vans;

void dfs(int v){

    m[v]=1;
    for(auto u:adj[v])
        if(e[v][u].S>r||e[v][u].F<l)
            if (!m[u])
                dfs(u);
}
signed main() {

    cin >> n >> mi;
    FOR(i,n+1)FOR(j,n+1)e[i][j].F=INF,e[i][j].S=-INF;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        e[v][u].F=min(i+1,e[u][v].F);
        e[u][v].F=e[v][u].F;
        e[v][u].S=max(i+1,e[u][v].S);
        e[u][v].S=e[v][u].S;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)
            if (!m[i])
            {
//                cout<<"i "<<i<<endl;
                ans++,dfs(i);
            }
        vans.pb(ans);
        ans = 0;
    }
    for (auto u:vans)cout << u << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (!m[u])
            if(e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        e[u][v].F = e[v][u].F = min(i + 1,e[v][u].F);
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (!m[u])
            if(e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << endl;
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn];
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] = 1;
    for (auto u:adj[v])
        if (!m[u])
            if(e[v][u].S > r || e[v][u].F < l)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        memset(m, 0, sizeof m);
        cin >> l >> r;
        rep(i, 1, n + 1)if (!m[i])
                ans++, dfs(i);
        cout << ans << "\n";
        ans = 0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define rep(i,f,l) for(int i=f;i<l;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>

const int MAXn=500+10;
int n,mi,q,u,v,ans,l,r;
pii e[MAXn][MAXn];
bool m[MAXn],mm=1;
vector<int> adj[MAXn];

void dfs(int v) {

    m[v] ^= 1;
    for (auto u:adj[v])
        if ((e[v][u].S > r || e[v][u].F < l)&&m[u] != mm)
                dfs(u);
}
signed main() {

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> mi;
    FOR(i, mi) {

        cin >> v >> u;
        adj[v].pb(u);
        adj[u].pb(v);
        if (e[v][u].F == 0)
            e[u][v].F = e[v][u].F = i + 1;
        e[u][v].S = e[v][u].S = i + 1;
    }
    cin >> q;
    while (q--) {

        cin >> l >> r;
        rep(i, 1, n + 1)
            if (m[i]!=mm)
                ans++, dfs(i);
        cout << ans << "\n";
        mm^=1;
        ans = 0;
    }
    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans;
bool used[510];
vector<pair<int,int> > graph[510];

void dfs(int u){
	used[u] = 1;
	for(int i=0;i<graph[u].size();i++){
		if((graph[u][i].sc>=x && graph[u][i].sc<=y) || used[graph[u][i].fi]) continue;
		dfs(graph[u][i].fi);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&x,&y);
		graph[x].pb(mp(y, i));
		graph[y].pb(mp(x, i));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		ans=0;
		memset(used, 0, sizeof(used));
		for(int i=1;i<=n;i++){
			if(!used[i]){
				dfs(i);
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans;
bool used[510];
vector<pair<int,int> > graph[510];

void dfs(int u){
	used[u] = 1;
	for(int i=0;i<graph[u].size();i++){
		if((graph[u][i].sc>=x && graph[u][i].sc<=y) || used[graph[u][i].fi]) continue;
		dfs(graph[u][i].fi);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&x,&y);
		graph[x].pb(mp(y, i));
		graph[y].pb(mp(x, i));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		ans=0;
		for(int i=1;i<=n;i++) used[i] = 0;
		for(int i=1;i<=n;i++){
			if(!used[i]){
				dfs(i);
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans;
bool used[510];
vector<pair<int,int> > graph[510];

void dfs(int u){
	used[u] = 1;
	for(int i=0;i<graph[u].size();i++){
		if((graph[u][i].sc>=x && graph[u][i].sc<=y) || used[graph[u][i].fi]) continue;
		dfs(graph[u][i].fi);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&x,&y);
		graph[x].pb(mp(y, i));
		graph[y].pb(mp(x, i));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		ans=0;
		memset(used, 0, sizeof(used));
		for(int i=1;i<=n;i++){
			if(!used[i]){
				dfs(i);
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans,p[510],r[510];
bool used[510];

int findSet(int x){
	return p[x] == x ? x : p[x] = findSet(p[x]);
}

void merge(int x, int y){
	x = findSet(x);
	y = findSet(y);
	if(r[x]>=r[y]) p[y] = x, r[x]+=r[y];
	else p[x] = y, r[y]+=r[x];
}

vector<pair<int,int> > edge;

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		edge.pb(mp(x, y));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		for(int i=1;i<=n;i++){
			p[i] = i;
			r[i] = 1;
			used[i] = 0;
		}
		for(int i=0;i<m;i++){
			if(i==x){
				i = y;
				continue;
			}
			merge(edge[i].fi, edge[i].sc);
		}
		ans = 0;
		for(int i=1;i<=n;i++){
			if(!used[findSet(i)]) ans++;
			used[findSet(i)] = 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans,p[510],r[510];
bool used[510];

int findSet(int x){
	return p[x] == x ? x : p[x] = findSet(p[x]);
}

void merge(int x, int y){
	x = findSet(x);
	y = findSet(y);
	if(r[x]>=r[y]) p[y] = x, r[x]+=r[y];
	else p[x] = y, r[y]+=r[x];
}

vector<pair<int,int> > edge;

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d %d",&x,&y);
		edge.pb(mp(x, y));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		for(int i=1;i<=n;i++){
			p[i] = i;
			r[i] = 1;
			used[i] = 0;
		}
		for(int i=0;i<m;i++){
			if(i==x){
				i = y;
				continue;
			}
			merge(edge[i].fi, edge[i].sc);
		}
		ans = 0;
		for(int i=1;i<=n;i++){
			if(!used[findSet(i)]) ans++;
			used[findSet(i)] = 1;
		}
		printf("%d\n", ans);
	}
	return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
using namespace std;

int n,m,o,x,y,ans;
bool used[510];
vector<pair<int,int> > graph[510];

void dfs(int u){
	used[u] = 1;
	for(int i=0;i<graph[u].size();i++){
		if((graph[u][i].sc<x || graph[u][i].sc>y) && !used[graph[u][i].fi]) dfs(graph[u][i].fi);
	}
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&x,&y);
		graph[x].pb(mp(y, i));
		graph[y].pb(mp(x, i));
	}
	scanf("%d",&o);
	while(o--){
		scanf("%d %d",&x,&y);
		x--, y--;
		ans=0;
		for(int i=1;i<=n;i++) used[i] = 0;
		for(int i=1;i<=n;i++){
			if(!used[i]){
				dfs(i);
				ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e4+10;
int const M2=1e6+10;
int const M3=1e4+10;
int mod=1e9+7;
//int l[M],r[M];
vector<pii>adj[500+10];
bool mark[500+10];
pair<pii,int> cur[M];
int cnt=0;
bool now=0;
int ans[M];
int ii;
void dfs(int v)
{
    mark[v]=now%2;
   // cerr<<v<<" ";
    for(int i=0;i<adj[v].size();i++)
    {
       // int u=adj[v][i];
       // if(edg[v][i]>=l2 && edg[v][i]<=r2 && r2-l2>=200)
       // {
       //     i=lower_bound(adj[v].begin(),adj[v].end(),r2+1)-adj[v].begin();
      //  }
        if(mark[adj[v][i].F]==(now%2) || (cur[ii].F.F<=adj[v][i].S && adj[v][i].S<=cur[ii].F.S))
            continue;
        dfs(adj[v][i].F);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
        scanf("%d%d",&a,&b),adj[a].pb(mp(b,i)),adj[b].pb(mp(a,i));
    int q;
    cin>>q;
    for(int i=1;i<=q;i++)
        scanf("%d%d",&cur[i].F.F,&cur[i].F.S),cur[i].S=i;
     sort(cur+1,cur+q+1);
    //for(int i=1;i<=q;i++)
      //  l[i]=cur[i].F.F,r[i]=cur[i].F.S;
    now=1;
    for(ii=1;ii<=q;ii++){
   //     int l,r;
   // cerr<<ii<<" ";
        if(cur[ii].F.F==cur[ii-1].F.F && cur[ii].F.S==cur[ii-1].F.S)
        {
            ans[cur[ii].S]=cnt;
        }
        else{
            cnt=0;
            for(int i=1;i<=n;i++)
            {
                if(mark[i]!=(now%2))
                    dfs(i),cnt++;
            }
            ans[cur[ii].S]=cnt;
            now=1-now;
        }
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e4+10;
int const M2=1e6+10;
int const M3=1e4+10;
int mod=1e9+7;
//int l[M],r[M];
vector<pii>adj[500+10];
bool mark[500+10];
pair<pii,int> cur[M];
int cnt=0;
int ans[M];
int ii;
void dfs(int v)
{
    mark[v]=1;
    for(int i=0;i<adj[v].size();i++)
    {
       // int u=adj[v][i];
       // if(edg[v][i]>=l2 && edg[v][i]<=r2 && r2-l2>=200)
       // {
       //     i=lower_bound(adj[v].begin(),adj[v].end(),r2+1)-adj[v].begin();
      //  }
        if(mark[adj[v][i].F]==1 || (cur[ii].F.F<=adj[v][i].S && adj[v][i].S<=cur[ii].F.S))
            continue;
        dfs(adj[v][i].F);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
        scanf("%d%d",&a,&b),adj[a].pb(mp(b,i)),adj[b].pb(mp(a,i));
    int q;
    cin>>q;
    for(int i=1;i<=q;i++)
        scanf("%d%d",&cur[i].F.F,&cur[i].F.S),cur[i].S=i;
     sort(cur+1,cur+q+1);
    //for(int i=1;i<=q;i++)
      //  l[i]=cur[i].F.F,r[i]=cur[i].F.S;
    for(ii=1;ii<=q;ii++){
   //     int l,r;
        if(cur[ii].F.F==cur[ii-1].F.F && cur[ii].F.S==cur[ii-1].F.S)
        {
            ans[cur[ii].S]=cnt;
        }
        else{
            cnt=0;
            for(int i=1;i<=n;i++)
            {
                if(!mark[i])
                    dfs(i),cnt++;
            }
            memset(mark,0,sizeof mark);
            ans[cur[ii].S]=cnt;
        }
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e4+10;
int const M2=1e6+10;
int const M3=1e4+10;
int mod=1e9+7;
//int l[M],r[M];
vector<pii>adj[500+10];
bool mark[500+10];
int cnt=0;
bool now=1;
int l,r;
void dfs(int v)
{
    mark[v]=now%2;
    for(auto u:adj[v])
    {
        if(mark[u.F]==(now%2) || (l<=u.S && u.S<=r))
            continue;
        dfs(u.F);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
        scanf("%d%d",&a,&b),adj[a].pb(mp(b,i)),adj[b].pb(mp(a,i));
    int q;
    cin>>q;
    now=1;
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d",&l,&r);
        cnt=0;
        for(int j=1;j<=n;j++)
        {
            if(mark[j]!=i%2)
                dfs(j),cnt++;
        }
        printf("%d\n",cnt);
        now=1-now;
    }
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e4+10;
int mod=1e9+7;
int l[M],r[M];
vector<pii>adj[M];
bool mark[M3];
pair<pii,int> cur[M];
int cnt=0;
int ans[M];
int ii;
void dfs(int v)
{
    mark[v]=1;
    for(int i=0;i<adj[v].size();i++)
    {
       // int u=adj[v][i];
       // if(edg[v][i]>=l2 && edg[v][i]<=r2 && r2-l2>=200)
       // {
       //     i=lower_bound(adj[v].begin(),adj[v].end(),r2+1)-adj[v].begin();
      //  }
        if(mark[adj[v][i].F]==1 || (l[ii]<=adj[v][i].S && adj[v][i].S<=r[ii]))
            continue;
        dfs(adj[v][i].F);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
        scanf("%d%d",&a,&b),adj[a].pb(mp(b,i)),adj[b].pb(mp(a,i));
    int q;
    cin>>q;
    for(int i=1;i<=q;i++)
        scanf("%d%d",&cur[i].F.F,&cur[i].F.S),cur[i].S=i;
     sort(cur+1,cur+q+1);
    for(int i=1;i<=q;i++)
        l[i]=cur[i].F.F,r[i]=cur[i].F.S;
    for(ii=1;ii<=q;ii++){
   //     int l,r;
        if(l[ii]==l[ii-1] && r[ii]==r[ii-1])
        {
            ans[cur[ii].S]=cnt;
            continue;
        }
        cnt=0;
        for(int i=1;i<=n;i++)
        {
            if(!mark[i])
                dfs(i),cnt++;
        }
        memset(mark,0,sizeof mark);
        ans[cur[ii].S]=cnt;
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}


#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e4+10;
int const M2=1e6+10;
int const M3=1e4+10;
int mod=1e9+7;
//int l[M],r[M];
vector<pii>adj[500+10];
bool mark[500+10];
pair<pii,int> cur[M];
int cnt=0;
//l,r;
bool now=0;
int ans[M];
//int ii;
void dfs(int v,int l,int r)
{
    mark[v]=now%2;
    for(auto u:adj[v])
    {
        if((l>u.S || r<u.S) && mark[u.F]!=now%2)
            dfs(u.F,l,r);
    }
}
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
int main(){
	//ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n,m,a,b;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
        scanf("%d%d",&a,&b),adj[a].pb(mp(b,i)),adj[b].pb(mp(a,i));
    int q;
    cin>>q;
    for(int i=1;i<=q;i++)
        scanf("%d%d",&cur[i].F.F,&cur[i].F.S),cur[i].S=i;
     sort(cur+1,cur+q+1);
    now=1;
    for(int ii=1;ii<=q;ii++){
        if( cur[ii].F.S==cur[ii-1].F.S && cur[ii].F.F==cur[ii-1].F.F)
        {
            ans[cur[ii].S]=cnt;
        }
        else{
            cnt=0;
            for(int i=1;i<=n;i++)
            {
                if(mark[i]!=(now%2)){
                    dfs(i,cur[ii].F.F,cur[ii].F.S),cnt++;
                }
            }
            ans[cur[ii].S]=cnt;
            now=1-now;
        }
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}