Young programmer Vasya develops a data storage
with a programming interface of multi-dimensional array.
Elements of this array are accessed by composite index: (i_{1}, i_{2}, …, i_{N}).
Array dimensions are defined by values A_{1}, A_{2}, …, A_{N}
(i.e. 0 ≤ i_{k} < A_{k}, k = 1… N).

Index ranges are non-decreasing (A_{k} ≤ A_{k + 1}).
A special feature of Vasya's array is index-permutation symmetry.
It means that elements with composite indices coinciding up to their permutation
are considered equal.

To compactly represent array in memory Vasya decided on the following layout.
Elements are stored sequentially row-by-row (aka row-major order) in one-dimensional array,
which corresponds to lexicographically increasing composite indices.
Those elements for which some permutation of their composite index was already
encountered before are skipped.

Your program must execute queries of two kinds.

Given composite index, determine corresponding one-dimensional index.

Given one-dimensional index, determine corresponding composite index.

Input format

Input data starts with an integer N — number of array dimensions.

Followed by N integers A_{j} — array sizes in each dimension.
Next are integer M and M query descriptions, one per line.
Queries are of two kinds:

Character f, followed by N integers
(i_{1}, i_{2}, …, i_{N}) — composite index.

Character b, followed by an integer — one-dimensional index.

Output format

Output must contain a sequence of integers — result of execution for each query
in the order of input.
Elements of composite indices must be sorted in ascending order.

Constraints

Indexing of both one-dimensional and multi-dimensional arrays starts with zero.