### Canonicalized Input Description:

An integer n (2 ≤ n ≤ 100000), representing some quantity or size.
n lines follow, each containing an integer ki (0 ≤ ki ≤ n-1) followed by ki integers representing IDs.
An integer q (2 ≤ q ≤ 200000), representing some quantity or size.
q lines follow, each containing either:
- Three integers: 0, v (1 ≤ v ≤ n-1), and w (1 ≤ w ≤ 10000).
- Two integers: 1 and u (1 ≤ u ≤ n-1).

### 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, node_info, q, queries) that takes in the input.
```
def f(n: int, node_info: List[Tuple[int, List[int]]], q: int, queries: List[Tuple[int, ...]]):
    ''' 
    n: an integer 
    node_info: a list of tuples where each tuple contains an integer and a list of integers
    q: an integer
    queries: a list of tuples, where each tuple contains either two or three integers
    '''
```