Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Oh No! Classes!

By mehdi_ · Limits 1s, 512 MB

You will be given three pairs of integers, which denotes the starting and ending time in seconds of three classes.

The task is very simple. You have to assign three classrooms for the classes and find the total class time. Class time is when at least one class is running.

Input

The first line will contain a positive integer T (1 ≤ T ≤ 100), denoting the number of test cases.

Each of the next T lines will contain 6 space separated positive integers denoting a1, b1, a2, b2, a3, b3 (0 ≤ a1, b1, a2, b2, a3, b3 ≤ 106).

Integers ai and bi are the starting and finishing time respectively of the i’th class.

Output

For each test case print the time required.

Sample

InputOutput
1
1 2 3 4 5 6
6

Here the first class is from 1 to 2 inclusive, so the class time is 2. The second class is from 3 to 4 inclusive, so the class time is 2 and it is the same for the third one.


Discussion

Statistics


53% Solution Ratio

AashiqEarliest, Jan '17

kamrul_ashrafFastest, 0.0s

Nasif_44thLightest, 0 B

mashfiqur404Shortest, 321B

Submit

Login to submit

Related Contests

Intra AUST Programming Contest Fall 2016 Ended at 2016-12-17 11:30:00 +0000 UTC
Replay of Intra AUST Programming Contest Fall 2016 Ended at 2017-01-04 16:00:00 +0000 UTC