import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Locale;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	private static final BigInteger mod = BigInteger.valueOf(10000000000L);
	private static final BigInteger two = BigInteger.valueOf(2);

	private void solve() throws IOException {
		for (int t = nextInt(); t > 0; t--) {
			int x1 = nextInt();
			int y1 = nextInt();
			int x2 = nextInt();
			int y2 = nextInt();

			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
			if (res.compareTo(mod) > 0) {
				print("...");
			}
			println(res.mod(mod));
		}
//		for (int t = 100000; t > 0; t--) {
//			int x1 = 708;
//			int y1 = 167897;
//			int x2 = 100025;
//			int y2 = 654654654;
//
//			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
//			if (res.compareTo(mod) > 0) {
//				print("...");
//			}
//			println(res.mod(mod));
//		}

	}

	private BigInteger f(long x, long y) {
		if (x == 0 || y == 0) {
			return BigInteger.ZERO;
		} else if (x == y) {
			BigInteger sq = BigInteger.valueOf(x * x);
			return sq.multiply(sq.add(BigInteger.ONE)).divide(two);
		} else if (x > y) {
			BigInteger res = f(y, y);
			long p = (y + 1) * (y + 1);
			long pp = (y + 2) * (y + 2);
			long d = pp - p;
			long k = x - y;

			BigInteger K = BigInteger.valueOf(k);

			BigInteger s = squresum(y + 1, x);

			BigInteger Y = BigInteger.valueOf(y);
			BigInteger Y1 = BigInteger.valueOf(y - 1);

			BigInteger t = s.multiply(two).subtract(Y1.multiply(K)).multiply(Y).divide(two);
			return res.add(t);
		} else {
			BigInteger res = f(x, x);
			long p = x * x + 1;
			long pp = (x + 1) * (x + 1) + 1;
			long d = pp - p;
			long k = y - x;

			BigInteger K = BigInteger.valueOf(k);
			BigInteger s = squresum(x, y - 1).add(K);

			BigInteger X = BigInteger.valueOf(x);
			BigInteger X1 = BigInteger.valueOf(x - 1);

			BigInteger t = s.multiply(two).add(X1.multiply(K)).multiply(X).divide(two);
			return res.add(t);
		}
	}

	private BigInteger squresum(long l, long r) {
		if (l == 1) {
			BigInteger n = BigInteger.valueOf(r);
			BigInteger n1 = BigInteger.valueOf(r + 1);
			BigInteger n2 = BigInteger.valueOf(r + r + 1);
			return n.multiply(n1).multiply(n2).divide(BigInteger.valueOf(6));
		} else {
			return squresum(1, r).subtract(squresum(1, l - 1));
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new E().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Locale;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	private static final BigInteger mod = BigInteger.valueOf(10000000000L);
	private static final BigInteger two = BigInteger.valueOf(2);

	private void solve() throws IOException {
		for (int t = nextInt(); t > 0; t--) {
			int x1 = nextInt();
			int y1 = nextInt();
			int x2 = nextInt();
			int y2 = nextInt();

			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
			if (res.compareTo(mod) > 0) {
				print("...");
			}
			String s = res.mod(mod).toString();
			while (s.length() < 10) {
				s = "0" + s;
			}
			println(s);
		}
//		for (int t = 100000; t > 0; t--) {
//			int x1 = 708;
//			int y1 = 167897;
//			int x2 = 100025;
//			int y2 = 654654654;
//
//			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
//			if (res.compareTo(mod) > 0) {
//				print("...");
//			}
//			println(res.mod(mod));
//		}

	}

	private BigInteger f(long x, long y) {
		if (x == 0 || y == 0) {
			return BigInteger.ZERO;
		} else if (x == y) {
			BigInteger sq = BigInteger.valueOf(x * x);
			return sq.multiply(sq.add(BigInteger.ONE)).divide(two);
		} else if (x > y) {
			BigInteger res = f(y, y);
			long p = (y + 1) * (y + 1);
			long pp = (y + 2) * (y + 2);
			long d = pp - p;
			long k = x - y;

			BigInteger K = BigInteger.valueOf(k);

			BigInteger s = squresum(y + 1, x);

			BigInteger Y = BigInteger.valueOf(y);
			BigInteger Y1 = BigInteger.valueOf(y - 1);

			BigInteger t = s.multiply(two).subtract(Y1.multiply(K)).multiply(Y).divide(two);
			return res.add(t);
		} else {
			BigInteger res = f(x, x);
			long p = x * x + 1;
			long pp = (x + 1) * (x + 1) + 1;
			long d = pp - p;
			long k = y - x;

			BigInteger K = BigInteger.valueOf(k);
			BigInteger s = squresum(x, y - 1).add(K);

			BigInteger X = BigInteger.valueOf(x);
			BigInteger X1 = BigInteger.valueOf(x - 1);

			BigInteger t = s.multiply(two).add(X1.multiply(K)).multiply(X).divide(two);
			return res.add(t);
		}
	}

	private BigInteger squresum(long l, long r) {
		if (l == 1) {
			BigInteger n = BigInteger.valueOf(r);
			BigInteger n1 = BigInteger.valueOf(r + 1);
			BigInteger n2 = BigInteger.valueOf(r + r + 1);
			return n.multiply(n1).multiply(n2).divide(BigInteger.valueOf(6));
		} else {
			return squresum(1, r).subtract(squresum(1, l - 1));
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new E().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Locale;
import java.util.Stack;
import java.util.StringTokenizer;

public class E {

	private static final BigInteger mod = BigInteger.valueOf(10000000000L);
	private static final BigInteger two = BigInteger.valueOf(2);

	private void solve() throws IOException {
		for (int t = nextInt(); t > 0; t--) {
			int x1 = nextInt();
			int y1 = nextInt();
			int x2 = nextInt();
			int y2 = nextInt();

			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
			if (res.compareTo(mod) > 0) {
				print("...");
				String s = res.mod(mod).toString();
				while (s.length() < 10) {
					s = "0" + s;
				}
				println(s);
			} else {
				println(res);
			}
		}
//		for (int t = 100000; t > 0; t--) {
//			int x1 = 708;
//			int y1 = 167897;
//			int x2 = 100025;
//			int y2 = 654654654;
//
//			BigInteger res = f(x2, y2).subtract(f(x2, y1 - 1)).subtract(f(x1 - 1, y2)).add(f(x1 - 1, y1 - 1));
//			if (res.compareTo(mod) > 0) {
//				print("...");
//			}
//			println(res.mod(mod));
//		}

	}

	private BigInteger f(long x, long y) {
		if (x == 0 || y == 0) {
			return BigInteger.ZERO;
		} else if (x == y) {
			BigInteger sq = BigInteger.valueOf(x * x);
			return sq.multiply(sq.add(BigInteger.ONE)).divide(two);
		} else if (x > y) {
			BigInteger res = f(y, y);
			long p = (y + 1) * (y + 1);
			long pp = (y + 2) * (y + 2);
			long d = pp - p;
			long k = x - y;

			BigInteger K = BigInteger.valueOf(k);

			BigInteger s = squresum(y + 1, x);

			BigInteger Y = BigInteger.valueOf(y);
			BigInteger Y1 = BigInteger.valueOf(y - 1);

			BigInteger t = s.multiply(two).subtract(Y1.multiply(K)).multiply(Y).divide(two);
			return res.add(t);
		} else {
			BigInteger res = f(x, x);
			long p = x * x + 1;
			long pp = (x + 1) * (x + 1) + 1;
			long d = pp - p;
			long k = y - x;

			BigInteger K = BigInteger.valueOf(k);
			BigInteger s = squresum(x, y - 1).add(K);

			BigInteger X = BigInteger.valueOf(x);
			BigInteger X1 = BigInteger.valueOf(x - 1);

			BigInteger t = s.multiply(two).add(X1.multiply(K)).multiply(X).divide(two);
			return res.add(t);
		}
	}

	private BigInteger squresum(long l, long r) {
		if (l == 1) {
			BigInteger n = BigInteger.valueOf(r);
			BigInteger n1 = BigInteger.valueOf(r + 1);
			BigInteger n2 = BigInteger.valueOf(r + r + 1);
			return n.multiply(n1).multiply(n2).divide(BigInteger.valueOf(6));
		} else {
			return squresum(1, r).subtract(squresum(1, l - 1));
		}
	}

	private String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	private int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	private double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}

	private long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	private void print(Object o) {
		writer.print(o);
	}

	private void println(Object o) {
		writer.println(o);
	}

	private void printf(String format, Object... o) {
		writer.printf(format, o);
	}

	public static void main(String[] args) {
		long time = System.currentTimeMillis();
		Locale.setDefault(Locale.US);
		new E().run();
		System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time));
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	private void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(13);
		}
	}
}


import java.io.*;
import java.util.*;
import java.math.*;

public class CF152E {
    public static void main(String[] args) throws IOException {
        new CF152E().run();
    }

    BigInteger solve2(int k, int n) {
        if (n == 0) {
            return BigInteger.ZERO;
        }
        BigInteger res = BigInteger.valueOf(k).multiply(BigInteger.valueOf(n - 1)).multiply(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(2 * n - 1));
        res = res.divide(BigInteger.valueOf(6));
        BigInteger res2 = BigInteger.valueOf(n).multiply(BigInteger.valueOf(k)).multiply(BigInteger.valueOf(k + 1));
        res2 = res2.divide(BigInteger.valueOf(2));
        return res.add(res2);
    }

    BigInteger solve2(int n, int k1, int k2) {
        BigInteger first = solve2(n, k2);
        BigInteger second = solve2(n, k1 - 1);
        return first.subtract(second);
    }

    BigInteger solve3(int n, int k) {
        if (n == 0) {
            return BigInteger.ZERO;
        }
        ++n;
        BigInteger res1 = BigInteger.valueOf(n - 1).multiply(BigInteger.valueOf(n)).multiply(BigInteger.valueOf(2 * n - 1)).divide(BigInteger.valueOf(6));
        res1 = res1.multiply(BigInteger.valueOf(k));
        BigInteger res2 = BigInteger.valueOf(n).multiply(BigInteger.valueOf(k - 1)).multiply(BigInteger.valueOf(k)).divide(BigInteger.valueOf(2));
        res1 = res1.subtract(res2);
        BigInteger nw = BigInteger.valueOf(k).multiply(BigInteger.valueOf(k - 1)).divide(BigInteger.valueOf(2));
        return res1.add(nw);
    }

    BigInteger solve3(int n1, int n2, int k) {
        BigInteger first = solve3(n2, k);
        BigInteger second = solve3(n1 - 1, k);
        return first.subtract(second);
    }

    BigInteger arithmSq(int n) {
        BigInteger rn = BigInteger.valueOf(n).pow(2);
        return rn.multiply(rn.add(BigInteger.ONE)).divide(BigInteger.valueOf(2));
    }

    BigInteger solve(int n, int k) {
        BigInteger result = BigInteger.ZERO;
        if (n <= k) {
            result = result.add(arithmSq(n));
            result = result.add(solve2(n, n + 1, k));
        } else {
            result = result.add(arithmSq(k));
            result = result.add(solve3(k + 1, n, k));
        }
        return result;
    }

    StreamTokenizer in;

    int nextInt() throws IOException {
        in.nextToken();
        return (int)in.nval;
    }

    void run() throws IOException {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        int n = nextInt();
        for (int test = 0; test < n; ++test) {
            int a = nextInt(), b = nextInt(), c = nextInt(), d = nextInt();
            BigInteger res1 = solve(a - 1, b - 1);
            BigInteger res2 = solve(c, d);
            BigInteger res3 = solve(a - 1, d);
            BigInteger res4 = solve(c, b - 1);
            BigInteger ans = res2.subtract(res3).subtract(res4).add(res1);
            if (ans.compareTo(BigInteger.valueOf(10000000000L)) != -1) {
                System.out.print("...");
                String res = (ans.remainder(BigInteger.valueOf(10000000000L))).toString();
                for (int i = 0; i < 10 - (int)res.length(); ++i) {
                    System.out.print(0);
                }
                System.out.println(res);
            } else {
                System.out.println(ans);
            }
        }
    }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public static void main ( String args[] ) throws Exception {
		(new P9()).solve();
	}
}

class P9
{
	BufferedReader in;

	final BigInteger ZERO = BigInteger.ZERO;
	final BigInteger ONE = BigInteger.ONE;
	final BigInteger TWO = bigInt ( "2" );
	final BigInteger SIX = bigInt ( "6" );

	BigInteger bigInt ( String s ) { return new BigInteger ( s ); }

	BigInteger acum ( BigInteger n ) {
		return ( n.multiply ( n.add(ONE) ) ).divide ( TWO );
	}

	BigInteger acumSq ( BigInteger n ) {
		BigInteger r = n.multiply ( n.add ( ONE ) );
		r = r.multiply ( TWO.multiply(n).add ( ONE ) );
		return r.divide ( SIX );
	}

	BigInteger count ( int x, int y )
	{
		if ( x < 0 || y < 0 )
			return ZERO;

		BigInteger sqMax = bigInt ( "" + (Math.min(x,y)+1) );
		sqMax = sqMax.multiply(sqMax);

		BigInteger ans = acum ( sqMax );

		if ( x < y )
		{
			BigInteger fr = bigInt ( "" + (x+1) );
			BigInteger to = bigInt ( "" + y );
			BigInteger n = bigInt ( "" + (x+1) );
			BigInteger m = to.subtract(fr).add(ONE);

			BigInteger sqSum = acumSq ( to );
			sqSum = sqSum.subtract ( acumSq ( fr.subtract(ONE) ) );

			BigInteger toAdd = sqSum.multiply ( n );
			toAdd = toAdd.add ( m.multiply ( acum ( n ) ) );

			ans = ans.add ( toAdd );
		}
		else if ( x > y )
		{
			BigInteger fr = bigInt ( "" + (y+1) );
			BigInteger to = bigInt ( "" + x );
			BigInteger n = bigInt ( "" + (y+1) );
			BigInteger m = to.subtract(fr).add(ONE);

			BigInteger sqSum = acumSq (to.add(ONE));
			sqSum = sqSum.subtract ( acumSq(fr) );

			BigInteger toAdd = sqSum.multiply ( n );
			toAdd = toAdd.subtract ( m.multiply ( acum ( n.subtract(ONE) ) ) );

			ans = ans.add ( toAdd );
		}

		return ans;
	}

	void solveCase ( ) throws Exception
	{
		StringTokenizer st;
		st = new StringTokenizer ( in.readLine() );

		int sx = toInt ( st.nextToken() ) - 1;
		int sy = toInt ( st.nextToken() ) - 1;
		int bx = toInt ( st.nextToken() ) - 1;
		int by = toInt ( st.nextToken() ) - 1;

		BigInteger ans = count ( bx, by );
		ans = ans.subtract ( count ( bx, sy-1 ) );
		ans = ans.subtract ( count ( sx-1, by ) );
		ans = ans.add ( count ( sx-1, sy-1 ) );

		String s = ans.toString();
		if ( s.length() <= 10 ) println ( s );
		else println ( "..." + s.substring ( s.length()-10, s.length() ) );
	}

	public void solve ( ) throws Exception
	{
		in = new BufferedReader ( new InputStreamReader ( System.in ) );
		int nCases = toInt ( in.readLine() );
		while ( (nCases--) > 0 )
			solveCase ( );
	}

	public int toInt ( String s ) { return Integer.parseInt ( s ); }
	public void println ( Object o ) { System.out.println ( o ); }
	public void print ( Object o ) { System.out.print ( o ); }
	public void println ( ) { System.out.println ( ); }
}


import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	public static void main ( String args[] ) throws Exception {
		(new P9()).solve();
	}
}

class P9
{
	BufferedReader in;

	final BigInteger ZERO = BigInteger.ZERO;
	final BigInteger ONE = BigInteger.ONE;
	final BigInteger TWO = bigInt ( "2" );
	final BigInteger SIX = bigInt ( "6" );

	BigInteger bigInt ( String s ) { return new BigInteger ( s ); }

	BigInteger acum ( BigInteger n ) {
		return ( n.multiply ( n.add(ONE) ) ).divide ( TWO );
	}

	BigInteger acumSq ( BigInteger n ) {
		BigInteger r = n.multiply ( n.add ( ONE ) );
		r = r.multiply ( TWO.multiply(n).add ( ONE ) );
		return r.divide ( SIX );
	}

	BigInteger count ( int x, int y )
	{
		if ( x < 0 || y < 0 )
			return ZERO;

		BigInteger sqMax = bigInt ( "" + (Math.min(x,y)+1) );
		sqMax = sqMax.multiply(sqMax);

		BigInteger ans = acum ( sqMax );

		if ( x < y )
		{
			BigInteger fr = bigInt ( "" + (x+1) );
			BigInteger to = bigInt ( "" + y );
			BigInteger n = bigInt ( "" + (x+1) );
			BigInteger m = to.subtract(fr).add(ONE);

			BigInteger sqSum = acumSq ( to );
			sqSum = sqSum.subtract ( acumSq ( fr.subtract(ONE) ) );

			BigInteger toAdd = sqSum.multiply ( n );
			toAdd = toAdd.add ( m.multiply ( acum ( n ) ) );

			ans = ans.add ( toAdd );
		}
		else if ( x > y )
		{
			BigInteger fr = bigInt ( "" + (y+1) );
			BigInteger to = bigInt ( "" + x );
			BigInteger n = bigInt ( "" + (y+1) );
			BigInteger m = to.subtract(fr).add(ONE);

			BigInteger sqSum = acumSq (to.add(ONE));
			sqSum = sqSum.subtract ( acumSq(fr) );

			BigInteger toAdd = sqSum.multiply ( n );
			toAdd = toAdd.subtract ( m.multiply ( acum ( n.subtract(ONE) ) ) );

			ans = ans.add ( toAdd );
		}

		return ans;
	}

	void solveCase ( ) throws Exception
	{
		StringTokenizer st;
		st = new StringTokenizer ( in.readLine() );

		int sx = toInt ( st.nextToken() ) - 1;
		int sy = toInt ( st.nextToken() ) - 1;
		int bx = toInt ( st.nextToken() ) - 1;
		int by = toInt ( st.nextToken() ) - 1;

		BigInteger ans = count ( bx, by );
		ans = ans.subtract ( count ( bx, sy-1 ) );
		ans = ans.subtract ( count ( sx-1, by ) );
		ans = ans.add ( count ( sx-1, sy-1 ) );

		String s = ans.toString();
		if ( s.length() < 10 ) println ( s );
		else println ( "..." + s.substring ( s.length()-10, s.length() ) );
	}

	public void solve ( ) throws Exception
	{
		in = new BufferedReader ( new InputStreamReader ( System.in ) );
		int nCases = toInt ( in.readLine() );
		while ( (nCases--) > 0 )
			solveCase ( );
	}

	public int toInt ( String s ) { return Integer.parseInt ( s ); }
	public void println ( Object o ) { System.out.println ( o ); }
	public void print ( Object o ) { System.out.print ( o ); }
	public void println ( ) { System.out.println ( ); }
}


#include<cstdio>
#include<algorithm>

#define mo 10000000000ll

using namespace std;

int t,x1,y1,x2,y2;

long long Mul(long long x,long long m)
{
    long long nowans=0;
    while(m)
    {
        if(m&1)
        {
            nowans=nowans+x;
            if(nowans>=mo)nowans-=mo;
        }
        x=x+x;
        if(x>=mo)x-=mo;
        m>>=1;
    }
    return nowans;
}

long long getn2(long long x)
{
    int flag2=0,flag3=0;
    long long X=x;
    if(X%2==0)X/=2,flag2=1;
    if(X%3==0)X/=3,flag3=1;
    long long nowans=X;
    X=x+1;
    if(!flag2&&X%2==0)flag2=1,X/=2;
    if(!flag3&&X%3==0)flag3=1,X/=3;
    nowans=Mul(nowans,X);
    X=2*x+1;
    if(!flag2)X/=2;
    if(!flag3)X/=3;
    nowans=Mul(nowans,X);
    return nowans;
}

long long calc(long long x,long long y)
{
    if(!x||!y)return 0;
    long long X=min(x,y),nowans,nowsum;
    if(X*X%2==0)nowans=X*X/2,nowans%=mo,nowans=Mul(nowans,(1+X*X)%mo);
    else nowans=(1+X*X)/2,nowans%=mo,nowans=Mul(nowans,X*X%mo);
    if(x>X)
    {
        nowsum=getn2(x)-getn2(X);
        if(nowsum<0)nowsum+=mo;
        nowans+=Mul(nowsum,y);
        if(nowans>=mo)nowans-=mo;
        if(y%2==0)nowsum=y/2,nowsum=Mul(nowsum,y-1);
        else nowsum=(y-1)/2,nowsum=Mul(nowsum,y);
        nowans-=Mul(nowsum,(x-X));
        if(nowans<0)nowans+=mo;
    }
    if(y>X)
    {
        nowsum=getn2(y-1)-getn2(X-1)+(y-X);
        if(nowsum<0)nowsum+=mo;
        if(nowsum>=mo)nowsum-=mo;
        nowans+=Mul(X,nowsum);
        if(nowans>=mo)nowans-=mo;
        if(x%2==0)nowsum=x/2,nowsum=Mul(nowsum,x-1);
        else nowsum=(x-1)/2,nowsum=Mul(nowsum,x);
        nowans+=Mul((y-X),nowsum);
        if(nowans>=mo)nowans-=mo;
    }
    return nowans;
}

long double getn2(long double x)
{
    return (2*x*x*x+3*x*x+x)/6;
}

long double calc_(long double x,long double y)
{
    long double X=min(x,y),nowans=(1+X*X)*X*X/2,nowsum;
    if(x>X)
    {
        nowsum=getn2(x)-getn2(X);
        nowans+=nowsum*y;
        nowsum=(1+y-1)*(y-1)/2;
        nowans-=nowsum*(x-X);
    }
    if(y>X)
    {
        nowsum=getn2(y-1)-getn2(X-1)+(y-X);
        nowans+=X*nowsum;
        nowsum=(1+x-1)*(x-1)/2;
        nowans+=(y-X)*nowsum;
    }
    return nowans;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
        long long nowans=(calc(x2,y2)-calc(x1-1,y2)+mo-calc(x2,y1-1)+mo+calc(x1-1,y1-1))%mo;
        if((calc_(x2,y2)-calc_(x1-1,y2)-calc_(x2,y1-1)+calc_(x1-1,y1-1))>=1e10)printf("...%.10I64d\n",nowans);
        else printf("%I64d\n",nowans);
    }
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const LL maxn=100000;
struct data
{
       LL bit[maxbits*2+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits; ++i)
         for (int j=1; j<=maxbits; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
//LL sumsqu(LL x) {return x*(x+1)*(2*x+1)/6;}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
/*   LL k;
   if (x==y)
      return (x*x+1)*x*x/2;
      else if (x>y)
           {
              k=x-y;
              return (y*y+1)*y*y/2-(y-1)*y/2*k+y*(sumsqu(y+k)-sumsqu(y));
           }
           else
           {
              k=y-x;
              return (x*x+1)*x*x/2+(1+x)*x/2*k+x*(sumsqu(x+k-1)-sumsqu(x-1));
           }*/
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=maxbits-i; ++j) printf("0");
     if (k!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i, j, k;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>2)
     {
        printf("...");
        print_zero(a.bit[2]);
        print_zero(a.bit[1]);
        printf("\n");
     }
     else
     {
          printf("%I64d",a.bit[i]);
          for (j=i-1; j>0; --j)
              print_zero(a.bit[j]);
          printf("\n");
     }
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const int maxn=1000000000;
struct data
{
       LL bit[maxbits+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits/2; ++i)
         for (int j=1; j<=maxbits/2; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=9-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>1)
     {
        if ((a.bit[i]/10==0) && (i==2))
           {
             if (a.bit[2]%10!=0)
             {
                i=a.bit[2]%10;
                printf("%d",i);
                print(a.bit[1]);
             }
             else printf("%I64d\n",a.bit[1]);
           }
           else
           {
                printf("...");
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
           }
     }
     else  printf("%I64d\n",a.bit[1]);
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const int maxn=1000000000;
struct data
{
       LL bit[maxbits+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits/2+1; ++i)
         for (int j=1; j<=maxbits/2+1; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=9-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>1)
     {
        if ((a.bit[i]/10==0) && (i==2))
           {
             if (a.bit[2]%10!=0)
             {
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
             }
             else printf("%I64d\n",a.bit[1]);
           }
           else
           {
                printf("...");
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
           }
     }
     else  printf("%I64d\n",a.bit[1]);
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=3;
const LL maxn=100000;
struct data
{
       LL bit[maxbits*2+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits; ++i)
         for (int j=1; j<=maxbits; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
//LL sumsqu(LL x) {return x*(x+1)*(2*x+1)/6;}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
/*   LL k;
   if (x==y)
      return (x*x+1)*x*x/2;
      else if (x>y)
           {
              k=x-y;
              return (y*y+1)*y*y/2-(y-1)*y/2*k+y*(sumsqu(y+k)-sumsqu(y));
           }
           else
           {
              k=y-x;
              return (x*x+1)*x*x/2+(1+x)*x/2*k+x*(sumsqu(x+k-1)-sumsqu(x-1));
           }*/
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=5-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i, j, k;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>2)
     {
        printf("...");
        print_zero(a.bit[2]);
        print_zero(a.bit[1]);
        printf("\n");
     }
     else
     {
          printf("%I64d",a.bit[i]);
          for (j=i-1; j>0; --j)
              print_zero(a.bit[j]);
          printf("\n");
     }
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=4;
const int maxn=1000000000;
struct data
{
       LL bit[maxbits+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits/2; ++i)
         for (int j=1; j<=maxbits/2; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=9-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>1)
     {
        if ((a.bit[i]/10==0) && (i==2))
           {
             if (a.bit[2]%10!=0)
             {
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
             }
             else printf("%I64d\n",a.bit[1]);
           }
           else
           {
                printf("...");
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
           }
     }
     else  printf("%I64d\n",a.bit[1]);
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const LL maxn=100000;
struct data
{
       LL bit[maxbits*2+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits; ++i)
         for (int j=1; j<=maxbits; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
//LL sumsqu(LL x) {return x*(x+1)*(2*x+1)/6;}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
/*   LL k;
   if (x==y)
      return (x*x+1)*x*x/2;
      else if (x>y)
           {
              k=x-y;
              return (y*y+1)*y*y/2-(y-1)*y/2*k+y*(sumsqu(y+k)-sumsqu(y));
           }
           else
           {
              k=y-x;
              return (x*x+1)*x*x/2+(1+x)*x/2*k+x*(sumsqu(x+k-1)-sumsqu(x-1));
           }*/
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=maxbits-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i, j, k;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>2)
     {
        printf("...");
        print_zero(a.bit[2]);
        print_zero(a.bit[1]);
        printf("\n");
     }
     else
     {
          printf("%I64d",a.bit[i]);
          for (j=i-1; j>0; --j)
              print_zero(a.bit[j]);
          printf("\n");
     }
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const int maxn=1000000000;
struct data
{
       LL bit[maxbits+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits/2; ++i)
         for (int j=1; j<=maxbits/2; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=9-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>1)
     {
        if ((a.bit[i]/10==0) && (i==2))
           printf("%I64d\n",a.bit[1]);
           else
           {
                printf("...");
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
           }
     }
     else  printf("%I64d\n",a.bit[1]);
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
const int maxbits=5;
const int maxn=1000000000;
struct data
{
       LL bit[maxbits+1];
};

void mul(data a, data b, data &c)
{
     data t;
     memset(t.bit, 0, sizeof(t.bit));
     for (int i=1; i<=maxbits/2; ++i)
         for (int j=1; j<=maxbits/2; ++j)
         {
             t.bit[i+j-1]+=a.bit[i]*b.bit[j];
             t.bit[i+j]+=t.bit[i+j-1]/maxn;
             t.bit[i+j-1]%=maxn;
         }
     c=t;
}
void add(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]+b.bit[i]+g;
         g=c.bit[i]/maxn;
         c.bit[i]%=maxn;
     }
}
void del(data a, data b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=1; i<=maxbits; ++i)
     {
         c.bit[i]=a.bit[i]-b.bit[i]+g;
         if (c.bit[i]<0)
         {
            c.bit[i]+=maxn;
            g=-1;
         }
         else g=0;
     }
}
void div(data a, LL b, data &c)
{
     LL g=0;
     memset(c.bit, 0, sizeof(c.bit));
     for (int i=maxbits; i>=1; --i)
     {
         g=g*maxn+a.bit[i];
         c.bit[i]=g/b;
         g=g%b;
     }
}
void cha(LL a, data &b)
{
     memset(b.bit, 0 ,sizeof(b.bit));
     b.bit[2]=a/maxn;
     b.bit[1]=a%maxn;
}
void sumsqu(LL x, data &a)
{
     data X, T, temp, temp2, temp3;
     memset(T.bit, 0, sizeof(T.bit));
     T.bit[1]=1;
     cha(x, X);

     add(X, T, temp);
     add(temp, X, temp2);
     mul(temp, temp2, temp3);
     mul(X, temp3, temp);
     div(temp, 6, temp);
     a=temp;
}
void g(LL x, LL y, data &a)
{
     data X, Y, K, temp, temp2, fir, sec, thir;
     LL k;
     cha(x, X);
     cha(y, Y);
     if (x==y)
     {
        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);
        a=fir;
     }
     else if (x>y)
     {
        k=x-y;
        cha(k, K);

        mul(Y, Y, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(Y, Y, temp);
        del(temp, Y, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(y+k, temp);
        sumsqu(y, temp2);
        del(temp, temp2, temp);
        mul(Y, temp, thir);

        del(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
     else
     {
        k=y-x;
        cha(k, K);

        mul(X, X, temp);
        mul(temp, temp, temp2);
        add(temp, temp2, temp);
        div(temp, 2, fir);

        mul(X, X, temp);
        add(X, temp, temp2);
        div(temp2, 2, temp2);
        mul(temp2, K, sec);

        sumsqu(x+k-1, temp);
        sumsqu(x-1, temp2);
        del(temp, temp2, temp);
        mul(X, temp, thir);

        add(fir, sec, temp);
        add(temp, thir, temp);
        a=temp;
     }
}
void print_zero(LL a)
{
     int i=0, j;
     LL k=a;
     while (k!=0) {++i; k/=10;}
     for (j=1; j<=9-i; ++j) printf("0");
     if (a!=0)
        printf("%I64d",a);
}
void print(data a)
{
     int i;
     for (i=maxbits; i>0; --i)
         if (a.bit[i]!=0) break;
     if (i>1)
     {
        if ((a.bit[i]/10==0) && (i==2))
           {
             if (a.bit[2]%10!=0)
             {
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
             }
             else printf("%I64d\n",a.bit[1]);
           }
           else
           {
                printf("...");
                i=a.bit[2]%10;
                printf("%d",i);
                print_zero(a.bit[1]);
                printf("\n");
           }
     }
     else  printf("%I64d\n",a.bit[1]);
}
void work()
{
     LL x1, x2, y1, y2;
     scanf("%I64d %I64d %I64d %I64d",&x1, &y1, &x2, &y2);
     --x1; --y1;
     data a1, a2, a3, a4;
     g(x2, y2, a1);
     g(x1, y1, a2);
     g(x2, y1, a3);
     g(x1, y2, a4);
     add(a1, a2, a1);
     del(a1, a3, a1);
     del(a1, a4, a1);
     print(a1);
}
int main()
{

    int test, i;
    scanf("%d",&test);
    for (i=1; i<=test; ++i)
        work();
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#define h 200005
using namespace std;
vector < pair<unsigned long long int,unsigned long long int> > V[h+5];
unsigned long long int n,m,nra,nrb,mxb,mxa,k,ka,kb,x,i,j,a,b,ind,Kappa1[h],Kappa2[h];
int main()
{
  //  freopen("a.in","r",stdin);
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>x;
        k=x%h;
        for (j=0;j<V[k].size();j++)
        {
            if (V[k][j].first==x)
            {
                V[k][j].second++;
                j=V[k].size()+5;
            }
        }
        if (j==V[k].size())
        {
            V[k].push_back(make_pair(x,1));
        }
    }
    cin>>m;
    for (i=0;i<m;i++)
    {
        cin>>Kappa1[i];
    }
    for (i=0;i<m;i++)
    {
        cin>>Kappa2[i];
    }
    for (i=0;i<m;i++)
    {
        a=Kappa1[i];
        b=Kappa2[i];
        ka=a%h;
        kb=b%h;
        nra=0;
        nrb=0;
        for (j=0;j<V[ka].size();j++)
        {
            if (V[ka][j].first==a)
            {
                nra+=V[ka][j].second;
               // j=V[ka].size()+5;
            }
        }
        for (j=0;j<V[kb].size();j++)
        {
            if (V[kb][j].first==b)
            {
                nrb+=V[kb][j].second;
              //  j=V[kb].size()+5;
            }
        }
        if (nra>mxa)
        {
            mxa=nra;
            mxb=nrb;
            ind=i;
        }
        else if (nra==mxa&&nrb>mxb)
        {
            ind=i;
            mxb=nrb;
        }
    }
    //cout<<mxa<<" "<<mxb<<" ";
    cout<<ind+1;
}


#include <iostream>
#include <cstdio>
#include <vector>
#define h 200005
using namespace std;
vector < pair<unsigned long long int,unsigned long long int> > V[h+5];
unsigned long long int n,m,nra,nrb,mxb,mxa,k,ka,kb,x,i,j,a,b,ind,Kappa1[h],Kappa2[h];
int main()
{
  //  freopen("a.in","r",stdin);
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>x;
        k=x%h;
        for (j=0;j<V[k].size();j++)
        {
            if (V[k][j].first==x)
            {
                V[k][j].second++;
                j=V[k].size()+5;
            }
        }
        if (j==V[k].size())
        {
            V[k].push_back(make_pair(x,1));
        }
    }
    cin>>m;
    for (i=0;i<m;i++)
    {
        cin>>Kappa1[i]>>Kappa2[i];
    }
    for (i=0;i<m;i++)
    {
        a=Kappa1[i];
        b=Kappa2[i];
        ka=a%h;
        kb=b%h;
        nra=0;
        nrb=0;
        for (j=0;j<V[ka].size();j++)
        {
            if (V[ka][j].first==a)
            {
                nra+=V[ka][j].second;
               // j=V[ka].size()+5;
            }
        }
        for (j=0;j<V[kb].size();j++)
        {
            if (V[kb][j].first==b)
            {
                nrb+=V[kb][j].second;
              //  j=V[kb].size()+5;
            }
        }
        if (nra>mxa)
        {
            mxa=nra;
            mxb=nrb;
            ind=i;
        }
        else if (nra==mxa&&nrb>mxb)
        {
            ind=i;
            mxb=nrb;
        }
    }
    //cout<<mxa<<" "<<mxb<<" ";
    cout<<ind+1;
}


#include <iostream>
#include <cstdio>
#include <vector>
#define h 200005
using namespace std;
vector < pair<unsigned long long int,unsigned long long int> > V[h+5];
unsigned long long int n,m,nra,nrb,mxb,mxa,k,ka,kb,x,i,j,a,b,ind;
int main()
{
  //  freopen("a.in","r",stdin);
    cin>>n;
    for (i=0;i<n;i++)
    {
        cin>>x;
        k=x%h;
        for (j=0;j<V[k].size();j++)
        {
            if (V[k][j].first==x)
            {
                V[k][j].second++;
                j=V[k].size()+5;
            }
        }
        if (j==V[k].size())
        {
            V[k].push_back(make_pair(x,1));
        }
    }
    cin>>m;
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        ka=a%h;
        kb=b%h;
        nra=0;
        nrb=0;
        for (j=0;j<V[ka].size();j++)
        {
            if (V[ka][j].first==a)
            {
                nra+=V[ka][j].second;
                j=V[ka].size()+5;
            }
        }
        for (j=0;j<V[kb].size();j++)
        {
            if (V[kb][j].first==b)
            {
                nrb+=V[kb][j].second;
                j=V[kb].size()+5;
            }
        }
        if (nra>mxa)
        {
            mxa=nra;
            mxb=nrb;
            ind=i;
        }
        else if (nra==mxa&&nrb>mxb)
        {
            ind=i;
            mxb=nrb;
        }
    }
    //cout<<mxa<<" "<<mxb<<" ";
    cout<<ind+1;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
    int n;
    scanf(" %d", &n);
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) scanf(" %d", y + i);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      cin >> tmp;
      cnt[tmp]++;
    }
    int m;
    cin >> m;
    vector<int> x(m), y(m);
    REP (i, m) cin >> x[i];
    REP (i, m) cin >> y[i];

    tuple<int, int, int> ret = {-1, -1, 0};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], cnt[y[i]], i});
    }

    cout << get<2>(ret)+1 << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
  tuple<int, int, int> tt;
  tt={1,2,3};

    int n;
    scanf(" %d", &n);
    map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) scanf(" %d", y + i);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
    int n;
    scanf(" %d", &n);
    map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) scanf(" %d", y + i);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      cin >> tmp;
      cnt[tmp]++;
    }
    int m;
    cin >> m;
    vector<int> x(m), y(m);
    REP (i, m) cin >> x[i];
    REP (i, m) cin >> y[i];

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    cout << ret.second.second+1 << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

int x[200000];
int y[200000];
int main() {
  int n;
  scanf(" %d", &n);
  map<int, int> cnt;
  REP (i, n) {
    int tmp;
    scanf(" %d", &tmp);
    cnt[tmp]++;
  }
  int m;
  scanf(" %d", &m);
  REP (i, m) scanf(" %d", x + i);
  REP (i, m) scanf(" %d", y + i);

  tuple<int, int, int> ret = make_tuple(-1, -1, -1);
  REP (i, m) {
    ret = max(ret, make_tuple(cnt[x[i]], cnt[y[i]], i));
  }

  printf("%d\n", get<2>(ret)+1);

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    scanf(" %d", &n);
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    vector<int> x(m), y(m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) cin >> y[i];

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    cout << ret.second.second+1 << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    scanf(" %d", &n);
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    vector<int> x(m), y(m);
    REP (i, m) scanf(" %d", &x[i]);
    REP (i, m) scanf(" %d", &y[i]);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int main() {
    ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      cin >> tmp;
      cnt[tmp]++;
    }
    int m;
    cin >> m;
    vector<int> x(m), y(m);
    REP (i, m) cin >> x[i];
    REP (i, m) cin >> y[i];

    tuple<int, int, int> ret = {-1, -1, 0};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], cnt[y[i]], i});
    }

    cout << get<2>(ret)+1 << endl;

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
    tuple<int, int> tt;
    int n;
    scanf(" %d", &n);
    map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) scanf(" %d", y + i);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
    ios_base::sync_with_stdio(0);

    int n;
    scanf(" %d", &n);
    unordered_map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", &x[i]);
    REP (i, m) scanf(" %d", &y[i]);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <tuple>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define EACH(itr,c) for(__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); itr++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define MP(x,y) make_pair(x,y)
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

int x[200000];
int y[200000];
int main() {
  tuple<int, int, int> tt;

    int n;
    scanf(" %d", &n);
    map<int, int> cnt;
    REP (i, n) {
      int tmp;
      scanf(" %d", &tmp);
      cnt[tmp]++;
    }
    int m;
    scanf(" %d", &m);
    REP (i, m) scanf(" %d", x + i);
    REP (i, m) scanf(" %d", y + i);

    pair<int, pair<int, int> > ret = {-1, {-1, 0}};
    REP (i, m) {
      ret = max(ret, {cnt[x[i]], {cnt[y[i]], i}});
    }

    printf("%d\n", ret.second.second + 1);

    return 0;
}


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

#define endl "\n"

bool cmp(const pair<pair<int,int>,int> a,const pair<pair<int,int>,int> b)
{
	if (a.first == b.first) return a.second > b.second;
	return a.first > b.first;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um;
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector < pair<pair<int, int>, int> > v(m);
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].first.first = um[num];
		v[i].second = i+1;
	}
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].first.second = um[num];
	}
	sort(v.begin(), v.end(), cmp);
	cout << v[0].second;
}


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

#define mod 1000000007
#define endl "\n"
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define dba(arr,size) for(auto i=0;i<size;i++) cout<<arr[i]<<" "; cout<<endl;
#define db2da(arr,row,col) for(auto i=0;i<row;i++){ for(auto j=0;j<col;j++) cout<<arr[i][j]<<" "; cout<<endl; }
#define all(container) container.begin(),container.end()

bool mySort(pair<int,int> &a,pair<int,int> &b){
    return a.second<=b.second;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int l;
    unordered_map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin>>l;
        cnt[l]+=1;
    }
    vector<pair<int,int> > sorted_cnt(all(cnt));
    sort(all(sorted_cnt),mySort);
    //tr(sorted_cnt,it) cout<<it->first<<" "<<it->second<<endl; cout<<endl;
    int m;
    cin>>m;
    int a,s;
    unordered_map<int,int> audio,subtitle;
    for(int i=1;i<=m;i++){
        cin>>a;
        audio[a]=i;
    }
    for(int i=1;i<=m;i++){
        cin>>s;
        subtitle[s]=i;
    }
    int best_movie=-1;
    for(auto it=sorted_cnt.rbegin();it!=sorted_cnt.rend();it++){
        auto it2=audio.find(it->first);
        if(it2==audio.end()) continue;
        best_movie=it2->second;
        break;
    }
    if(best_movie==-1){
        for(auto it=sorted_cnt.rbegin();it!=sorted_cnt.rend();it++){
        auto it2=subtitle.find(it->first);
        if(it2==subtitle.end()) continue;
        best_movie=it2->second;
        break;
    }
    }
    cout<<best_movie;
}


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

#define mod 1000000007
#define endl "\n"
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define dba(arr,size) for(auto i=0;i<size;i++) cout<<arr[i]<<" "; cout<<endl;
#define db2da(arr,row,col) for(auto i=0;i<row;i++){ for(auto j=0;j<col;j++) cout<<arr[i][j]<<" "; cout<<endl; }
#define all(container) container.begin(),container.end()

bool mySort(pair<int,int> &a,pair<int,int> &b){
    return a.second<=b.second;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int l;
    unordered_map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin>>l;
        cnt[l]+=1;
    }
    vector<pair<int,int> > sorted_cnt(all(cnt));
    sort(all(sorted_cnt),mySort);
    //tr(sorted_cnt,it) cout<<it->first<<" "<<it->second<<endl; cout<<endl;
    int m;
    cin>>m;
    int a,s;
    unordered_map<int,int> audio,subtitle;
    for(int i=0;i<m;i++){
        cin>>a;
        audio[a]=1;
    }
    for(int i=0;i<m;i++){
        cin>>s;
        subtitle[s]=1;
    }
    int best_movie=-1;
    for(auto it=sorted_cnt.end();it!=sorted_cnt.begin();it--){
        if(audio.find(it->first)==audio.end()) continue;
        best_movie=it->first;
        break;
    }
    cout<<best_movie;
}


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

#define LL long long
#define ULL unsigned long long
#define MOD 1000000007
#define TR(it,container) for(auto it=container.begin();it!=container.end();++it)
#define DB1(x) cout<<#x<<"="<<x<<endl;
#define DB2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define DB3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define DBA(arr,size) for(auto i=0;i<size;++i) cout<<arr[i]<<" "; cout<<endl;
#define DB2DA(arr,row,col) for(auto i=0;i<row;++i){ for(auto j=0;j<col;++j) cout<<arr[i][j]<<" "; cout<<endl; }
#define FOR(i,x,y) for(auto i=x;i<=y;++i)
#define ROF(i,y,x) for(auto i=y;i>=x;--i)
#define ALL(container) container.begin(),container.end()
#define endl "\n"

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    #ifdef LOCAL_MACHINE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif // LOCAL_MACHINE
    int n,m,l;
    cin>>n;
    unordered_map<int,int> scientist;
    while(n--){
        cin>>l;
        scientist[l]+=1;
    }
    cin>>m;
    int audio[m],subtitle[m];
    FOR(i,0,m-1) cin>>audio[i];
    FOR(i,0,m-1) cin>>subtitle[i];
    //vector<pair<int,int> > scientists(ALL(scientist));
    //sort(ALL(scientists),MySort());
    //int total=scientists.size();
    int movie=0,a=0,b=0;
    FOR(i,0,m-1){
        if(a<scientist[audio[i]]){
            a=scientist[audio[i]];
            b=scientist[subtitle[i]];
            movie=i+1;
        }
        else if(a==scientist[audio[i]]){
            a=scientist[audio[i]];
            if(b<scientist[subtitle[i]]){
                b=scientist[subtitle[i]];
                movie=i+1;
            }
        }
    }
    cout<<movie;
}


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

#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um;
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector < pair<int, int> > v(m);
	pair<int, int> best;
	best.first = 0;
	best.second = 0;
	int ans = 1;
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].first = um[num];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].second = um[num];
		if (best.first < v[i].first)
		{
			best.first = v[i].first;
			best.second = v[i].second;
			ans = i + 1;
		}
		else if(best.first == v[i].first)
		{
			if (best.second < v[i].second)
			{
				best.second = v[i].second;
				ans = i + 1;
			}
		}
		cout << i + 1 << endl;
		cout << best.first << " " << best.second << endl;
	}
	cout << ans;
}


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

#define LL long long
#define ULL unsigned long long
#define MOD 1000000007
#define TR(it,container) for(auto it=container.begin();it!=container.end();++it)
#define DB1(x) cout<<#x<<"="<<x<<endl;
#define DB2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define DB3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define DBA(arr,size) for(auto i=0;i<size;++i) cout<<arr[i]<<" "; cout<<endl;
#define DB2DA(arr,row,col) for(auto i=0;i<row;++i){ for(auto j=0;j<col;++j) cout<<arr[i][j]<<" "; cout<<endl; }
#define FOR(i,x,y) for(auto i=x;i<=y;++i)
#define ROF(i,y,x) for(auto i=y;i>=x;--i)
#define ALL(container) container.begin(),container.end()
#define endl "\n"

//struct MySort{
//    bool operator()(const pair<int,int> &a,const pair<int,int> &b){
//        if(a.second==b.second) return true;
//        return a.second>b.second;
//    }
//};

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    #ifdef LOCAL_MACHINE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif // LOCAL_MACHINE
    int n,m,l,found;
    cin>>n;
    unordered_map<int,int> scientist;
    while(n--){
        cin>>l;
        scientist[l]+=1;
    }
    cin>>m;
    int audio[m],subtitle[m];
    FOR(i,0,m-1) cin>>audio[i];
    FOR(i,0,m-1) cin>>subtitle[i];
    //vector<pair<int,int> > scientists(ALL(scientist));
    //sort(ALL(scientists),MySort());
    //int total=scientists.size();
    found=0;
    int movie,a=0,b=0;
    FOR(i,0,m-1){
        if(a<scientist[audio[i]]){
            a=scientist[audio[i]];
            b=scientist[subtitle[i]];
            movie=i+1;
        }
        else if(a==scientist[audio[i]]){
            a=scientist[audio[i]];
            if(b<scientist[subtitle[i]]){
                b=scientist[subtitle[i]];
                movie=i+1;
            }
        }
    }
    cout<<movie;
}


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

#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um(100000000);
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector <int> v(m);
	pair<int, int> best;
	best.first = 0;
	best.second = 0;
	int ans = 1;
	for (int i = 0; i < m; ++i)
	{
		cin >> num;
		v[i] = um[num];
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> num;
		num=um[num];
		if (best.first < v[i])
		{
			best.first = v[i];
			best.second = num;
			ans = i + 1;
		}
		else if(best.first == v[i])
		{
			if (best.second < num)
			{
				best.second = num;
				ans = i + 1;
			}
		}
		//cout << i + 1 << endl;
		//cout << best.first << " " << best.second << endl;
	}
	cout << ans;
}


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

#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um;
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector < pair<int, int> > v(m);
	pair<int, int> best;
	best.first = 0;
	best.second = 0;
	int ans = 1;
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].first = um[num];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].second = um[num];
		if (best.first < v[i].first)
		{
			best.first = v[i].first;
			best.second = v[i].second;
			ans = i + 1;
		}
		else if(best.first == v[i].first)
		{
			if (best.second < v[i].second)
			{
				best.second = v[i].second;
				ans = i + 1;
			}
		}
		//cout << i + 1 << endl;
		//cout << best.first << " " << best.second << endl;
	}
	cout << ans;
}


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

#define mod 1000000007
#define endl "\n"
#define tr(container,it) for(auto it=container.begin();it!=container.end();it++)
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define dba(arr,size) for(auto i=0;i<size;i++) cout<<arr[i]<<" "; cout<<endl;
#define db2da(arr,row,col) for(auto i=0;i<row;i++){ for(auto j=0;j<col;j++) cout<<arr[i][j]<<" "; cout<<endl; }
#define all(container) container.begin(),container.end()

bool mySort(pair<int,int> &a,pair<int,int> &b){
    return a.second<=b.second;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int l;
    unordered_map<int,int> cnt;
    for(int i=0;i<n;i++){
        cin>>l;
        cnt[l]+=1;
    }
    vector<pair<int,int> > sorted_cnt(all(cnt));
    sort(all(sorted_cnt),mySort);
    //tr(sorted_cnt,it) cout<<it->first<<" "<<it->second<<endl; cout<<endl;
    int m;
    cin>>m;
    int a,s;
    unordered_map<int,int> audio,subtitle;
    for(int i=1;i<=m;i++){
        cin>>a;
        audio[a]=i;
    }
    for(int i=1;i<=m;i++){
        cin>>s;
        subtitle[s]=i;
    }
    int best_movie=-1;
    for(auto it=sorted_cnt.rbegin();it!=sorted_cnt.rend();it++){
        auto it2=audio.find(it->first);
        if(it2==audio.end()) continue;
        best_movie=it2->second;
        break;
    }
    cout<<best_movie;
}


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

#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um(100000000/3);
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector <int> v(m);
	pair<int, int> best;
	best.first = 0;
	best.second = 0;
	int ans = 1;
	for (int i = 0; i < m; ++i)
	{
		cin >> num;
		v[i] = um[num];
	}
	for (int i = 0; i < m; ++i)
	{
		cin >> num;
		num=um[num];
		if (best.first < v[i])
		{
			best.first = v[i];
			best.second = num;
			ans = i + 1;
		}
		else if(best.first == v[i])
		{
			if (best.second < num)
			{
				best.second = num;
				ans = i + 1;
			}
		}
		//cout << i + 1 << endl;
		//cout << best.first << " " << best.second << endl;
	}
	cout << ans;
}


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

#define endl "\n"

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,m,num;
	cin >> n;
	unordered_map<int, int> um;
	for (int i = 0; i < n; ++i)
	{
		cin >> num;
		um[num] += 1;
	}
	cin >> m;
	vector < pair<int, int> > v(m);
	pair<int, int> best;
	best.first = 0;
	best.second = 0;
	int ans = 1;
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].first = um[num];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> num;
		v[i].second = um[num];
		if (best.first < v[i].first)
		{
			best.first = v[i].first;
			best.second = v[i].second;
			ans = i + 1;
		}
		else if(best.first == v[i].first)
		{
			if (best.second < v[i].second)
			best.second = v[i].second;
			ans = i + 1;
		}
	}
	cout << ans;
}


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

#define LL long long
#define ULL unsigned long long
#define MOD 1000000007
#define TR(it,container) for(auto it=container.begin();it!=container.end();++it)
#define DB1(x) cout<<#x<<"="<<x<<endl;
#define DB2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define DB3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl;
#define DBA(arr,size) for(auto i=0;i<size;++i) cout<<arr[i]<<" "; cout<<endl;
#define DB2DA(arr,row,col) for(auto i=0;i<row;++i){ for(auto j=0;j<col;++j) cout<<arr[i][j]<<" "; cout<<endl; }
#define FOR(i,x,y) for(auto i=x;i<=y;++i)
#define ROF(i,y,x) for(auto i=y;i>=x;--i)
#define ALL(container) container.begin(),container.end()
#define endl "\n"

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
    #ifdef LOCAL_MACHINE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif // LOCAL_MACHINE
    int n,m,l;
    cin>>n;
    unordered_map<int,int> scientist;
    while(n--){
        cin>>l;
        scientist[l]+=1;
    }
    cin>>m;
    int audio[m],subtitle[m];
    FOR(i,0,m-1) cin>>audio[i];
    FOR(i,0,m-1) cin>>subtitle[i];
    //vector<pair<int,int> > scientists(ALL(scientist));
    //sort(ALL(scientists),MySort());
    //int total=scientists.size();
    int movie=1,a=0,b=0;
    FOR(i,0,m-1){
        if(a<scientist[audio[i]]){
            a=scientist[audio[i]];
            b=scientist[subtitle[i]];
            movie=i+1;
        }
        else if(a==scientist[audio[i]]){
            a=scientist[audio[i]];
            if(b<scientist[subtitle[i]]){
                b=scientist[subtitle[i]];
                movie=i+1;
            }
        }
    }
    cout<<movie;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll  unsigned long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200005],b[200005];
unordered_map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200006],b[200006];
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200005],b[200005];
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=-1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};
vector<ll>v;
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=-1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++){
        ll x,y;
        cin>>x>>y;
        x=mp[x];
        y=mp[y];
        if(x>aud){
            ans=i;
            aud=x;
            sub=y;
        }
        else if(x==aud){
            if(y>sub){
                ans=i;
                x=aud;
                y=sub;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll  long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200007],b[200007];
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200005],b[200005];
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200005],b[200005];
unordered_map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


//10/12/2019
#include<bits/stdc++.h>

using namespace std;

#define debug printf("Debug\n");
#define ll  unsigned long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define p_b(x) push_back(x)
#define m_p(x) make_pair(x,y)

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll val,pos;
};

vector<ll>v;
ll a[200005],b[200005];
map<ll,ll>mp;

int main(){
    _fastio
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        mp[x]++;
    }
    ll ans=1,aud=0,sub=0;
    ll m;
    cin>>m;
    for(ll i=1;i<=m;i++) cin>>a[i];
    for(ll i=1;i<=m;i++) cin>>b[i];
    for(ll i=1;i<=m;i++){
        ll x,y;
        x=a[i];
        y=b[i];
        ll x1=mp[x];
        ll y1=mp[y];
        if(x1>aud){
            ans=i;
            aud=x1;
            sub=y1;
        }
        else if(x1==aud){
            if(y1>sub){
                ans=i;
                aud=x1;
                sub=y1;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}