eolymp
bolt
Try our new interface for solving problems
Problems

Area Coverage

Area Coverage

In this day and age, a lot of the spying on other countries is done with the use of satellites and drones equipped with cameras. All these photographs of various sizes and from various sources can be combined to give a picture of the country as a whole.

Given the photographs (that is to say, the rectangular area covered by each, since the contents of the photographs themselves are of course top-secret!), can you work out what the total area is of all that is photographed? Note that certain areas can appear on multiple photographs and should be counted only once.

Input

First line contains number of test cases, at most 100. After that per test case:

  • first line contains number of photographs n (1n1000).
  • n lines with four space-separated integers x1, y1, x2 and y2 (0x1, y1, x2, y2106, x1 < x2 и y1 < y2): the coordinates of the southwest and northeast corner respectively for each photograph. The photographs are all rectangular in shape with their other corners at (x1, y2) and (x2, y1).

The coordinates correspond to a flat two-dimensional space (i.e. we assume the Earth to be flat).

Output

For each test case print in one line the total area of all that appears on the photographs.

prb6406.gif

Time limit 1 second
Memory limit 128 MiB
Input example #1
2
3
1 2 7 5
3 0 4 7
6 4 8 8
2
1 1 4 5
2 2 7 4
Output example #1
29
18
Source 2013 Benelux Algorithm Programming Contest (BAPC), Preliminaries, September 28, Problem A