SP1554 ZOO - Zoo

Description

The pride of the Asia-Pacific region is the newly constructed Great Circular Zoo. Situated on a small Pacific island, it consists of a large circle of different enclosures, each containing its own exotic animal as illustrated below. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP1554/1563f78c3cea2721a57d42d198a2f8999ccc93b3.png)You are in charge of public relations for the zoo, which means it is your job to keep people as happy as possible. A busload of schoolchildren has just arrived, and you are eager to please them. However, this is no easy task|there are animals that some children love, and there are animals that some children fear. For example, little Alex loves monkeys and koalas because they are cute, but fears lions because of their sharp teeth. On the other hand, Polly loves lions because of their beautiful manes, but fears koalas because they are extremely smelly. You have the option of removing some animals from their enclosures, so that children are not afraid. However, you are worried that if you remove too many animals then this will leave the children with nothing to look at. Your task is to decide which animals to remove so that as many children can be made happy as possible. Each child is standing outside the circle, where they can see five consecutive enclosures. You have obtained a list of which animals each child fears, and which animals each child loves. A child will be made happy if either at least one animal they fear is removed from their field of vision, or at least one animal they love is not removed from their field of vision. For example, consider the list of children and animals illustrated below: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP1554/cea531b4ebed8a54f60250206b43966df215b82c.png)``` ----------------------------------------------------------------------- |Child |Enclosures Visible |Fears |Loves | |Alex |2, 3, 4, 5, 6 |Enclosure 4 |Enclosures 2, 6| |Polly |3, 4, 5, 6, 7 |Enclosure 6 |Enclosure 4 | |Chaitanya |6, 7, 8, 9, 10 |Enclosure 9 |Enclosures 6, 8| |Hwan |8, 9, 10, 11, 12 |Enclosure 9 |Enclosure 12 | |Ka-Shu |12, 13, 14, 1, 2 |Enclosures 12, 13, 2 |- | ----------------------------------------------------------------------- ``` Suppose you remove the animals from enclosures 4 and 12. This will make Alex and Ka-Shu happy, because at least one animal that they fear has gone. This will also keep Chaitanya happy, since both enclosures 6 and 8 still contain animals that he loves. However, both Polly and Hwan will be unhappy, since they cannot see any animals that they love but they can still see all the animals that they fear. This arrangement therefore gives a total of three happy children. Now suppose you put these animals back into their enclosures, and remove the animals from enclosures 4 and 6 instead. Alex and Polly will be happy because the animals that they fear in enclosures 4 and 6 have gone. Chaitanya will be happy because, even though animal 6 has gone, he can still see the animal in enclosure 8 which he loves. Likewise, Hwan will be happy because she can now see the animal in enclosure 12, which she loves. The only person unhappy will be Ka-Shu. Finally, suppose you put the animals back once more and then remove only the animal from enclosure 13. Ka-Shu will now be happy since one animal that he fears has been removed, and Alex, Polly, Chaitanya and Hwan will all be happy since they can all see at least one animal that they love. Thus this arrangement gives five happy children, the largest number possible.

Input Format

Multiple test cases, the number of them will be given at the very first line. For each test case: The first line will be of the form N C, where N is the number of animal enclosures (10

Output Format

Output must consist of a single integer, giving the largest number of children that can be made happy.