You are given $$$t$$$ test cases. For each test case, you are given two integers $$$a$$$ and $$$b$$$ ($$$a \lt b$$$), and $$$n$$$ available operations.
The $$$i$$$-th operation is described by a pair $$$(x_i, y_i)$$$:
Initially, $$$v = a$$$.
You may apply each operation at most once, in any order. You may only apply an operation if after applying it the value does not exceed $$$b$$$ (i.e., you must keep $$$v \le b$$$ at all times).
Your task is to find the minimum total cost needed to reach exactly $$$v = b$$$. If it is impossible, output $$$-1$$$.
For each test case, print one integer: the minimum total cost to reach $$$b$$$, or $$$-1$$$ if it is impossible.
24 3 102 1 1 12 5 1 12 1 52 23 4
4-1
In the first test case, the cheapest way is to use two cheap $$$+1$$$ operations first, then double: $$$3 \to 4 \to 5 \to 10$$$, with total cost $$$1+1+2=4$$$.
In the second test case, only doubling operations are available, so from $$$1$$$ we can reach only $$$2$$$ and $$$4$$$, but never $$$5$$$. Hence the answers are $$$\texttt{4}$$$ and $$$\texttt{-1}$$$.