House of Kittens (Large)
Time limit5sMemory limit512 MB
Assign a flavor to each polygon vertex so that every room touches each flavor used, maximizing the flavor count.
Problem
You adopted a few kittens, and now you are building a house for them. From the outside the house is a convex polygon with vertices. Inside, interior walls divide it into rooms, and each interior wall is a straight segment between two vertices. No two interior walls cross, but several walls may touch the same vertex.
At every vertex you build a pillar made entirely of catnip. A kitten can play with any pillar that touches the room it is in.
You want to use several flavors of catnip. One pillar uses a single flavor, and different pillars may use different flavors. The problem is that if some room cannot reach every flavor in the house, the kittens in that room feel left out. So the assignment of flavors to pillars has to satisfy both of these conditions.
(a) Every flavor is reachable from every room. (b) The number of flavors used is as large as possible.
Find , the largest number of flavors the house can use. You do not print the assignment itself.
The picture below shows an 8-sided house that uses three flavors (the red, green, and blue dots) while every room still reaches all three. Starting at the left vertex of the top wall and going clockwise, the flavors are green, blue, red, red, blue, green, blue, red.

Input
The first line contains the number of test cases, . test cases follow.
Each test case consists of three lines. The first line contains the number of vertices and the number of interior walls . The second line contains space-separated integers , the vertex where each interior wall begins. The third line contains space-separated integers , the vertex where each interior wall ends.
The vertices are numbered in clockwise order, so interior wall joins vertex and vertex .
Limits
- for every
- Interior walls touch each other only at the vertices.
- Interior walls touch the outer boundary of the house only at the vertices.
Output
For each test case, print one line in the form Case #x: C, where is the test case number starting from 1 and is the largest number of catnip flavors that the house can use. Print only this number; do not print the flavor assigned to each pillar.