Canonicalized Input Description:

An integer X (1 ≤ X ≤ 10^9).
An integer K (1 ≤ K ≤ 10^5).
A list of K integers, each between 1 and 10^9, in ascending order.
An integer Q (1 ≤ Q ≤ 10^5).
A list of Q tuples, each containing:
  - An integer t_i (0 ≤ t_i ≤ 10^9), in ascending order.
  - An integer a_i (0 ≤ a_i ≤ X).

### Example Input:

```
180
3
60 120 180
3
30 90
61 1
180 180
```

### Function Signature:
Write a function f(X, K, r, Q, queries) that takes in the input.
```python
def f(X: int, K: int, r: List[int], Q: int, queries: List[Tuple[int, int]]):
    ''' 
    X: an integer 
    K: an integer
    r: a list of integers
    Q: an integer
    queries: a list of tuples
    '''
```