You are given a sorted list of ‘N’ disjoint ranges of integers and a range ‘removeRange’. A range can be represented as [ ‘start’, ‘end’) where ‘end’ > ‘start’ and all the real numbers ‘x’ such that ( ‘start’ <= ‘x’ < ‘end’ ) belong to that range.
You need to remove all intersections between any range in the given list of ranges and range ‘removeRange’. Then return a resulting list of ranges in sorted order.
Note :
Here, Disjoint ranges mean that no two ranges from the given list intersect each other.
A list of ranges [ (X1, Y1), (X2, Y2), (X3, Y3) … (Xn, Yn) ] is sorted if and only if Xi > Xi-1 and as the given ranges are disjoint, so Xi > Yi-1 for each i [ 1 < i <= n].
Example :
Let ‘N’= 3, given list be [(1, 3), (4, 6), (8, 11) ], and ‘removeRange’ be (2, 8).
Then after removing all intersections between ranges in the list and ‘removeRange’.The list will look like [(1, 2), (8, 11) ].
As we have removed,
Range (2,3) from the first range (1,3).
The whole second range (4, 6) as this is fully intersecting with the given ‘removeRange’
Nothing from the third range (8, 11) as no point is in this range is intersecting with the given ‘removeRange’ (2,8).
Note :
The resulting list after removing ranges can be empty also.
Input format :
The first line of input contains an integer ‘T’ denoting the number of test cases. The description of ‘T’ test cases follows
The first line of each test case contains an integer ‘N’ representing the number of ranges in the given list.
Next ‘N’ lines of the test case contain two space-separated integers, ‘start’ and ‘end’, denoting the starting and the ending point of the i-th range.
The last line of the test cases contains two space-separated integers, ‘start’ and ‘end’, denoting the starting and the ending point of the ‘removeRange’.
Output format :
For each test case, print ‘K’ lines containing two space-separated integers, ‘start’ and ‘end’, denoting the starting and the ending point of the ith range in the resulting list after removing ranges. Where ‘K’ is the size of the resulting list of ranges. If ‘K’ is 0 i.e. the resulting list does not contain any range then print ‘-1’
The output of each test case will be printed in a separate line.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
In the given function, you need to return a 2D array ‘arr[K][2]’, where ‘K’ is the number of ranges in the resulting list after removing ranges and ‘arr[i][0]’, ‘arr[i][1]’ are the starting and ending points in the ‘i th’ range of resulting string.
Constraints :
1 <= T <= 5
1 <= N <= 3000
1 <= start <= end <= 10^9
Where ‘T’ is the total number of test cases, ‘N’ is the number of ranges, and ‘start’ and ‘end’ represent the first and the last integer of a range.
Time Limit : 1 sec
2
4
1 3
4 6
7 8
9 10
5 8
1
1 6
2 4
1 3
4 5
9 10
1 2
4 6
Test case 1:
The given ranges are [ (1, 3), (4, 6), (7, 8), (9, 10)] and given ‘removeRange’ is (5, 8).
Below figure shows the remove operation on given ranges, ‘removeRange’ is shown in red color.

Test case 2:

1
2
5 10
10 12
1 15
-1
The given ‘removeRange’ fully intersects with all ranges in the given list, thus we have to remove all ranges and return an empty list.
Check all points from minimum point to maximum point in the given range.
The idea here is to iterate over all points from minimum to maximum point in the given list of ranges and check if this point can be part of the range in the result list. The minimum point will be the ‘start’ point of the first range in the list and the maximum point will be the ‘end’ point of the last range in the given list because the given list is sorted. A point can only be included in the answer if and only if it lies in one of the given ranges and doesn’t lie on the given ‘removeRange’, else it cannot be included in the answer.
The function will take two parameters:
bool check ( ‘point’, ‘list’ ):
O(D * N ), where ‘D’ is the difference between the minimum and maximum points in the given list of ranges and ‘N’ is the total number of given ranges.
As we checking each point from minimum to maximum point in the given list of ranges, and a check operation takes O(N) times complexity in the worst case, hence the overall complexity will be O ( D* N ).
O(N), where ‘N’ is the total number of given ranges.
In the worst case, the ‘answer’ array will store all the given ranges hence overall space complexity will be O(N).