An integer N (3 ≤ N ≤ 10^5), representing some quantity or size.
N-1 lines, each containing three integers a, b, c where (1 ≤ a, b ≤ N) and (1 ≤ c ≤ 10^9).
Two integers Q and K (1 ≤ Q ≤ 10^5, 1 ≤ K ≤ N).
Q lines, each containing two integers x and y (1 ≤ x, y ≤ N, x ≠ y, x ≠ K, y ≠ K).

### Example Input:

```
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5
```

### Function Signature:
Write a function f(inputs) that takes in a list of inputs as tuples.
def f(inputs: List[Tuple[int, List[Tuple[int, int, int]], int, int, List[Tuple[int, int]]]]):
    '''
    inputs: a list of tuples
    '''