Ninja just started his new job at a cinema hall where there are ‘N’ number of rows with 10 seats in each row. Each seat is labeled with a number from 1 to 10. You are given an M x 2 2-D array/list “NON_VACANT”, where NON_VACANT[i][j] denotes that the seat located in a row ‘i’ and labeled ‘j’ is not vacant.
Ninja can assign seats in only groups of four people such that they all sit adjacent to each other in one single row. Help Ninja in finding the maximum number of the four people groups he can assign seats to.
Note:
Seats 3,4 and 7,8 are considered as not adjacent to each other.
There is an exceptional case in which seats 3,4 and seat 7,8 are considered to be adjacent and Ninja can split the group from the middle and assign seats to two people on each side.
Ninja can assign seats to a group of four people in the below depicted three manners.

The first line contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases are as follows.
The first line of each test case contains two space-separated integers ‘N’, and ‘M’, denoting the number of rows in the cinema hall and the number of reserved seats.
The next ‘M’ line contains two space-separated integers denoting the row number and seat number of reserved seats.
Output Format:
For each test case, return a single integer denoting the maximum number of the four-people groups that can be seated adjacently.
Note:
You don’t need to print anything; It has already been taken care of.
1 <= T <= 10
1 <= N <= 10^5
0 <= M <= 10*N
1 <= NON_VACANT[i][0] <= N
1 <= NON_VACANT[i][1] <= 10
Time limit: 1 sec
2
3 5
2 2
2 4
2 6
3 3
3 5
2 2
1 4
2 1
3
3
In the first test case,
In Row 1 - Two groups can be seated in seats [ 2,3,4,5 ] and [ 6,7,8,9 ]
In Row 2 - No group can be seated.
In Row 3 - One group can be seated in seats [ 6,7,8,9 ]
So a total of 3 groups can be seated.

Test Case 2:
In Row 1 - One group can be seated in seats [ 6,7,8,9 ]
In Row 2 - Two groups can be seated as [ 2,3,4,5 ] and [6,7,8,9 ]
So a total of 3 groups can be seated.

2
4 4
4 6
1 7
4 3
1 4
2 5
1 3
1 4
2 5
1 8
2 6
4
0
Can you think of all the possible ways in a row in which a group of people can be seated?
At first, it can be seen that the number of four-people groups that can be seated in a particular row is independent of all the other rows. So, if we know how to find the number of groups in a particular row, then similarly we can find it for all the other rows and our final answer will be the total number of groups in all rows.
Now, let's see how we can find the number of groups for a particular row:
We can simplify our solution from seat 2 to seat 9.
We will divide the seats into four sections:
Section1 - seat 2, 3
Section2 - seat 4, 5
Section3 - seat 6, 7
Section4 - seat 8, 9

So we will check the vacant sections in each row and calculate the total number of four-group people that can be seated.
Algorithm:
O(N + M), where ‘N’ is the number of rows in the cinema hall and ‘M’ is number of reserved seats.
Since we have traversed through all the rows and the reserved seats. Therefore the time complexity will be O(N + M).
O(N + M), where ‘N’ is the number of rows in the cinema hall and ‘M’ is number of reserved seats.
We have used an extra 2-D array “reservedSeats” to store all the rows and reserved seats in all rows. Therefore the space complexity will be O(N + M).