### Canonicalized Input Description:

An integer N (2 ≤ N ≤ 300000), representing some quantity or size.
An integer Q (2 ≤ Q ≤ 100000), representing some other quantity or size.
A list of integers A of size N, where each integer is between 1 and 300000.
A list of integers B of size Q, where each integer is between 1 and 300000.

### Example Input:

```
3 3
9 3 8
4
6
5
```

### Function Signature:
Write a function f(N, Q, A, B) that takes in the input.
def f(N: int, Q: int, A: List[int], B: List[int]):
    ''' 
    N: an integer
    Q: an integer
    A: a list of integers
    B: a list of integers
    '''