Homer Simpson has different kinds of barrels for collecting and storing various liquids. For example, water barrels, oil barrels, and so on. He keeps these barrels in the basement of his house in sequential order. Each barrel has a capacity, which is the maximum volume of the liquid it can contain.
Let's denote the capacity of the -th barrel by . There are barrels, with their numbering starting at , so the st barrel has capacity, ..., the th barrel has capacity.
Recently, Bart and Homer have started a project: each day, Bart brings home a specific type of liquid (for example, water, oil, yogurt, etc.) with volume , either purchased from a store or collected during his daily activities. Homer tries to pour the liquid into an appropriate barrel using a specific strategy called the "Simpson Barrel Finding Algorithm" ():
- First, he finds all barrels for the given liquid type that have at least units of free volume remaining (initially, each barrel's free volume equals its capacity). - If there are several such barrels, he selects those with the smallest free volume among them. - If there is still a tie, he chooses the barrel with the smallest index.
Suppose Homer selects the barrel with index using . He and Bart then pour the liquid into the th barrel, and its free volume decreases by .
If there is no barrel with enough free space for the given liquid, Homer and Bart simply store the liquid elsewhere and ignore it for now.
The first line contains integers: — number of barrels in the basement (1 \leq n \leq 1000000), — number of liquid types (1 \leq L \leq 1000), — number of days Bart brings home a liquid (number of queries, 1 \leq q \leq 100000).
The next line contains integers, where the th integer is , the capacity of the th barrel (1 \leq \text{Cap}[i] \leq 10^9). The following line contains integers, where the th integer is and indicates the type of the th barrel (oil, water, soap, yogurt, etc., 1 \leq l \leq L).
The next lines each contain numbers and separated by a space (1 \leq l \leq L, 1 \leq v \leq 10^9).
For each query, output on a separate line the index of the barrel (1 \leq b \leq n) selected by after processing the query.
If there is no suitable barrel for the liquid, output .
Example 1