Problem: A mysterious device was discovered in an ancient ruin. The device consists of a disc with integers inscribed on both sides, a bundle of cards with an integer written on each of them and a pedestal within which the cards are placed. The disc rotates when the bundle of cards is put into the pedestal. Only one side of the disc is exposed to view at any one time.

The disc is radially segmented in equal angles into $K$ sections, and an integer, from $1$ to $K$ in increasing order, is inscribed clockwise on each section on the front side. The sections on the back side share the same boundaries with the front side, and a negative counterpart of that in the section on the front side is inscribed, i.e., if $X$ is inscribed in the front side section, $-X$ is inscribed on the counterpart section on the back side. There is a needle on the periphery of the disc, and it always points to the middle point of the arc that belongs to a section. Hereafter, we say "the disc is set to $X$" if the front side section just below the needle contains an integer $X$.

<image>
Fig.1 Disc with 5 sections (i.e., $K = 5$): When the disc is set to $1$ on the front side, it is set to $-1$ on the back side.

Investigation of the behavior of the device revealed the following:

When the bundle of cards is placed in the pedestal, the device sets the disc to 1.
Then, the device reads the cards slice by slice from top downward and performs one of the following actions according to the integer $A$ on the card

* If $A$ is a positive number, it rotates the disc clockwise by $|A|$ sections.
* If $A$ is zero, it turns the disc back around the vertical line defined by the needle and the center of the disc.
* If $A$ is a negative number, it rotates the disc counterclockwise by $|A|$ sections.



It is provided that $|A|$ is the absolute value of $A$. The final state of the device (i.e., to what section the needle is pointing) varies depending on the initial stacking sequence of the cards. To further investigate the behavior of the device, we swapped two arbitrary cards in the stack and placed the bundle in the pedestal to check what number the disc is set to. We performed this procedure over again and again.

Given the information on the device and several commands to swap two cards, make a program to determine the number to which the device is set at the completion of all actions. Note that the stacking sequence of the cards continues to change as a new trial is made.



Input

The input is given in the following format.


$K$ $N$ $Q$
$A_1$ $A_2$ ... $A_N$
$L_1$ $R_1$
$L_2$ $R_2$
$...$
$L_Q$ $R_Q$


The first line provides the number of sections $K$ ($2 \leq K \leq 10^9$), the slices of cards $N$ ($2 \leq N \leq 100,000$), and the number of commands $Q$ ($1 \leq Q \leq 100,000$). The second line provides an array of $N$ integers inscribed on the sections of the disc. $A_i$ ($-10^9 \leq A_i \leq 10^9$) represents the number written on the $i$-th card from the top. Each of the subsequent $Q$ lines defines the $i$-th command $L_i,R_i$ ($1 \leq L_ i < R_i \leq N$) indicating a swapping of $L_i$-th and $R_i$-th cards from the top followed by placing the card bundle in the device.

Output

For each command, output a line containing the number to which the device is set at the completion of all actions.

Examples

Input

5 3 1
1 -2 0
2 3


Output

-3


Input

5 7 5
0 0 3 3 3 3 3
1 2
2 3
3 4
4 5
5 6


Output

1
2
3
4
5

Solution (in CPP):

Solution:
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<Pll>v;
map<Pll, Pll>ma;
set<LL>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, a[210000], b[210000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Seg {
	LL n;
	vector<LL>node, lazy;
	vector<bool> flag;
	Seg(LL n_) {
		n = 1; while (n < n_)n *= 2;
		node.resize(n * 2 - 1);
		flag.resize(n * 2 - 1);
		lazy.resize(n * 2 - 1);
		rep(i, n)node[n + i - 1] = 0;
		Rrep(i, n - 2)node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
		//区間最小などの時
		//rep(i, n * 2 - 1)lazy[i] = -1;
	}
	//区間の最小の遅延
	void ceval(LL k, LL l, LL r) {
		if (lazy[k] != 0) {
			node[k] = -node[k];
			flag[k] = !flag[k];
			if (r - l >= 1) {
				lazy[k * 2 + 1] ^= 1;
				lazy[k * 2 + 2] ^= 1;
			}
			lazy[k] = 0;
		}
	}
	void update1(LL l, LL r) {
		update1(0, 0, n - 1, l, r);
	}
	void update1(LL i, LL a, LL b, LL l, LL r) {
		ceval(i, a, b);
		if (b < l || r < a)return;
		if (l <= a && b <= r) {
			lazy[i] ^= 1;
			ceval(i, a, b);
		}
		else {
			update1(i * 2 + 1,  a, (a + b) / 2, l, r);
			update1(i * 2 + 2, (a + b + 1) / 2, b, l, r);
			node[i] = (node[i * 2 + 1] + node[i * 2 + 2]);
		}
	}
	void update2(LL x,LL l) {
		update2(0, x, 0, n - 1, l);
	}
	void update2(LL i, LL x, LL a, LL b, LL l) {
		ceval(i, a, b);
		if (b < l || l < a)return;
		if (l <= a && b <= l) {
			node[i] = x * (flag[i] ? -1 : 1);
		}
		else {
			update2(i * 2 + 1, x, a, (a + b) / 2, l);
			update2(i * 2 + 2, x, (a + b + 1) / 2, b, l);
			node[i] = (node[i * 2 + 1] + node[i * 2 + 2]);
		}
	}
	LL getsum(LL l, LL r) {
		return getsum(0, 0, n - 1, l, r);
	}
	LL getsum(LL i, LL a, LL b, LL l, LL r) {
		ceval(i, a, b);
		if (b < l || r < a)return 0;
		if (l <= a && b <= r)return node[i];
		return (getsum(i * 2 + 1, a, (a + b) / 2, l, r) + getsum(i * 2 + 2, (a + b + 1) / 2, b, l, r));
	}
};
Seg seg(210000);
int main() {
	cin >> n >> m >> q;
	rep(i,m){
		cin >> a[i];
		if (a[i] == 0)
			seg.update1(i, m), cnt++;
		else
			seg.update2(a[i], i);
	}
	rep(i, q) {
		LL x, y;
		cin >> x >> y;
		x--, y--;
		if (a[x]==a[y]) {}
		else if(a[x]==0){
			seg.update1(x,m);
			seg.update1(y,m);
			seg.update2(0, y);
			seg.update2(a[y], x);		
		}
		else if (a[y]==0) {
			swap(x, y);
			seg.update1(x, m);
			seg.update1(y, m);
			seg.update2(0, y);
			seg.update2(a[y], x);
		}
		else {
			seg.update2(a[x],y);
			seg.update2(a[y], x);
		}
		swap(a[x],a[y]);
		LL cur = (seg.getsum(0, m) % n + n) % n;
		cout << ((n-cur)%n+1)*(cnt%2?-1:1) << endl;
	}
	return 0;
}