SP286 SCITIES - Selfish Cities

Description

Far, far away there is a world known as Selfishland because of the nature of its inhabitants. Hard times have forced the cities of Selfishland to exchange goods among each other. C1 cities are willing to sell some goods and the other C2 cities are willing to buy some goods (each city can either sell or buy goods, but not both). There would be no problem if not for the selfishness of the cities. Each selling city will sell its goods to one city only, and each buying city will buy goods from one city only. Your goal is to connect the selfish cities in such a way that the amount of exchanged goods is maximalized.

Input Format

The first line contains a positive integer t

Output Format

For each test case print the maximal amount of goods exchanged.