Implement a function that calculates the maximum distance in a graph and the associated cost based on that distance. The function will evaluate multiple test cases consisting of a set of edges for each graph.
Functionality Requirements:
Define a function calculate_max_distance_and_cost(test_cases) that takes a list of test cases.
Each test case is a tuple containing:
An integer n representing the number of vertices in the graph (numbered from 1 to n).
A list of edges, where each edge is represented as a tuple (x, y, z), indicating an undirected edge between vertices x and y with a weight of z.
The function should perform the following tasks:
Construct an adjacency list for the graph.
Determine the maximum distance in the graph using a Breadth-First Search (BFS) algorithm.
Calculate the cost based on the maximum distance found, using the following criteria:
If the distance is less than 100, the cost is 0.
If the distance is between 100 and 999, the cost is 100.
If the distance is between 1000 and 9999, the cost is 1000.
If the distance is 10000 or more, the cost is 10000.
Return a list of tuples, where each tuple consists of the calculated cost and the maximum distance for each test case.
Input/Output Requirements:
Input: A list of test cases, where each test case is a tuple (n, edges).
Output: A list of tuples (cost, max_distance) for each test case.
File Requirements:
Write the implementation in a file named /app/solution.py. The file should include the function definition and adhere to Python coding conventions.