Elephants in a Pond

All submissions for this problem are available.

###Read problems statements in [Hindi](http://www.codechef.com/download/translated/CK100TST/hindi/ELEPPOND.pdf), [Mandarin Chinese](http://www.codechef.com/download/translated/CK100TST/mandarin/ELEPPOND.pdf), [Russian](http://www.codechef.com/download/translated/CK100TST/russian/ELEPPOND.pdf), [Vietnamese](http://www.codechef.com/download/translated/CK100TST/vietnamese/ELEPPOND...) and [Bengali](http://www.codechef.com/download/translated/CK100TST/bengali/ELEPPOND.pdf) as well.
Some elephants have decided to drink water from a pond. The pond may be considered a grid with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). There are $4N$ elephants and they stand at the perimeter of the pond in such a way that there is exactly one elephant at the top and bottom of each column and at the left and right end of each row.
Since elephants can only see straight, in order to drink, an elephant must stretch its trunk over and into the pond. If an elephant's trunk has length $L$, it covers $L$ nearest cells to the elephant in the elephant's row or column. For example, for an elephant with trunk length $3$ standing at the south side of column $2$, its trunk should cover cells $(N, 2)$, $(N-1, 2)$ and $(N-2, 2)$.
Since elephant herds have a strict hierarchy, the elephants on each side of the pond order themselves in such a way that their trunk lengths are either non-increasing or non-decreasing.
It is guaranteed that the trunks of elephants at the opposite ends of a row or column will never touch each other. But it is still possible for the trunks of some elephants (which are on adjacent sides) to touch or intersect in this scenario. The trunks of two elephants touch if there is at least one cell they both cover. The elephants do not want this to happen, so some of them have to leave. Your task is to find the minimum number of elephants that have to be removed from this arrangement so that no two remaining elephants' trunks touch each other.
### Input
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $L_{n, 1}, L_{n, 2}, \dots, L_{n, N}$, where $L_{n, i}$ denotes the length of the trunk of the elephant at the north side of column $i$.
- The third line contains $N$ space-separated integers $L_{s, 1}, L_{s, 2}, \dots, L_{s, N}$, where $L_{s, i}$ denotes the length of the trunk of the elephant at the south side of column $i$.
- The fourth line contains $N$ space-separated integers $L_{e, 1}, L_{e, 2}, \dots, L_{e, N}$, where $L_{e, i}$ denotes the length of the trunk of the elephant at the east side of row $i$.
- The fifth line contains $N$ space-separated integers $L_{w, 1}, L_{w, 2}, \dots, L_{w, N}$, where $L_{w, i}$ denotes the length of the trunk of the elephant at the west side of row $i$.
### Output
For each test case, print a single line containing one integer — the minimum number of elephants to remove.
### Constraints
- $1 \le T \le 1,000$
- $1 \le N \le 10,000$
- $0 \le L_{d, i} \le N$ for each valid $i$ and direction $d$
- for each direction $d$, the sequence $L_{d, 1}, L_{d, 2}, \dots, L_{d, N}$ is monotonous (ie. either monotonically increasing, or monotonically decreasing)
- $L_{n, i} + L_{s, i} \le N$ for each valid $i$
- $L_{e, i} + L_{w, i} \le N$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10,000$
### Example Input
```
2
2
1 1
1 1
1 1
1 1
2
1 2
1 0
0 0
0 0
```
### Example Output
```
4
0
```
### Explanation
**Example case 1:** The elephant on the North side at column 1 and the elephant on the West side at row 1 have their trunks touching each other. Similarly, there are three other intersections. You can check that you need to remove at least 4 elephants.

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to INR 20,000 (for Indian Community), $700 (for Global Community) and lots more CodeChef goodies up for grabs.