### Input Description

1. An integer \( N \) (1 ≤ \( N \) ≤ 2000), representing some quantity or size.
2. An integer \( M \) (1 ≤ \( M \) ≤ 2000), representing another quantity or size.
3. \( M \) lines follow, each containing three integers \( a_i \), \( b_i \), and \( c_i \) where \( 1 ≤ a_i < b_i ≤ N \) and \( 1 ≤ c_i ≤ 3 \).
4. An integer \( Q \) (1 ≤ \( Q \) ≤ 2000), representing yet another quantity or size.
5. \( Q \) lines follow, each containing two integers \( d_j \) and \( e_j \) where \( 1 ≤ d_j ≤ N \) and \( 0 ≤ e_j ≤ 100000 \).

### Example Input:

```
4 3
1 3 2
2 4 1
1 2 3
2
4 6
2 4
```

### Function Signature:
Write a function `f(N, M, triples, Q, pairs)` that takes the input. 
```python
def f(N: int, M: int, triples: List[Tuple[int, int, int]], Q: int, pairs: List[Tuple[int, int]]):
    '''
    N: int -> The first integer
    M: int -> The second integer
    triples: List[Tuple[int, int, int]] -> The list of triples
    Q: int -> The third integer
    pairs: List[Tuple[int, int]] -> The list of pairs
    '''
```