An integer n (2 ≤ n ≤ 100000), representing some quantity or size.
n lines each containing an integer k followed by k integers, representing some relationships.
An integer q (2 ≤ q ≤ 200000), representing the number of queries.
q lines, each containing either three integers or two integers, representing different types of operations.

### Example Input:

```
6
2 1 2
2 3 5
0
0
0
1 4
7
1 1
0 3 10
1 2
0 4 20
1 3
0 5 40
1 4
```

### Function Signature:
Write a function f(n, relationships, q, queries) that takes in the input.
def f(n: int, relationships: List[Tuple[int, List[int]]], q: int, queries: List[Tuple[int, Union[int, Tuple[int, int]]]]):
    '''
    n: an integer
    relationships: a list of tuples, each containing an integer and a list of integers
    q: an integer
    queries: a list of tuples, each containing either two integers or a tuple of three integers
    '''