# Step 1: Create a ring of C computers with C bidirectional links def create_ring(C): links = [] for i in range(1, C): links.append((i, i+1)) links.append((C, 1)) return links # Step 2: Assign unique IDs to each computer def assign_ids(C): ids = list(range(1, C+1)) return ids # Step 3: Print the network design def print_network_design(links): for link in links: print(link[0], link[1]) # Step 4: Read the permuted design from the judge def read_permuted_design(C): permuted_links = [] for i in range(C): u, v = map(int, input().split()) permuted_links.append((u, v)) return permuted_links # Step 5: Find a ring in the permuted design def find_ring(permuted_links, C): # Convert permuted links to a dictionary for easy lookup permuted_dict = {u: v for u, v in permuted_links} # Start with the first computer in the permuted design x1 = permuted_links[0][0] xi = x1 # Keep track of visited computers to avoid loops visited = set([x1]) # Find the ring by following the links ring = [x1] while len(ring) < C: xi = permuted_dict[xi] ring.append(xi) visited.add(xi) # Make sure the ring is closed if permuted_dict[xi] != x1 or len(visited) < C: print("Wrong Answer") exit(0) return ring # Step 6: Repeat for each test case T = int(input()) # Number of test cases for _ in range(T): C, L = map(int, input().split()) # Number of computers and links links = create_ring(C) # Step 1: Create ring ids = assign_ids(C) # Step 2: Assign IDs print_network_design(links) # Step 3: Print network design