The grasshopper is located on the numeric axis at the point with coordinate $$$x_0$$$.Having nothing else to do he starts jumping between integer points on the axis. Making a jump from a point with coordinate $$$x$$$ with a distance $$$d$$$ to the left moves the grasshopper to a point with a coordinate $$$x - d$$$, while jumping to the right moves him to a point with a coordinate $$$x + d$$$.The grasshopper is very fond of positive integers, so for each integer $$$i$$$ starting with $$$1$$$ the following holds: exactly $$$i$$$ minutes after the start he makes a jump with a distance of exactly $$$i$$$. So, in the first minutes he jumps by $$$1$$$, then by $$$2$$$, and so on.The direction of a jump is determined as follows: if the point where the grasshopper was before the jump has an even coordinate, the grasshopper jumps to the left, otherwise he jumps to the right.For example, if after $$$18$$$ consecutive jumps he arrives at the point with a coordinate $$$7$$$, he will jump by a distance of $$$19$$$ to the right, since $$$7$$$ is an odd number, and will end up at a point $$$7 + 19 = 26$$$. Since $$$26$$$ is an even number, the next jump the grasshopper will make to the left by a distance of $$$20$$$, and it will move him to the point $$$26 - 20 = 6$$$.Find exactly which point the grasshopper will be at after exactly $$$n$$$ jumps.

The first line of input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$x_0$$$ ($$$-10^{14} \leq x_0 \leq 10^{14}$$$) and $$$n$$$ ($$$0 \leq n \leq 10^{14}$$$) — the coordinate of the grasshopper's initial position and the number of jumps.

Print exactly $$$t$$$ lines. On the $$$i$$$-th line print one integer — the answer to the $$$i$$$-th test case — the coordinate of the point the grasshopper will be at after making $$$n$$$ jumps from the point $$$x_0$$$.

NoteThe first two test cases in the example correspond to the first two jumps from the point $$$x_0 = 0$$$. Since $$$0$$$ is an even number, the first jump of length $$$1$$$ is made to the left, and the grasshopper ends up at the point $$$0 - 1 = -1$$$.Then, since $$$-1$$$ is an odd number, a jump of length $$$2$$$ is made to the right, bringing the grasshopper to the point with coordinate $$$-1 + 2 = 1$$$.

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let standardInputString = '';
let currentLine = 0;

process.stdin.on('data', (rawData) => {
  standardInputString += rawData;
});

process.stdin.on('end', () => {
  standardInputString = standardInputString
    .trim()
    .split('\n')
    .map((line) => {
      return line
        .split(' ')
        .map((char) =>
          Number(char) > -Infinity && Number(char) < Infinity
            ? Number(char)
            : char
        );
    });
  solveProblem();
});

const readLine = () => standardInputString[currentLine++];

const solveProblem = function () {
  const t = readLine()[0];
  for (let i = 0; i < t; i++) {
    const [x, n] = readLine();
    if (n % 4 === 0) console.log(x);
    else if ((n - 1) % 4 === 0) console.log(x % 2 === 0 ? x - n : x + n);
    else if ((n - 2) % 4 === 0) console.log(x % 2 === 0 ? x + 1 : x - 1);
    else if ((n - 3) % 4 === 0)
      console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);
  }
};

const solveProblem = function (problem) {
  for (let i = 0; i < problem.T; i++) {
    const [x, n] = problem.testCases[i];
    if (n % 4 === 0) {
      console.log(x);
    } else if ((n - 1) % 4 === 0) {
      console.log(x % 2 === 0 ? x - n : x + n);
    } else if ((n - 2) % 4 === 0) {
      console.log(x % 2 === 0 ? x + 1 : x - 1);
    } else if ((n - 3) % 4 === 0) {
      console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);
    }
  }
};

// -4 -3 -2 -1 0 1 2 3 4 5 6 7
//f

function readInput() {
  const readline = require('readline');
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false,
  });

  const problem = {
    T: 0,
    testCases: [],
    // testCase1: [],
    // testCase2: [],
  };

  let cursor = 1;

  rl.on('line', function (line) {
    // TODO: Process input
    if (cursor === 1) {
      // Get number of test cases from first line
      problem.T = +line;
      cursor++;
    } else {
      const [input1, input2] = line.split(' ');
      const input = [];

      input.push(+input1);
      input.push(+input2);
      problem.testCases.push(input);
      cursor++;
    }
  }).on('close', () => {
    // Finished processing input, now solve question
    solveProblem(problem);
    process.exit();
  });
}

readInput();

// cat input.txt | node app.js // Terminal command to run the code

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => BigInt(j)))
        main()
        process.exit(0)
    }
})

function solve([a, n]) {
    let sum = a
    for (let i = 1n; i <= n; i++) {
        sum += (sum % 2n === 0n ? -i : i)
        console.log(i,' ',sum)
    }
    console.log('s',sum)
}

function solve1([a, n]) {
    if (a % 2n === 0n) {
        switch (n % 4n) {
            case 1n: {
                console.log((-n + a).toString())
                break;
            }
            case 2n: {
                console.log((1n + a).toString())
                break;
            }
            case 3n: {
                console.log((n + 1n + a).toString())
                break;
            }
            case 0n: {
                console.log((a).toString())
                break;
            }
        }
    } else {
        switch (n % 4n) {
            case 1n: {
                console.log((n + a).toString())
                break;
            }
            case 2n: {
                console.log((a - 1n).toString())
                break;
            }
            case 3n: {
                console.log((-n + a - 1n).toString())
                break;
            }
            case 0n: {
                console.log((a).toString())
                break;
            }
        }
    }
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve1(inputArr[i])
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

function main(){
  let input = Number(readline().replace('\r',''));
  let output = [];
  for(let i=0; i<input; i++){
    let point = readline().replace('\r','').split(' ');
    output.push(position(Number(point[0]), Number(point[1])))
  }
  for(let j=0; j<output.length; j++){
    print(output[j])
  }
}

function position(x, jump){
  let j = jump - 1;
  if(x%2===0){

  if(j%4===1) {
  x = x + Math.floor(jump/4)*(-4) + (-1) + jump;
  }

  else if(j%4===2){
  x = x + (jump-1)*2 + Math.floor(jump/4)*(-4);
  }

  else if(j%4===3) {
  x = x;
  }

  else if(j%4===0){
  x = x + Math.floor(jump/4)*(-4) + (-1);
  }

  }

  else{

  if(j%4===1) {
  x = x + Math.floor(jump/4)*(4) + (1) + (-1)*jump;
  }

  else if(j%4===2){
  x = x + (jump-1)*(-2) + Math.floor(jump/4)*(4);
  }

  else if(j%4===3) {
  x = x;
  }

  else if(j%4===0){
  x = x + Math.floor(jump/4)*(4) + (1);
  }

  }

  return x;
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [x0, n] = rna();

		const k = n % 4;

		let ans = 0;
		if (k == 1) {
			ans = -n;
		} else if (k == 2) {
			ans = 1;
		} else if (k == 3) {
			ans = n + 1;
		}

		if (x0&1) ans = -ans;

		ans += x0;

		console.log(ans);
	}
}

var dataitr;
var stdin_input = "";
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { dataitr = stdin_input.split('\n').values(); main(); });

const rl = () => dataitr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let t = rn();
	while (t--) {
		let [x, n] = rna();

		let anss = [0, -n, 1, n + 1];

		let ans = (x % 2 ? -1 : 1) * anss[n % 4];

		console.log(x + ans);
	}
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var x = k[0], n = k[1];
        var v = [0, -n, 1, n + 1];
        var ans = (x % 2 ? -1 : 1) * v[n % 4];
        console.log(x + ans);
    }
});

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readLine() {
    return inputString[currentLine++];
}
/* let arr = readLine().split(" ").map((x) => {return parseInt(x)});
let test = readLine();
while(test--)
{

}
*/
function main() {
    let test = readLine();
while(test--)
{
    let arr = readLine().split(" ").map((x) => {return parseInt(x)});
    let x0 = arr[0];
    let n = arr[1];
    if (x0%2 == 0){
        if (n%4 == 0){
            console.log(x0);
        }
        else if (n%4==1){
            console.log(x0-n);
        }
        else if (n%4 == 2){
            console.log(x0+1);
        }
        else if (n%4 == 3){
            console.log(x0+1+n);
        }

    }
    else{
        if (n%4 == 0){
            console.log(x0);
        }
        else if (n%4==1){
            console.log(x0+n);
        }
        else if (n%4 == 2){
            console.log(x0-1);
        }
        else if (n%4 == 3){
            console.log(x0-1-n);
        }
    }

}
    return 0;
}

"use strict";
exports.__esModule = true;
var readline = require("readline");
var process = require("process");
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
var lines = [];
rl.on("line", function (line) {
    lines.push(line);
});
rl.on("close", function () {
    main();
});
function main() {
    for (var i = 1; i < lines.length; i++) {
        var fields = lines[i].split(" ");
        var x0 = parseInt(fields[0]);
        var n = parseInt(fields[1]);
        console.log(solve(x0, n));
    }
}
function jump(x, i) {
    if (x % 2 != 0) {
        x += i;
    }
    else {
        x -= i;
    }
    return x;
}
function solve(x0, n) {
    var i = 1;
    if (i < n) {
        i += Math.floor((n - i) / 4) * 4;
    }
    while (i <= n) {
        x0 = jump(x0, i);
        i++;
    }
    return x0;
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let [x,n]=readline().split(' ').map(Number);
        if(n==0)
        {
            console.log(x);
            continue;
        }
        let i = 1;
        let ans=0;
        if(n%4==1)
            ans=-n;
        else if(n%4==2)
            ans=1;
        else if(n%4==3)
            ans=n+1;
        if(Math.abs(x)%2==1)
            ans=-ans;
        console.log(ans+x);
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function gcd(a, b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
// let a=readline().split(' ').map(Number)
// a.sort((a,b)=>a-b)

function main() {
    let t = Number(readline())
    for (let j = 1; j <= t; j++) {
        let [x,n]=readline().split(' ').map(Number);
        if(n==0)
        {
            console.log(x);
            continue;
        }
        let i = 1;
        let ans=0;
        if(n%4==1)
            ans=-n;
        else if(n%4==2)
            ans=1;
        else if(n%4==3)
            ans=n+1;
        if(Math.abs(x)%2==1)
            ans=-ans;
        console.log(ans+x);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let standardInputString = '';
let currentLine = 0;

process.stdin.on('data', (rawData) => {
  standardInputString += rawData;
});

process.stdin.on('end', () => {
  standardInputString = standardInputString
    .trim()
    .split('\n')
    .map((line) => {
      return line
        .split(' ')
        .map((char) =>
          Number(char) > -Infinity && Number(char) < Infinity
            ? Number(char)
            : char
        );
    });
  solveProblem();
});

const readLine = () => standardInputString[currentLine++];

const solveProblem = function () {
  const t = readLine()[0];
  console.log(t);
  for (let i = 0; i < t; i++) {
    const [x, n] = readLine();
    if (n % 4 === 0) console.log(x);
    else if ((n - 1) % 4 === 0) console.log(x % 2 === 0 ? x - n : x + n);
    else if ((n - 2) % 4 === 0) console.log(x % 2 === 0 ? x + 1 : x - 1);
    else if ((n - 3) % 4 === 0)
      console.log(x % 2 === 0 ? x + 1 + n : x - 1 - n);
  }
};

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => BigInt(j)))
        main()
        process.exit(0)
    }
})

function solve([a, n]) {
    // let sum = a
    // for (let i = 1; i <= b; i++) {
    //
    //     sum += (sum % 2 === 0 ? -i : i)
    //     console.log(i,' ',sum)
    // }
    // console.log('s',sum)
    if (a % 2n === 0n) {
        switch (n % 4n) {
            case 1n: {
                console.log((-n+a).toString())
                break;
            }
            case 2n: {
                console.log((1n+a).toString())
                break;
            }
            case 3n: {
                console.log((n+1n+a).toString())
                break;
            }
            case 0n: {
                console.log((a).toString())
                break;
            }
        }
    } else {
        switch (n % 4n) {
            case 1n: {
                console.log((n+a).toString())
                break;
            }
            case 2n: {
                console.log((n-1n).toString())
                break;
            }
            case 3n: {
                console.log((-n+a-1n).toString())
                break;
            }
            case 0n: {
                console.log((a).toString())
                break;
            }
        }

    }
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([a, n]) {
    // let sum = a
    // for (let i = 1; i <= b; i++) {
    //
    //     sum += (sum % 2 === 0 ? -i : i)
    //     console.log(i,' ',sum)
    // }
    // console.log('s',sum)
    if (a % 2 === 0) {
        switch (n % 4) {
            case 1: {
                console.log(-n+a)
                break;
            }
            case 2: {
                console.log(1+a)
                break;
            }
            case 3: {
                console.log(n+1+a)
                break;
            }
            case 0: {
                console.log(a)
                break;
            }
        }
    } else {
        switch (n % 4) {
            case 1: {
                console.log(n+a)
                break;
            }
            case 2: {
                console.log(n-1)
                break;
            }
            case 3: {
                console.log(-n+a-1)
                break;
            }
            case 0: {
                console.log(a)
                break;
            }
        }

    }
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

function main(){
  let input = Number(readline().replace('\r',''));
  let output = [];
  for(let i=0; i<input; i++){
    let point = readline().replace('\r','').split(' ');
    output.push(position(Number(point[0]), Number(point[1])))
  }
  for(let j=0; j<output.length; j++){
    print(output[j])
  }
}

function position(x, jump){
  let m = 1;
  if(x%2===0){
  m = -1;
  }

  let j = jump - 1;

  if(j%4===1) {
  x = x + Math.floor(jump/4)*4*m + m + m*jump*m;
  }

  else if(j%4===2){
  x = x + (jump-1)*(-2)*m + Math.floor(jump/4)*4*m;
  }

  else if(j%4===3) {
  x = x;
  }

  else if(j%4===0){
  x = x + Math.floor(jump/4)*4*m + m;
  }

  return x;
}


You are an environmental activist at heart but the reality is harsh and you are just a cashier in a cinema. But you can still do something!You have $$$n$$$ tickets to sell. The price of the $$$i$$$-th ticket is $$$p_i$$$. As a teller, you have a possibility to select the order in which the tickets will be sold (i.e. a permutation of the tickets). You know that the cinema participates in two ecological restoration programs applying them to the order you chose:  The $$$x\%$$$ of the price of each the $$$a$$$-th sold ticket ($$$a$$$-th, $$$2a$$$-th, $$$3a$$$-th and so on) in the order you chose is aimed for research and spreading of renewable energy sources.  The $$$y\%$$$ of the price of each the $$$b$$$-th sold ticket ($$$b$$$-th, $$$2b$$$-th, $$$3b$$$-th and so on) in the order you chose is aimed for pollution abatement. If the ticket is in both programs then the $$$(x + y) \%$$$ are used for environmental activities. Also, it's known that all prices are multiples of $$$100$$$, so there is no need in any rounding.For example, if you'd like to sell tickets with prices $$$[400, 100, 300, 200]$$$ and the cinema pays $$$10\%$$$ of each $$$2$$$-nd sold ticket and $$$20\%$$$ of each $$$3$$$-rd sold ticket, then arranging them in order $$$[100, 200, 300, 400]$$$ will lead to contribution equal to $$$100 \cdot 0 + 200 \cdot 0.1 + 300 \cdot 0.2 + 400 \cdot 0.1 = 120$$$. But arranging them in order $$$[100, 300, 400, 200]$$$ will lead to $$$100 \cdot 0 + 300 \cdot 0.1 + 400 \cdot 0.2 + 200 \cdot 0.1 = 130$$$.Nature can't wait, so you decided to change the order of tickets in such a way, so that the total contribution to programs will reach at least $$$k$$$ in minimum number of sold tickets. Or say that it's impossible to do so. In other words, find the minimum number of tickets which are needed to be sold in order to earn at least $$$k$$$.

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 100$$$) — the number of independent queries. Each query consists of $$$5$$$ lines. The first line of each query contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of tickets. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$100 \le p_i \le 10^9$$$, $$$p_i \bmod 100 = 0$$$) — the corresponding prices of tickets. The third line contains two integers $$$x$$$ and $$$a$$$ ($$$1 \le x \le 100$$$, $$$x + y \le 100$$$, $$$1 \le a \le n$$$) — the parameters of the first program. The fourth line contains two integers $$$y$$$ and $$$b$$$ ($$$1 \le y \le 100$$$, $$$x + y \le 100$$$, $$$1 \le b \le n$$$) — the parameters of the second program. The fifth line contains single integer $$$k$$$ ($$$1 \le k \le 10^{14}$$$) — the required total contribution. It's guaranteed that the total number of tickets per test doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$q$$$ integers — one per query.  For each query, print the minimum number of tickets you need to sell to make the total ecological contribution of at least $$$k$$$ if you can sell tickets in any order. If the total contribution can not be achieved selling all the tickets, print $$$-1$$$.

NoteIn the first query the total contribution is equal to $$$50 + 49 = 99 < 100$$$, so it's impossible to gather enough money.In the second query you can rearrange tickets in a following way: $$$[100, 100, 200, 200, 100, 200, 100, 100]$$$ and the total contribution from the first $$$6$$$ tickets is equal to $$$100 \cdot 0 + 100 \cdot 0.1 + 200 \cdot 0.15 + 200 \cdot 0.1 + 100 \cdot 0 + 200 \cdot 0.25 = 10 + 30 + 20 + 50 = 110$$$.In the third query the full price of each ticket goes to the environmental activities.In the fourth query you can rearrange tickets as $$$[100, 200, 100, 100, 100]$$$ and the total contribution from the first $$$4$$$ tickets is $$$100 \cdot 0 + 200 \cdot 0.31 + 100 \cdot 0 + 100 \cdot 0.31 = 62 + 31 = 93$$$.

'use strict'

const gcd = (x, y) => { while(y) y = x % (x = y); return x; }
const lcm = (a, b) => a * b / gcd(a, b);

const bs = (n, p, a, x, b, y, r) => {
    p = [ 0, ...p, 0 ];
    for (let j=1; j<=n; j++) { p[j] += p[j-1]; }
    const c = lcm(a, b);
    const f = (j) => {
        const A = Math.floor(j/a);
        const B = Math.floor(j/b);
        const C = Math.floor(j/c);
        return p[C]*(x+y) + (p[B]-p[C])*y + (p[B+A-C]-p[B])*x >= r;
    }
    for (let j=1; j<=n; j++) { if (f(j)) return j; }
    return -1;
}

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const n = parseInt(readline());
    const p = readline().split(' ').map(x => x/100).sort((A, B) => B - A);
    const xa = readline().split(' ');
    let x = parseInt(xa[0]);
    let a = parseInt(xa[1]);
    const yb = readline().split(' ');
    let y = parseInt(yb[0]);
    let b = parseInt(yb[1]);
    if (x > y) {
      const z = x;
      const c = a;
      x = y; a = b;
      y = z; b = c;
    }
    const k = parseInt(readline());
    print(bs(n, p, a, x, b, y, k));
}

'use strict'

const q = parseInt(readline());
for (let i = 0; i < q; i++) {
  const n = parseInt(readline());
  const p = readline().split(' ').map(Number).sort((A, B) => B - A);
  const xa = readline().split(' ');
  let x = parseInt(xa[0]);
  let a = parseInt(xa[1]);
  const yb = readline().split(' ');
  let y = parseInt(yb[0]);
  let b = parseInt(yb[1]);
  if (x < y) {
    const z = x;
    const c = a;
    x = y; a = b;
    y = z; b = c;
  }
  const k = parseInt(readline());
  const fn = (N) => {
    const lx = Math.floor(N/a);
    const ly = Math.floor(N/b);
    const lxy = Math.floor(N/(a*b));
    const w = (chunk, ps) => chunk
      .reduce((r, i) => r + i*ps/100, 0);
    return w(p.slice(0, lxy), x + y)
      + w(p.slice(lxy, lxy + lx), x)
      + w(p.slice(lxy + lx, lxy + lx + ly), y);
  }
  let j = 0;
  let r = 0;
  while(r < k && ++j <= n) {
    if (j%a===0 || j%b===0) {
      r = fn(j);
    }
  }
  if (r < k) j = -1;
  write(j + '\n')
}

'use strict'

const gcd = (x, y) => { while(y) y = x % (x = y); return x; }
const lcm = (a, b) => a * b / gcd(a, b);

const bs = (n, p, a, x, b, y, r) => {
    for (let j=1; j<=n; j++) { p[j] += p[j-1]; }
    const c = lcm(a, b);
    const f = (j) => {
        const A = Math.floor(j/a);
        const B = Math.floor(j/b);
        const C = Math.floor(j/c);
        return r <= p[C]*(x+y) + (p[B]-p[C])*y + (p[B+A-C]-p[B])*x;
    }
    for (let j=1; j<=n; j++) { if (f(j)) return j; }
    return -1;
}

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const n = parseInt(readline());
    const p = readline().split(' ').map(Number).sort((A, B) => B - A);
    const xa = readline().split(' ');
    let x = parseInt(xa[0]);
    let a = parseInt(xa[1]);
    const yb = readline().split(' ');
    let y = parseInt(yb[0]);
    let b = parseInt(yb[1]);
    if (x < y) {
      const z = x;
      const c = a;
      x = y; a = b;
      y = z; b = c;
    }
    const k = parseInt(readline());
    print(bs(n, p, a, x, b, y, k));
}

'use strict'

const gcd = (x, y) => { while(y) y = x % (x = y); return x; }
const lcm = (a, b) => a * b / gcd(a, b);

const bs = (n, p, a, x, b, y, r) => {
    for (let j=1; j<=n; j++) { p[j] += p[j-1]; }
    const c = lcm(a, b);
    const f = (j) => {
        const A = Math.floor(j/a);
        const B = Math.floor(j/b);
        const C = Math.floor(j/c);
        return r <= p[C]*(x+y) + (p[B]-p[C])*y + (p[B+A-C]-p[B])*x;
    }
    for (let j=1; j<=n; j++) { if (f(j)) return j; }
    return -1;
}

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const n = parseInt(readline());
    const p = readline().split(' ').map(Number).sort((A, B) => B - A);
    const xa = readline().split(' ');
    let x = parseInt(xa[0]);
    let a = parseInt(xa[1]);
    const yb = readline().split(' ');
    let y = parseInt(yb[0]);
    let b = parseInt(yb[1]);
    if (x < y) {
      const z = x;
      const c = a;
      x = y; a = b;
      y = z; b = c;
    }
    const k = parseInt(readline());
    print(bs(n, p, a, x, b, x, k));
}


According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.  However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.Write a program that models the behavior of Ankh-Morpork residents.

NoteIn the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = +readline();
  const a = readline().split(' ').map(x => parseInt(x));
  const b = new Array(n).fill(['']);
  let max = 0;
  for (let i = n - 1; i >= 0; i--) {
    if (a[i] > max) {
      b[i] = range(a[i], max);
      max = a[i];
    }
  }
  for (let i = 0; i < n; i++) {
    print(b[i].join(' ') + '\n');
  }
}
function range(hi, lo) {
  const a = [];
  while (hi > lo) {
    a.push(hi--);
  }
  return a;
}

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    snackTower(inputString[0], inputString[1]);
});

function snackTower(numberOfSnacks, snacks) {

    let outputArray = [];
    let snacksFrequencyArray = [];
    let currentMax = numberOfSnacks;
    snacks = snacks.split(" ");

    for(let index = 0 ; index < numberOfSnacks ; index++){

        snacksFrequencyArray[snacks[index]] = 1

        while (snacksFrequencyArray[currentMax]) {
            outputArray.push(currentMax);
            outputArray.push(" ")
            currentMax--;
        }

        outputArray.push("\n");
    }
    console.log(outputArray.join(""));
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}

function array2d(r,c) {
    let ans =[];
    for(let i = 0; i < r; i++) {
        let rowElements = [];
        for(let j = 0; j < c; j++) {
            rowElements.push(0);
        }
        ans.push(rowElements);
    }
    return ans;
}
function max(a,b){
    if(a > b) return a;
    else return b;
}
function main() {
    let [n] = readint();
    let s = readint();
    let has = [...s];
    has.fill(0);
    let curr =  n - 1;
    s.forEach(element => {
        has[element - 1] = 1;
        if(element - 1 == curr) {
            const begin = curr;
            for(let i = begin; i >=0; i--) {
                if(has[i]) {
                    write((i + 1) + " ");
                    curr--;
                }
                else break;
            }
            console.log();
        } else console.log();
    });
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let input = [];
readline.on('line', line => {
  input.push(line);
});
process.stdin.on('end', () => {
const n = parseInt(input[0], 10);
let secondLine = input[1].split(' ');
secondLine = secondLine.map((a) => parseInt(a, 10));
let expected = n;
const reserve = {};
let text = '';

for (let i=0; i<n; i++) {
  const size = secondLine[i];
  if (size === expected) {
    let line = size.toString();
    expected --;
    while (reserve[expected]) {
      line += ` ${expected}`;
      delete reserve[expected];
      expected --;
    }
    text += line;
  } else {
    reserve[size] = true;
  }
  text += '\n';
}
  console.log(text);
});

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    var snacksArr = new Array(20000);
    var largest = n;
    var str = '';
    snacks = snacks.split(' ');
    for(let i = 0; i < n; i++){
        var size = snacks[i];
        snacksArr[size] = 1;
        while(snacksArr[largest]){
            str = str + " " + largest--;
        }
        if(str){
            console.log(str);
            str = '';
        }
        else{
        console.log('');

        }

    }
}

// snackTower('10', '5 1 6 2 8 3 4 10 9 7')

var numberOfDays = Number(readline())
  var snaksPerDays = readline().split(' ').map(Number)

  var snacks = new Array(numberOfDays).fill(0)

  var index = numberOfDays
  for (var i = 0; i < numberOfDays; i++) {
    snacks[snaksPerDays[i] - 1] = 1

    var stack = []
    while(snacks[index - 1]) {
      stack.push(index)
      index -= 1
    }

    print(stack.join(' '))
  }

/*
    The idea to solve this problem is to seek whether the biggest remaining snacks has fall on that day or not,
    if the bigger snacks has fall, print them, otherwise print empty line.

    We could know the biggest remaining snack by exploiting the fact that the size of the snack given
    will be always 1..n
*/

var n = parseInt(readline());
var sizes = readline().split(' ').map(Number);
var current_max = n;

var has_fall = []; // hash table containing whether certain size snack has fall or not
var tmp = []; // temp array for printing single line by using print() in js

for(var i = 0; i < n; i++) {

    var size = sizes[i];
    has_fall[size] = 1;

    // exploiting the fact that size will be always 1..n
    while(has_fall[current_max] === 1) {

        tmp.push(current_max);
        current_max--; // we could know the next biggest remaining snack size is this
    }

    print(tmp.join(' '));
    tmp = [];
}

"use strict";

var _slicedToArray = (function() {
  function sliceIterator(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
    try {
      for (
        var _i = arr[Symbol.iterator](), _s;
        !(_n = (_s = _i.next()).done);
        _n = true
      ) {
        _arr.push(_s.value);
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"]) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
  return function(arr, i) {
    if (Array.isArray(arr)) {
      return arr;
    } else if (Symbol.iterator in Object(arr)) {
      return sliceIterator(arr, i);
    } else {
      throw new TypeError(
        "Invalid attempt to destructure non-iterable instance"
      );
    }
  };
})();

var compose = function compose() {
  for (
    var _len = arguments.length, functions = Array(_len), _key = 0;
    _key < _len;
    _key++
  ) {
    functions[_key] = arguments[_key];
  }

  return function() {
    for (
      var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
      _key2 < _len2;
      _key2++
    ) {
      args[_key2] = arguments[_key2];
    }

    return functions.reduce(function(currArgs, func) {
      return func(currArgs);
    }, args);
  };
};

var lineToStringArray = function lineToStringArray(str) {
  return str.split(" ");
};
var lineToNumberArray = function lineToNumberArray(str) {
  return lineToStringArray(str).map(function(num) {
    return parseInt(num, 10);
  });
};

var readNumbersLine = compose(
  readline,
  lineToNumberArray
);
var readStringsLine = compose(
  readline,
  lineToStringArray
);

var _readNumbersLine = readNumbersLine(),
  _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),
  n = _readNumbersLine2[0];

var elements = readNumbersLine();
var needed = n;
var currElements = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (
    var _iterator = elements[Symbol.iterator](), _step;
    !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
    _iteratorNormalCompletion = true
  ) {
    var curr = _step.value;

    currElements[curr] = true;
    if (curr !== needed) {
      print("");
      continue;
    }
    var res = [];
    while (currElements[needed]) {
      res.push(needed);
      needed--;
    }
    print(res.join(" "));
  }
} catch (err) {
  _didIteratorError = true;
  _iteratorError = err;
} finally {
  try {
    if (!_iteratorNormalCompletion && _iterator.return) {
      _iterator.return();
    }
  } finally {
    if (_didIteratorError) {
      throw _iteratorError;
    }
  }
}

var expect = parseInt(readline());
var vals = readline().split(" ").map(Number);
var temp = {};
var res = [];

for (var i = 0; i < vals.length; i++) {
    temp[vals[i]] = true;

    if (expect in temp) {
        while (expect in temp) {
            res.push(expect);
            delete temp.expect;
            expect = expect - 1;
        }

        print(res.join(" "));
        res = [];
    } else {
        print(" ");
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = +readline();
  const a = readline().split(' ').map(x => parseInt(x));
  let next = n;
  let t = [];
  for (let i = 0; i < n; i++) {
    t.unshift(a[i]);
    if (a[i] === next) {
      print(t.join(' '));
      next = t[t.length - 1] - 1;
      t = [];
    }
    print('\n');
  }
}

/**
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune,
and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city,
and the residents should build a Snacktower of them by placing snacks one on another. Of course,
big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So,
at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.
Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.

Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day
in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

*/

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    snackTower(inputString[0], inputString[1]);
});

function readline() {
    return inputString[currentLine++];
}

function snackTower(numberOfSnacks, snacks) {

    let outputArray = [];
    snacks = snacks.split(" ");
    let frequencyMap = {};
    let outputArrayFrequencyMap = {};
    let currentMax = numberOfSnacks;
    let frequencyMapIndexs = {};
    let lastMax;
    let notSeen = {};

    for (let index = 0; index < numberOfSnacks; index++) {
        notSeen[snacks[index]] = 1
    }

    for (let index = 0; index < numberOfSnacks; index++) {

        delete notSeen[snacks[index]];

        if (snacks[index] == currentMax) {

            outputArray.push(snacks[index]);
            frequencyMapIndexs[snacks[index]] = outputArray.length - 1
            outputArray.push(" ");
            let notSeenKeys = Object.keys(notSeen)
            lastMax = currentMax;
            currentMax = notSeenKeys[notSeenKeys.length - 1];
            frequencyMap[lastMax] = currentMax ? currentMax : 0;
            snacks[index] = 0;
        }

        if (snacks[index] != currentMax && !frequencyMap[currentMax]) {

            if (index != numberOfSnacks - 1)
                outputArray.push("\n");
        }

    }

    for (let index = 0; index < outputArray.length; index++) {
        if (outputArray[index] != "\n" && outputArray[index] != " ") {
            outputArrayFrequencyMap[outputArray[index]] = index;
        }
    }

    let frequencyMapKeys = Object.keys(frequencyMap);

    for (let indexKey = frequencyMapKeys.length - 1; indexKey > -1; indexKey--) {

        for (let index = frequencyMapKeys[indexKey] - 1; index > frequencyMap[frequencyMapKeys[indexKey]]; index--) {
            outputArray.splice(outputArray.indexOf(frequencyMapKeys[indexKey]) + 1, 0, " " + index)
            //    pushArrayAfterMax.push(" ")
            //  pushArrayAfterMax.push(index)
        }
    }
    //    frequencyMap[key] = pushArrayAfterMax;
    //  pushArrayAfterMax = []

    // let frequencyMapIndexsKeys = Object.keys(frequencyMapIndexs)

    // for (let index = frequencyMapIndexsKeys.length - 1; index > -1; index--) {

    //     outputArray.splice(outputArray.indexOf(frequencyMapIndexsKeys[index]) + 1, 0, ...frequencyMap[frequencyMapIndexsKeys[index]]);
    // }

    console.log(outputArray.join(""));

}

/**
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune,
and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city,
and the residents should build a Snacktower of them by placing snacks one on another. Of course,
big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So,
at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.
Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.

Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day
in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

*/

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    snackTower(inputString[0], inputString[1]);
});

function readline() {
    return inputString[currentLine++];
}

function snackTower(numberOfSnacks, snacks) {

    let outputArray = [];
    snacks = snacks.split(" ");
    let frequencyMap = {};
    let currentMax = numberOfSnacks;

    for (let index = 0; index < numberOfSnacks; index++) {

        if (Number(snacks[index]) == currentMax) {

            outputArray.push(snacks[index]);
            outputArray.push(" ");
            currentMax--;
        }

        if (frequencyMap[currentMax]) {

            outputArray.push(frequencyMap[currentMax]);
            outputArray.push(" ");
            currentMax--;
        }

        if (Number(snacks[index]) != currentMax && !frequencyMap[currentMax]) {

            if (index != numberOfSnacks - 1)
                outputArray.push("\n");

            frequencyMap[snacks[index]] = snacks[index];
        }

    }

    for (let index = 0; index < outputArray.length; index++) {
        if (frequencyMap[outputArray[index]])
            delete frequencyMap[outputArray[index]]
    }

    Object.keys(frequencyMap).forEach(key => {
        outputArray.push(frequencyMap[key]);
    });

    console.log(outputArray.join(""));

}

/**
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune,
and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city,
and the residents should build a Snacktower of them by placing snacks one on another. Of course,
big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So,
at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.
Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.

Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day
in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

*/

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    snackTower(inputString[0], inputString[1]);
});

function readline() {
    return inputString[currentLine++];
}

function snackTower(numberOfSnacks, snacks) {

    let outputArray = [];
    snacks = snacks.split(" ");
    let frequencyMap = {};
    let currentMax = numberOfSnacks;

    for (let index = 0; index < numberOfSnacks; index++) {

        if (Number(snacks[index]) == currentMax) {

            outputArray.push(snacks[index]);
            outputArray.push(" ");
            currentMax--;
        }

        if (frequencyMap[currentMax]) {

            outputArray.push(frequencyMap[currentMax]);
            outputArray.push(" ");
            currentMax--;
        }

        if (Number(snacks[index]) != currentMax && !frequencyMap[currentMax]) {

            if (index != numberOfSnacks - 1)
                outputArray.push("\n");

            frequencyMap[snacks[index]] = snacks[index];
        }

    }

    for (let index = 0; index < outputArray.length; index++) {
        if (frequencyMap[outputArray[index]])
            delete frequencyMap[outputArray[index]]
    }

    let frequencyMapKeys = Object.keys(frequencyMap)

    for (let index = frequencyMapKeys.length - 1; index > -1; index--) {

        if (index != frequencyMapKeys.length - 1) {
            outputArray.push(" ");
        }

        outputArray.push(frequencyMap[frequencyMapKeys[index]]);
    }

    console.log(outputArray.join(""));

}

/**
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune,
and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city,
and the residents should build a Snacktower of them by placing snacks one on another. Of course,
big snacks should be at the bottom of the tower, while small snacks should be at the top.

Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.

However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So,
at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell.
Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.

Write a program that models the behavior of Ankh-Morpork residents.

Input
The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks.

The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Output
Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day
in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

*/

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    snackTower(inputString[0], inputString[1]);
});

function readline() {
    return inputString[currentLine++];
}

function snackTower(numberOfSnacks, snacks) {

    let outputArray = [];
    snacks = snacks.split(" ");
    let frequencyMap = {};
    let currentMax = numberOfSnacks;
    let lastMax;
    let notSeen = {};

    for (let index = 0; index < numberOfSnacks; index++) {
        notSeen[snacks[index]] = 1
    }

    for (let index = 0; index < numberOfSnacks; index++) {

        delete notSeen[snacks[index]];

        if (snacks[index] == currentMax) {

            outputArray.push(snacks[index]);
            outputArray.push(" ");
            let notSeenKeys = Object.keys(notSeen)
            lastMax = currentMax;
            currentMax = notSeenKeys[notSeenKeys.length - 1];
            for(let index = lastMax -1 ; index > currentMax ; index--){
                outputArray.push(index);
                outputArray.push(" ");
            }
            snacks[index] = 0;

        }

        if (snacks[index] != currentMax && !frequencyMap[currentMax]) {

            if (index != numberOfSnacks - 1)
                outputArray.push("\n");

            //   frequencyMap[snacks[index]] = snacks[index];
        }

    }

    console.log(outputArray.join(""));

}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}

function array2d(r,c) {
    let ans =[];
    for(let i = 0; i < r; i++) {
        let rowElements = [];
        for(let j = 0; j < c; j++) {
            rowElements.push(0);
        }
        ans.push(rowElements);
    }
    return ans;
}
function max(a,b){
    if(a > b) return a;
    else return b;
}
function main() {
    let [n] = readint();
    let s = readint();
    let has = [...s];
    has.fill(0);
    let curr =  n - 1;
    s.forEach(element => {
        has[element - 1] = 1;
        if(element - 1 == curr) {
            const begin = curr;
            for(let i = begin; i >=0; i--) {
                if(has[i]) {
                    write((i + 1) + " ");
                    curr--;
                }
                else break;
            }
            console.log();
        }
    });
}

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    n = parseInt(n)
    // snacks = snacks.toString();
    // snacks = snacks.split(' ')
    var display = {};
    var delayed = new Array(n);
    var newDelayed = new Array(n);
    newDelayed.fill('');
    delayed.fill('');
    var delayedNumber = n;
    for (let i = 0; i < n; i++) {
        var num = n - i;
        if (snacks[i] != delayedNumber) {
            display[i] = '\n';
            console.log("\n");
            var delayedIndex = delayed.length - snacks[i];
            delayed[delayedIndex] = snacks[i];
            display[i + 1] = { queue: delayed };
        }
        else if (snacks[i] == delayedNumber) {
            var newArr = new Array(delayedNumber);
            var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;
            var delayedNumberToDsiplayIndex = delayed.length - snacks[i];
            if (lastDisplayedIndex)
                display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];
            else {
                var delayedIndex = delayed.length - snacks[i];
                delayed[delayedIndex] = snacks[i];
                display[lastDisplayedIndex] = { queue: delayed };
            }
            newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1)
           var str = JSON.stringify(newArr);
           str = str.replace(/,/g,' ')
           str = str.replace(/"/g,' ')
           str = str.replace('[',' ')
           str = str.replace(']',' ')
            console.log(str);
            delayed = newDelayed;
            delayedNumber = num - 1;

        }
    }
    return 0;
}
// snackTower('3', [3,1,2])

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    var snacksArr = new Array(20000);
    var largest = n;
    snacks = snacks.split(' ');
    for(let i = 0; i < n; i++){
        var size = snacks[i];
        snacksArr[size] = 1;
        while(snacksArr[largest]){
            console.log(largest--);
        }
        console.log('');
    }
}

// snackTower('10', '5 1 6 2 8 3 4 10 9 7')

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    n = parseInt(n)
    snacks = snacks.toString();
    snacks = snacks.split(' ')
    var display = {};
    var delayed = new Array(n);
    var newDelayed = new Array(n);
    newDelayed.fill('');
    delayed.fill('');
    var delayedNumber = n;
    for (let i = 0; i < n; i++) {
        var num = n - i;
        if (snacks[i] != delayedNumber) {
            display[i] = '\n';
            console.log("\n");
            var delayedIndex = delayed.length - snacks[i];
            delayed[delayedIndex] = snacks[i];
            display[i + 1] = { queue: delayed };
        }
        else if (snacks[i] == delayedNumber) {
            var newArr = new Array(delayedNumber);
            var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;
            var delayedNumberToDsiplayIndex = delayed.length - snacks[i];
            if (lastDisplayedIndex)
                display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];
            else {
                var delayedIndex = delayed.length - snacks[i];
                delayed[delayedIndex] = snacks[i];
                display[lastDisplayedIndex] = { queue: delayed };
            }
            newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1)
           var str = JSON.stringify(newArr);
           str = str.replace(/,/g,' ')
           str = str.replace(/"/g,' ')
           str = str.replace('[',' ')
           str = str.replace(']',' ')
            console.log(str);
            delayed = newDelayed;
            delayedNumber = num - 1;

        }
    }
    return 0;
}
// snackTower('3', [3,1,2])

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    var snacksArr = new Array(20000);
    var largest = n;
    snacks = snacks.split(' ');
    for(let i = 0; i < n; i++){
        var size = snacks[i];
        snacksArr[size] = 1;
        while(snacksArr[largest]){
            console.log(largest--);
        }
        console.log('');
    }
}

snackTower('10', '5 1 6 2 8 3 4 10 9 7')

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    n = parseInt(n)
    snacks = snacks.toString();
    snacks = snacks.split(' ')
    var display = {};
    var delayed = new Array(n);
    var newDelayed = new Array(n);
    newDelayed.fill('');
    delayed.fill('');
    var delayedNumber = n;
    for (let i = 0; i < n; i++) {
        var num = n - i;
        if (snacks[i] != delayedNumber) {
            display[i] = '0';
            // console.log("i");

            console.log('');
            var delayedIndex = delayed.length - snacks[i];
            delayed[delayedIndex] = snacks[i];
            display[i + 1] = { queue: delayed };
        }
        else if (snacks[i] == delayedNumber) {
            var newArr = new Array(delayedNumber);
            var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;
            var delayedNumberToDsiplayIndex = delayed.length - snacks[i];
            if (lastDisplayedIndex)
                display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];
            else {
                var delayedIndex = delayed.length - snacks[i];
                delayed[delayedIndex] = snacks[i];
                display[lastDisplayedIndex] = { queue: delayed };
            }
            newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1)
           var str = JSON.stringify(newArr);
           str = str.replace(/,/g,' ')
           str = str.replace(/"/g,'')
           str = str.replace('[','')
           str = str.replace(']','')
            console.log(str);
            delayed = newDelayed;
            delayedNumber = num - 1;

        }
    }
    return 0;
}

// snackTower('3', '3 1 2')

'use strict';

let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    snackTower(inputString[0], inputString[1]);
});
function snackTower(n, snacks) {
    n = parseInt(n)
    snacks = snacks.toString();
    snacks = snacks.split(' ')
    var display = {};
    var delayed = new Array(n);
    var newDelayed = new Array(n);
    newDelayed.fill('');
    delayed.fill('');
    var delayedNumber = n;
    for (let i = 0; i < n; i++) {
        var num = n - i;
        if (snacks[i] != delayedNumber) {
            display[i] = '\n';
            console.log("\n");
            var delayedIndex = delayed.length - snacks[i];
            delayed[delayedIndex] = snacks[i];
            display[i + 1] = { queue: delayed };
        }
        else if (snacks[i] == delayedNumber) {
            var newArr = new Array(delayedNumber);
            var lastDisplayedIndex = Object.keys(display).length ? Object.keys(display).length - 1 : 0;
            var delayedNumberToDsiplayIndex = delayed.length - snacks[i];
            if (lastDisplayedIndex)
                display[lastDisplayedIndex].queue[delayedNumberToDsiplayIndex] = snacks[i];
            else {
                var delayedIndex = delayed.length - snacks[i];
                delayed[delayedIndex] = snacks[i];
                display[lastDisplayedIndex] = { queue: delayed };
            }
            newArr = display[lastDisplayedIndex].queue.slice(delayed.length - delayedNumber,n - num +1)
           var str = JSON.stringify(newArr);
           str = str.replace(/,/g,' ')
           str = str.replace(/"/g,'')
           str = str.replace('[','')
           str = str.replace(']','')
            console.log(str);
            delayed = newDelayed;
            delayedNumber = num - 1;

        }
    }
    return 0;
}
// snackTower('3', '3 1 2')

var numberOfDays = Number(readline())
  var snaksPerDays = readline().split(' ').map(Number)

  var snacks = new Array(numberOfDays).fill(0)

  var index = numberOfDays
  for (var i = 0; i < numberOfDays; i++) {
    snacks[snaksPerDays[i] - 1] = 1

    var stack = []
    while(snacks[index - 1]) {
      stack.push(index)
      index -= 1
    }

    print(stack.reverse().join(' '))
  }

 var numberOfDays = Number(readline())
  var snaksPerDays = readline().split(' ').map(Number)

  var lookingFor = numberOfDays
  var stack = []
  var result = new Array(numberOfDays).fill("")
  for (var i = 0; i < numberOfDays; i++) {
    stack.push(snaksPerDays[i])

    if (snaksPerDays[i] === lookingFor) {
      result[i] = stack.reverse().join(' ')
      lookingFor -= stack.length
      stack = []
    }
  }

  for (var i = 0; i < numberOfDays; i++) {
    print(result[i])
  }

var n = parseInt(readline()),
    snacks = readline().split(' ').map(Number),
    snacks_ordered = JSON.parse(JSON.stringify(snacks)).sort(function(a, b){ return b - a }),
    tmp = [];

while(snacks_ordered.length > 0 && snacks.length > 0) {

    var current_max = snacks_ordered.shift();
    if(snacks.indexOf(current_max) !== -1) {

        while(snacks[0] !== current_max) {

            tmp.push(snacks.shift())
            print('');
        }

        tmp.push(snacks.shift()); // push current_max
        tmp.sort(function(a, b){ return b - a });

        print(tmp.join(' '));
        tmp = [];
    }
}

var expect = parseInt(readline());
var vals = readline().split(" ").map(Number);
var temp = [];

for (var i = 0; i < vals.length; i++) {
    temp.push(vals[i]);
    if (vals[i] === expect) {
        temp = temp.sort((a, b) => b - a);
        expect = temp[temp.length - 1] - 1;
        print(temp.join(" "));
        temp = [];
    } else {
        print(" ");
    }
}


Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")".Sereja needs to answer m queries, each of them is described by two integers li, ri (1 ≤ li ≤ ri ≤ n). The answer to the i-th query is the length of the maximum correct bracket subsequence of sequence sli, sli + 1, ..., sri. Help Sereja answer all queries.You can find the definitions for a subsequence and a correct bracket sequence in the notes.

The first line contains a sequence of characters s1, s2, ..., sn (1 ≤ n ≤ 106) without any spaces. Each character is either a "(" or a ")". The second line contains integer m (1 ≤ m ≤ 105) — the number of queries. Each of the next m lines contains a pair of integers. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n) — the description of the i-th query.

Print the answer to each question on a single line. Print the answers in the order they go in the input.

NoteA subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|).A correct bracket sequence is a bracket sequence that can be transformed into a correct aryphmetic expression by inserting characters "1" and "+" between the characters of the string. For example, bracket sequences "()()", "(())" are correct (the resulting expressions "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.For the third query required sequence will be «()».For the fourth query required sequence will be «()(())(())».

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let s = $(), n = s.length;
  let n2 = 1 << Math.ceil(Math.log2(n));
  let it = Array(n2 * 2);
  For(n2, n2 + n2 - 1, i => {
    it[i] = {
      opt: 0,
      open: s[i - n2] == '(' ? 1 : 0,
      close: s[i - n2] == ')' ? 1 : 0,
    }
  })
  // log(it)
  let merge = (l, r) => {
    let m = min(l.open, r.close)
    return {
      opt: l.opt + r.opt + m,
      open: l.open + r.open - m,
      close: l.close + r.close - m
    }
  }
  ForR(n2 - 1, 1, i => { it[i] = merge(it[i << 1], it[i << 1 | 1]) })
  // log(it)
  let query = (l, r) => {  //[l, r)
    let r1 = { opt: 0, open: 0, close: 0 };
    let r2 = { opt: 0, open: 0, close: 0 };
    for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {
      // log(res, l, r)
      if (l & 1) r1 = merge(r1, it[l++])
      // log(res)
      if (r & 1) r2 = merge(it[--r], r2)
      // log(res)
    }
    return merge(r1, r2);
  }
  let q = $(), l, r
  while (q--) {
    l = +$();
    r = +$();
    out.push(query(l - 1, r).opt * 2)
  }
  log(out.join('\n'))
}

var cad;
var Base;
var T;
function nodo(car){
    if(car){
        if(car=="("){
            this.I = 0;
            this.D = 1;
            }
        else {
            this.I = 1;
            this.D = 0;
            }
        this.mx = 0;
    }
    else {
        this.I = 0;
        this.D = 0;
        this.mx = 0;
    }
}
nodo.prototype.merge = function(a,b){
    var tmp = Math.min(a.D,b.I);
    this.mx = a.mx + b.mx + tmp;
    this.I = a.I+b.I-tmp;
    this.D = a.D+b.D-tmp;
}

function init(id,L,R){
    if(L==R) T[id] = new nodo(cad.charAt(L));
    else {
        var a = id<<1;
        var M = (L+R)>>1;
        init(a,L,M);
        init(a|1,M+1,R);
        T[id] = new nodo();
        T[id].merge(T[a],T[a|1]);
    }
}
var I,J;
function query(id, L, R){
    if(I<=L && R<=J){
	//	print("ans",L,R);
        return T[id];
        }
    else {
        var a = id<<1;
        var M = (L+R)>>1;
        if(J<=M) return query(a,L,M);
        else if(I>M) return query(a|1,M+1,R);
        else {
            var ans = new nodo();
            ans.merge(query(a,L,M),query(a|1,M+1,R));
            return ans;
        }
    }
}
function calc(sz){
	sz--;
//	print("es "+sz);
	var p = 1;
	while(p<=sz){
		p<<=1;
//  print(p);
	}
	return p<<1;
}
function main() {
	cad = next();
	var n = nextInt();
	//print(cad);
	//print(n);
	Base = new Array(cad.length+1);
	T = new Array(calc(cad.length));
	//var x = new nodo(cad.charAt(0));
	//print(x.I,x.D,x.mx);
	//print("antes");
	//print(cad.length-1);
	init(1,0,cad.length-1);

    //print("desp");
    for(var i = 0;i < n;i++){
       I = nextInt();
       //print(" I "+I);
       J = nextInt();
      // print(" * "+I+" "+J);

       I--;
       J--;
       print(query(1,0,cad.length-1).mx*2);
    }
}

var tokens = [];
var tokenPos = 0;
function next(){
    //print(tokenPos," >=", tokens.length);
	while(tokenPos >= tokens.length){
		tokens =  readline().split(/[\s]+/);
		tokenPos = 0;
		}
	//	print("lei",tokens);
	//print("es ",tokens);
//	print("retornare "+tokens[tokenPos]+"   pos "+tokenPos);
	return tokens[tokenPos++];
	}
function nextInt(){
	return parseInt(next());
}
main();

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn, init) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
  if (b < a) return [];
  let arr = Array(b - a + 1).fill(0);
  if (init) init(arr);
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return mid;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  let sub = [];
  a = a || 0;
  b = b || (this.length - 1);
  for (let i = a; i <= b; i++) {
    sub.push(this[i])
    if (fn(this[i], i, this)) {
      arr.push(sub);
      sub = [];
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
let MOD = 998244353
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + MOD) % MOD;
}

// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let time = Date.now();
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, min = Math.min, max = Math.max, abs = Math.abs;
  let s = $(), n = s.length;
  let n2 = 1 << Math.ceil(Math.log2(n));
  let it = Array(n2 * 2);
  For(n2, n2 + n2 - 1, i => {
    it[i] = {
      opt: 0,
      open: s[i - n2] == '(' ? 1 : 0,
      close: s[i - n2] == ')' ? 1 : 0,
    }
  })
  // log(it)
  let merge = (l, r) => {
    let m = min(l.open, r.close)
    return {
      opt: l.opt + r.opt + m,
      open: l.open + r.open - m,
      close: l.close + r.close - m
    }
  }
  ForR(n2 - 1, 1, i => { it[i] = merge(it[i << 1], it[i << 1 | 1]) })
  // log(it)
  let query = (l, r) => {  //[l, r)
    let res = { opt: 0, open: 0, close: 0 };
    for (l += n2, r += n2; l < r; l >>= 1, r >>= 1) {
      // log(res, l, r)
      if (l & 1) res = merge(res, it[l++])
      // log(res)
      if (r & 1) res = merge(res, it[--r])
      // log(res)
    }
    return res;
  }
  let q = $(), l, r
  while (q--) {
    l = +$();
    r = +$();
    out.push(query(l - 1, r).opt * 2)
  }
  log(out.join('\n'))
}


You are given a sequence of $$$n$$$ digits $$$d_1d_2 \dots d_{n}$$$. You need to paint all the digits in two colors so that:  each digit is painted either in the color $$$1$$$ or in the color $$$2$$$;  if you write in a row from left to right all the digits painted in the color $$$1$$$, and then after them all the digits painted in the color $$$2$$$, then the resulting sequence of $$$n$$$ digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit). For example, for the sequence $$$d=914$$$ the only valid coloring is $$$211$$$ (paint in the color $$$1$$$ two last digits, paint in the color $$$2$$$ the first digit). But $$$122$$$ is not a valid coloring ($$$9$$$ concatenated with $$$14$$$ is not a non-decreasing sequence).It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases in the input. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the length of a given sequence of digits. The next line contains a sequence of $$$n$$$ digits $$$d_1d_2 \dots d_{n}$$$ ($$$0 \le d_i \le 9$$$). The digits are written in a row without spaces or any other separators. The sequence can start with 0. It is guaranteed that the sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$2\cdot10^5$$$.

Print $$$t$$$ lines — the answers to each of the test cases in the input. If there is a solution for a test case, the corresponding output line should contain any of the valid colorings written as a string of $$$n$$$ digits $$$t_1t_2 \dots t_n$$$ ($$$1 \le t_i \le 2$$$), where $$$t_i$$$ is the color the $$$i$$$-th digit is painted in. If there are several feasible solutions, print any of them. If there is no solution, then the corresponding output line should contain a single character '-' (the minus sign).

NoteIn the first test case, $$$d=040425524644$$$. The output $$$t=121212211211$$$ is correct because $$$0022444$$$ (painted in $$$1$$$) concatenated with $$$44556$$$ (painted in $$$2$$$) is $$$002244444556$$$ which is a sorted sequence of $$$n$$$ given digits.

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split('').map(function (value) {
    return parseInt(value);
  });
};

function coloredSequences(seq) {
  var coloredSequences = [];

  for (var i = 0; i < 10; i++) {
    var coloredSequence = [];
    var p = 2;

    for (var j = 0; j < seq.length; j++) {
      if (seq[j] < i) {
        coloredSequence.push(1);
      } else if (seq[j] > i) {
        p = 1;
        coloredSequence.push(2);
      } else {
        coloredSequence.push(p);
      }
    }

    coloredSequences.push(coloredSequence);
  }

  return coloredSequences;
}

function rightColoredSequence(coloredSequences, seq) {
  for (var i = 0; i < coloredSequences.length; i++) {
    var color1Element = -1;
    var color2Element = -1;
    var right = true;
    var coloredSequence = coloredSequences[i];

    for (var j = 0; j < seq.length; j++) {
      if (coloredSequence[j] === 1) {
        if (seq[j] >= color1Element) {
          color1Element = seq[j];
        } else {
          right = false;
          break;
        }
      } else {
        if (seq[j] >= color2Element) {
          color2Element = seq[j];
        } else {
          right = false;
          break;
        }
      }
    }

    if (right) {
      return coloredSequence;
    }
  }

  return undefined;
}

function solve() {
  var length = parseInt(readline());
  var sequence = readline().getNumArray();
  var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);

  if (rightSequence === undefined) {
    write('-\n');
  } else {
    write(rightSequence.join('') + '\n');
  }
}

var n = parseInt(readline());

for (var i = 0; i < n; i++) {
  solve();
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var t = rdN();
    loop:while (t --> 0) {
        var n = rdN();
        var D = rdS().split('').map((v, i) => ({v: v, i: i})).sort((a,b) => {
            if (a.v != b.v) {
                return a.v - b.v;
            }
            return a.i - b.i;
        });
        //prOb(D)

        var res = crAr(n);
        var last = -1;
        var color = 1;
        var firstMissed = null;
        for (var i = 0; i < n; ++i) {
            var value = D[i].v;
            var index = D[i].i;
            if (index > last && (!firstMissed || firstMissed >= value)) {
                res[index] = color;
                last = index;
            } else if (!firstMissed) {
                firstMissed = value;
            }
        }
        var last = -1;
        var color = 2;
        for (var i = 0; i < n; ++i) {
            var value = D[i].v;
            var index = D[i].i;
            if (res[index]) {
                continue;
            }

            if (index > last) {
                res[index] = color;
                last = index;
            } else {
                pr('-');
                continue loop;
            }
        }
        pr(res.join(''));
        //wr(123)
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split('').map(function (value) {
    return parseInt(value);
  });
};

function coloredSequences(seq) {
  var coloredSequences = [];

  for (var i = 0; i < 10; i++) {
    var coloredSequence = [];
    var p = 2;

    for (var j = 0; j < seq.length; j++) {
      if (seq[j] < i) {
        coloredSequence.push(1);
      } else if (seq[j] > i) {
        p = 1;
        coloredSequence.push(2);
      } else {
        coloredSequence.push(p);
      }
    }

    coloredSequences.push(coloredSequence);
  }

  return coloredSequences;
}

function rightColoredSequence(coloredSequences, seq) {
  for (var i = 0; i < coloredSequences.length; i++) {
    var color1Element = -1;
    var color2Element = -1;
    var right = true;
    var coloredSequence = coloredSequences[i];

    for (var j = 0; j < seq.length; j++) {
      if (coloredSequence[j] === 1) {
        if (seq[j] >= color1Element) {
          color1Element = seq[j];
        } else {
          right = false;
          break;
        }
      } else {
        if (seq[j] >= color2Element) {
          color2Element = seq[j];
        } else {
          right = false;
          break;
        }
      }
    }

    if (right) {
      return coloredSequence;
    }
  }

  return undefined;
}

function solve() {
  var length = parseInt(readline());
  var sequence = readline().getNumArray();
  var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);

  if (rightSequence === undefined) {
    write('-');
  } else {
    write(rightSequence.join(''));
  }
}

var n = readline().getNumArray()[0];

for (var i = 0; i < n; i++) {
  solve();
}

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split('').map(function (value) {
    return parseInt(value);
  });
};

function coloredSequences(seq) {
  var coloredSequences = [];

  for (var i = 0; i < 10; i++) {
    var coloredSequence = [];
    var p = 2;

    for (var j = 0; j < seq.length; j++) {
      if (seq[j] < i) {
        coloredSequence.push(1);
      } else if (seq[j] > i) {
        p = 1;
        coloredSequence.push(2);
      } else {
        coloredSequence.push(p);
      }
    }

    coloredSequences.push(coloredSequence);
  }

  return coloredSequences;
}

function rightColoredSequence(coloredSequences, seq) {
  for (var i = 0; i < coloredSequences.length; i++) {
    var color1Element = -1;
    var color2Element = -1;
    var right = true;
    var coloredSequence = coloredSequences[i];

    for (var j = 0; j < seq.length; j++) {
      if (coloredSequence[j] === 1) {
        if (seq[j] >= color1Element) {
          color1Element = seq[j];
        } else {
          right = false;
          break;
        }
      } else {
        if (seq[j] >= color2Element) {
          color2Element = seq[j];
        } else {
          right = false;
          break;
        }
      }
    }

    if (right) {
      return coloredSequence;
    }
  }

  return undefined;
}

function solve() {
  var length = parseInt(readline());
  var sequence = readline().getNumArray();
  var rightSequence = rightColoredSequence(coloredSequences(sequence), sequence);

  if (rightSequence === undefined) {
    write('-\n');
  } else {
    write(rightSequence.join('') + '\n');
  }
}

var n = readline().getNumArray()[0];

for (var i = 0; i < n; i++) {
  solve();
}

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var t = rdN();
    loop:while (t --> 0) {
        var n = rdN();
        var D = rdS().split('').map((v, i) => ({v: v, i: i})).sort((a,b) => {
            if (a.v != b.v) {
                return a.v - b.v;
            }
            return a.i - b.i;
        });
        //prOb(D)

        var res = crAr(n);
        var last = -1;
        var color = 1;
        for (var i = 0; i < n; ++i) {
            var value = D[i].v;
            var index = D[i].i;
            if (index > last) {
                res[index] = color;
                last = index;
            }
        }
        var last = -1;
        var color = 2;
        for (var i = 0; i < n; ++i) {
            var value = D[i].v;
            var index = D[i].i;
            if (res[index]) {
                continue;
            }

            if (index > last) {
                res[index] = color;
                last = index;
            } else {
                pr('-');
                continue loop;
            }
        }
        pr(res.join(''));
        //wr(123)
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();