Those guys are definitely teaming.
n players numbered from 0 to n−1 are playing a game. There is a number x, which is initially equal to 0. There are n numbers a_i (0≤i,a_i≤n−1) that are subject to change between the rounds of the game. The game proceeds as follows:
After this process, the player with the number x wins.
Each player makes a move (that is, changes x) if and only if he will win if he makes a move, but won't win if he doesn't. Players know that everyone plays according to this strategy.
You have to answer q queries: if we change a_x to y who will win the game? Note that the changes are not reverted after each query.
The first line of input contains a single integer n (1≤n≤105) --- the number of players.
The second line contains n integers --- initial values of a_i (0≤a_i≤n−1).
The third line contains a single integer q (0≤q≤105) --- the number of queries.
q lines follow. i-th of them contains two integers x_i and y_i (0≤x_i,y_i≤n−1) meaning that a_x_i is equal to y_i from this query onwards.
Output q+1 integers. i-th them should be the number of the winner of the game after i−1 queries.