Beauty Permutation Queries
The problem uses 0-indexing, i.e., arrays are numbered starting from 0.
A permutation of length is an array of positive integers where each element appears exactly once and every number from to is present. For example, , , are permutations, while , , are not.
We define the set of reachable transformations of permutation with respect to set as the set of permutations that can be obtained from by applying the following operation any number of times (possibly 0):
Choose two indices such that , and swap the elements of permutation at positions and .
Here, denotes the bitwise XOR operation.
The set is called good with respect to permutation if the set of reachable transformations of permutation contains an identity permutation.
We call a permutation of length identity permutation if the following holds: .
The beauty of permutation is defined as the minimum size of a good set with respect to it.
You are given a permutation of length . You need to output the initial beauty of the permutation. You are also given queries. Each query consists of two numbers . After each query, you need to swap the elements at positions and . Note that the permutation retains changes after each query. In response to each query, you need to output the beauty of the resulting permutation.
Input
The first line contains two numbers and .
The second line contains numbers — the starting permutation.
The third line contains one number — the number of queries.
In the following lines, two numbers are given — the parameters of the -th query.
The values of the -th query are determined as follows. Let be the answer to the previous query, or the beauty of the initial permutation if this is the first query. Then , and .
Output
In the first line, output the beauty of the initial permutation.
In the following lines, output the answers to the queries.
Examples
Note
After the second query, the permutation becomes .
Let . Using this set, we can perform the following swaps to transform the permutation into the identity permutation:
Swap and . The permutation becomes .
Swap and . The permutation becomes .
Swap and . The permutation becomes .
Swap and . The permutation becomes .
It can be proven that it's impossible to obtain the identity permutation by performing operations with .
Scoring
( points): ;
( points): ;
( points): it is guaranteed that the answer does not exceed , ;
( points): ;
( points): ;
( points): ;
( points): no additional restrictions.