Soju
Time limit3sMemory limit128 MB
Given two point sets with every point of the first west of every point of the second, find the smallest Manhattan distance between a point from each set.
Problem
Two rival companies, IC and PC, share the soju market in Korea. Soju is a well-known Korean distilled liquor that goes well with Korean cuisine. The two companies have an agreement about where their branches may sit: every IC branch must lie to the west of every PC branch. In other words, all IC branches have a smaller -coordinate than any PC branch.
At the beginning of each month the companies check whether the agreement still holds. To do so they want the distance of the closest pair of branches, one from each company. The distance between two points and is defined as .

Figure 1. Blue disks are IC branches and red squares are PC branches. The distance of a closest pair between them is 5.
You are given two sets of points, and , representing the branches of IC and PC respectively. Every point in has a smaller -coordinate than any point in . Write a program that computes the minimum distance over all pairs with and .
Input
Your program reads from standard input. The first line contains the number of test cases . The first line of each test case contains an integer , the number of points in (). Each of the following lines contains the -coordinate and -coordinate of one point of . The next line contains an integer , the number of points in (). Each of the following lines contains the -coordinate and -coordinate of one point of . All coordinates are integers between and inclusive. Note that every point of has a smaller -coordinate than any point of .
Output
Your program writes to standard output. Print exactly one line for each test case. Each line contains a single integer, the distance of a closest pair of points, one from and one from .