Game

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

Those guys are definitely teaming.

nn players numbered from 0 to n1n-1 are playing a game. There is a number xx, which is initially equal to 0. There are nn numbers a_ia\_i (0i,a_in10 \leq i, a\_i \leq n - 1) that are subject to change between the rounds of the game. The game proceeds as follows:

  1. Player 0 either skips his turn or makes xx equal to (x+a_0)modn(x + a\_0) \bmod n.
  2. Player 1 either skips his turn or makes xx equal to (x+a_1)modn(x + a\_1) \bmod n.
  3. \ldots
  4. Player n1n - 1 either skips his turn or makes xx equal to (x+a_n1)modn(x + a\_{n-1}) \bmod n.

After this process, the player with the number xx wins.

Each player makes a move (that is, changes xx) 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 qq queries: if we change a_xa\_x to yy who will win the game? Note that the changes are not reverted after each query.

입력

The first line of input contains a single integer nn (1n1051 \leq n \leq 10^5) --- the number of players.

The second line contains nn integers --- initial values of a_ia\_i (0a_in10 \leq a\_i \leq n - 1).

The third line contains a single integer qq (0q1050 \leq q \leq 10^5) --- the number of queries.

qq lines follow. ii-th of them contains two integers x_ix\_i and y_iy\_i (0x_i,y_in10 \leq x\_i, y\_i \leq n - 1) meaning that a_x_ia\_{x\_i} is equal to y_iy\_i from this query onwards.

출력

Output q+1q+1 integers. ii-th them should be the number of the winner of the game after i1i-1 queries.