William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands.A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just after one of existing items $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \,\cdots\, \,.\,a_k$$$ and can be one of two types:   Add an item $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, a_k \,.\, 1$$$ (starting a list of a deeper level), or  Add an item $$$a_1 \,.\, a_2 \,.\, a_3 \,.\, \cdots \,.\, (a_k + 1)$$$ (continuing the current level).  Operation can only be applied if the list does not contain two identical items afterwards. And also, if we consider every item as a sequence of numbers, then the sequence of items should always remain increasing in lexicographical order. Examples of valid and invalid lists that are shown in the picture can found in the "Notes" section.When William decided to save a Word document with the list of his errands he accidentally hit a completely different keyboard shortcut from the "Ctrl-S" he wanted to hit. It's not known exactly what shortcut he pressed but after triggering it all items in the list were replaced by a single number: the last number originally written in the item number.William wants you to help him restore a fitting original nested list.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$), which is the number of lines in the list. Each of the next $$$n$$$ lines contains a single integer $$$a_i$$$ ($$$1 \le a_i \le n$$$), which is what remains of William's nested list. It is guaranteed that in each test case at least one fitting list exists. It is guaranteed that the sum of values $$$n$$$ across all test cases does not exceed $$$10^3$$$.

For each test case output $$$n$$$ lines which represent a valid nested list, which could become the data provided to you by William. If there are multiple answers, print any.

NoteIn the second example test case one example of a fitting list is:11.1 1.1.11.1.21.21.2.122.12.2This list can be produced by using the sequence of operations shown below:    Original list with a single item $$$1$$$.  Insert item $$$2$$$ by using the insertion operation of the second type after item $$$1$$$.  Insert item $$$1.1$$$ by using the insertion operation of the first type after item $$$1$$$.  Insert item $$$1.2$$$ by using the insertion operation of the second type after item $$$1.1$$$.  Insert item $$$1.1.1$$$ by using the insertion operation of the first type after item $$$1.1$$$.  Insert item $$$1.1.2$$$ by using the insertion operation of the second type after item $$$1.1.1$$$.  Insert item $$$1.2.1$$$ by using the insertion operation of the first type after item $$$1.2$$$.  Insert item $$$2.1$$$ by using the insertion operation of the first type after item $$$2$$$.  Insert item $$$2.2$$$ by using the insertion operation of the second type after item $$$2.1$$$.

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function findAllStr(json, map, mapRev, index) {
   mapRev[index] = json;
   if (Array.isArray(json)) {
      for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {
         findAllStr(json[i], map, mapRev, index + '_' + i);
      }
      return;
   }
   if (json && typeof json === 'string') {
      if (map[json]) {
         map[json].push(index);
      } else {
         map[json] = [index];
      }
   }
   return;
}

function solve() {
   var n = Number(read());
   var ans = [[1]];
   read();
   for (var i = 1; i < n; i++) {
      var a  = Number(read());
      ans[i] = ans[i - 1].slice();
      if (a === 1) {
         ans[i].push(1);
         continue;
      }
      var b = ans[i].pop();
      while(b + 1 !== a) {
         b = ans[i].pop();
      }
      ans[i].push(a);
   }
   write(ans.map((str) => str.join('.')).join('\n'));
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

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 n = rn();

		const ans = [];
		for (let i = 0; i < n; i++) {
			const a = rn();

			if (a == 1) {
				ans.push(1);
			} else {
				while (ans[ans.length-1] != a-1) ans.pop();
				ans[ans.length-1] += 1;
			}

			console.log(ans.join('.'));
		}
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function findAllStr(json, map, mapRev, index) {
   mapRev[index] = json;
   if (Array.isArray(json)) {
      for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {
         findAllStr(json[i], map, mapRev, index + '_' + i);
      }
      return;
   }
   if (json && typeof json === 'string') {
      if (map[json]) {
         map[json].push(index);
      } else {
         map[json] = [index];
      }
   }
   return;
}

function addToStore(store, address, value) {
   if (!store[address]) {
      store[address] = [];
   }
   store[address].push(value);
}

function getFromStore(store, address) {
   return store[address].pop();
}

function solve() {
   var n = Number(read());
   var ans = [[1]];
   var store = [];
   addToStore(store, 2, 0);
   read();
   for (var i = 1; i < n; i++) {
      var a  = Number(read());
      if (a === 1) {
         ans[i] = ans[i - 1].slice();
         ans[i].push(1);
         addToStore(store, 2, i);
         continue;
      }
      var j = getFromStore(store, a);
      ans[i] = ans[j].slice();
      ans[i][ans[i].length - 1] = a;
      addToStore(store, a + 1, i);
   }
   write(ans.map((str) => str.join('.')).join('\n'));
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function findAllStr(json, map, mapRev, index) {
   mapRev[index] = json;
   if (Array.isArray(json)) {
      for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {
         findAllStr(json[i], map, mapRev, index + '_' + i);
      }
      return;
   }
   if (json && typeof json === 'string') {
      if (map[json]) {
         map[json].push(index);
      } else {
         map[json] = [index];
      }
   }
   return;
}

function solve() {
   var n = Number(read());
   var ans = '0'.repeat(n).split('');
   ans[0] = [1];
   read();
   for (var i = 1; i < n; i++) {
      var a  = Number(read());
      if (a === 1) {
         ans[i] = ans[i - 1].slice();
         ans[i].push(1);
         continue;
      }
      var j = i - 1;
      while (ans[j][ans[j].length - 1] + 1 !== a) {
         j--;
      }
      ans[i] = ans[j].slice();
      ans[i][ans[i].length - 1] ++;
   }
   write(ans.map((str) => str.join('.')).join('\n'));
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}


The only difference between the easy and hard versions is that the given string $$$s$$$ in the easy version is initially a palindrome, this condition is not always true for the hard version.A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is not.Alice and Bob are playing a game on a string $$$s$$$ (which is initially a palindrome in this version) of length $$$n$$$ consisting of the characters '0' and '1'. Both players take alternate turns with Alice going first.In each turn, the player can perform one of the following operations:   Choose any $$$i$$$ ($$$1 \le i \le n$$$), where $$$s[i] =$$$ '0' and change $$$s[i]$$$ to '1'. Pay 1 dollar.  Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. Reversing a string means reordering its letters from the last to the first. For example, "01001" becomes "10010" after reversing.The game ends when every character of string becomes '1'. The player who spends minimum dollars till this point wins the game and it is a draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, or if it is a draw.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^3$$$). The second line of each test case contains the string $$$s$$$ of length $$$n$$$, consisting of the characters '0' and '1'. It is guaranteed that the string $$$s$$$ is a palindrome and contains at least one '0'.  Note that there is no limit on the sum of $$$n$$$ over test cases.

For each test case print a single word in a new line:    "ALICE", if Alice will win the game,  "BOB", if Bob will win the game,  "DRAW", if the game ends in a draw.

NoteIn the first test case of the example,   in the $$$1$$$-st move Alice has to perform the $$$1$$$-st operation, since the string is currently a palindrome.  in the $$$2$$$-nd move Bob reverses the string.  in the $$$3$$$-rd move Alice again has to perform the $$$1$$$-st operation. All characters of the string are '1', game over.  Alice spends $$$2$$$ dollars while Bob spends $$$0$$$ dollars. Hence, Bob always wins.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      console.log("BOB");
      continue;
    }
    let cnt = 0;
    for (let i = 0; i < n; i++) if (str[i] === "0") cnt++;
    if(cnt===1) console.log("BOB");
    else if (cnt % 2) console.log("ALICE");
    else console.log("BOB");
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    for (let i = mid - 1; i >= 0; i--) {
        if (str[i] === '0') zero++
    }
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        return zero === 1 ? 'BOB' : 'ALICE'
    }
    // 00x00 -> 10x00 -> 10x01, same with 0x0
    return 'BOB'
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 05/20/21 afternoon

const solve = (n, s) => {
    let cnt = 0;
    for (const c of s) cnt += (c == '0');
    // pr(cnt);
    if (n & 1 && s[n >>> 1] == '0' && cnt > 1) {
        pr("ALICE")
    } else {
        pr("BOB");
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

const palindromeDist = (line) => {
	let count = 0;
	for (let i=0; i<(line.length/2); i++) {
		if (line[i] !== line[line.length-1-i]) {
			count++;
		}
	}

	return count;
}

const solve = (line) => {
	const emptyCells = line.split('')
		.reduce((acc, item) => (acc += (item === '0' ? 1 : 0)), 0);

	if (emptyCells === 1) {
		return 'BOB';
	}

	const canDoPalindrome = line.length%2 === 1 && line[Math.floor(line.length/2)] === '0';

	return canDoPalindrome ? 'ALICE' : 'BOB';
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const [n, ...lines] = input.trim().split('\n')
		.map(l => l.trim());

	for (let i=0; i<n; i++) {
		console.log(solve(lines[(i*2)+1]));
	}
})

var e=readline();
for(var iq=0;iq<e;iq++){
  var n=parseInt(readline());
  var s=readline();
  var zc=0;
  for(var i=0;i<s.length;i++){
    if(s[i]=='0') {
      zc++
    }
  }
  if(zc==0){
  print('DRAW');
  }else{
    if(zc==1){
    print('BOB');
    }else{
      if(zc%2==1){
        print('ALICE');
      }else{
        print('BOB');
      }
    }
  }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      console.log("BOB");
      continue;
    }
    let cnt = 0;
    for (let i = 0; i < n; i++) if (str[i] === "0") cnt++;
    if (cnt % 2) console.log("ALICE");
    else console.log("BOB");
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) console.log("BOB");
    let cnt = 0;
    for (let i = 0; i < n; i++) if (str[i] === "0") cnt++;
    if (cnt % 2) console.log("ALICE");
    else console.log("BOB");
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    let cnt = 0,
      cnt1 = 0;
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") cnt++;
    }
    let i = 0,
      j = n - 1;
    while (i <= j) {
      if (str[i] !== str[j]) cnt1++;
      i++;
      j--;
    }
    if (cnt === 0) {
      console.log("DRAW");
    } else if (cnt1 === 0) {
      if (cnt % 2) {
        console.log("ALICE");
      } else console.log("BOB");
    } else {
      let p2 = cnt1;
      cnt -= cnt1;
      if (cnt === 0) console.log("DRAW");
      else {
        if (cnt % 2 === 0) {
          p1 += Math.floor(n / 2);
          p2 += Math.floor(n / 2);
        } else {
          if (cnt === 1) p1 = 1;
          else if (cnt === 3) {
            p1 = 1;
            p2 += 2;
          } else {
            p2 += Math.floor(n / 2);
            p1 += cnt - Math.floor(n / 2);
          }
        }
        if (p1 === p2) console.log("DRAW");
        if (p1 < p2) console.log("ALICE");
        else console.log("BOB");
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    let cnt = 0,
      cnt1 = 0;
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") cnt++;
    }
    let i = 0,
      j = n - 1;
    while (i <= j) {
      if (str[i] !== str[j]) cnt1++;
      i++;
      j--;
    }
    if (cnt === 0) {
      console.log("DRAW");
    } else if (cnt1 === 0) {
      if (cnt % 2) {
        if (cnt === 3) console.log("ALICE");
        else console.log("BOB");
      } else console.log("BOB");
    } else {
      let p2 = cnt1;
      cnt -= cnt1;
      if (cnt === 0) console.log("DRAW");
      else {
        if (cnt % 2 === 0) {
          p1 += Math.floor(n / 2);
          p2 += Math.floor(n / 2);
        } else {
          if (cnt === 1) p1 = 1;
          else if (cnt === 3) {
            p1 = 1;
            p2 += 2;
          } else {
            p2 += Math.floor(n / 2);
            p1 += cnt - Math.floor(n / 2);
          }
        }
        if (p1 === p2) console.log("DRAW");
        if (p1 < p2) console.log("ALICE");
        else console.log("BOB");
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    let cnt = 0,
      cnt1 = 0;
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") cnt++;
    }
    let i = 0,
      j = n - 1;
    while (i <= j) {
      if (str[i] !== str[j]) cnt1++;
      i++;
      j--;
    }
    if (cnt === 0) {
      console.log("DRAW");
    } else if (cnt1 === 0) {
      if (cnt % 2) {
        cnt = Math.floor(cnt / 2) > cnt - Math.floor(cnt / 2) ? 0 : 1;
        if (cnt) console.log("ALICE");
        else console.log("BOB");
      } else console.log("BOB");
    } else {
      let p2 = cnt1;
      cnt -= cnt1;
      if (cnt === 0) console.log("DRAW");
      else {
        if (cnt % 2 === 0) {
          p1 += Math.floor(n / 2);
          p2 += Math.floor(n / 2);
        } else {
          if (cnt === 1) p1 = 1;
          else if (cnt === 3) {
            p1 = 1;
            p2 += 2;
          } else {
            p2 += Math.floor(n / 2);
            p1 += cnt - Math.floor(n / 2);
          }
        }
        if (p1 === p2) console.log("DRAW");
        if (p1 < p2) console.log("ALICE");
        else console.log("BOB");
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    let cnt = 0,
      cnt1 = 0;
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") cnt++;
    }
    let i = 0,
      j = n - 1;
    while (i <= j) {
      if (str[i] !== str[j]) cnt1++;
      i++;
      j--;
    }
    if (cnt === 0) {
      console.log("DRAW");
    } else if (cnt1 === 0) {
      if (cnt % 2) {
        cnt = Math.floor(cnt / 2) > cnt - Math.floor(cnt / 2) ? 0 : 1;
        if (cnt) console.log("ALICE");
        else console.log("BOB");
      } else console.log("BOB");
    } else {
      let p2 = cnt1,
        p1 = 0;
      let r = cnt - cnt1;
      if (r === 2) p1 += r;
      else {
        p2 += Math.floor(r / 2);
        p1 += r - Math.floor(r / 2);
      }
      if (p1 === p2) console.log("DRAW");
      else if (p1 < p2) console.log("ALICE");
      else console.log("BOB");
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    let cnt = 0,
      cnt1 = 0;
    for (let i = 0; i < n; i++) {
      if (str[i] === "0") cnt++;
    }
    let i = 0,
      j = n - 1;
    while (i <= j) {
      if (str[i] !== str[j]) cnt1++;
      i++;
      j--;
    }
    if (cnt === 0) {
      console.log("DRAW");
    } else if (cnt1 === 0) {
      if (cnt % 2) console.log("ALICE");
      else console.log("BOB");
    } else {
      let p2 = cnt1,
        p1 = 0;
      let r = cnt - cnt1;
      if (r === 2) p1 += r;
      else {
        p2 += Math.floor(r / 2);
        p1 += r - Math.floor(r / 2);
      }
      if (p1 === p2) console.log("DRAW");
      else if (p1 < p2) console.log("ALICE");
      else console.log("BOB");
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim();
    if (n === 1) {
      if (str[0] === "0") console.log("BOB");
      else console.log("DRAW");
      continue;
    }
    let flag = true;
    for (let i = 0; i < n; i++) {
      if (str[i] !== str[n - 1 - i]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      let ans = true;
      for (let i = 0; i < n; i++) {
        if (str[i] === "0") {
          ans = false;
          break;
        }
      }
      if (ans) console.log("DRAW");
      else console.log("BOB");
    } else {
      let cnt = 0,
        cnt1 = 0;
      for (let i = 0; i < n; i++) {
        if (str[i] === "0") cnt++;
      }
      let i = 0,
        j = n - 1;
      while (i <= j) {
        if (str[i] !== str[j]) cnt1++;
        i++;
        j--;
      }
      if (cnt % cnt1 === 0) console.log("DRAW");
      else console.log("ALICE");
    }
  }
};
solve();

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    for (let i = mid - 1; i >= 0; i--) {
        if (str[i] === '0') zero++
    }
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        return str.length === 1 ? 'BOB' : 'ALICE'
    }
    // 00x00 -> 10x00 -> 10x01, same with 0x0
    return 'BOB'
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    for (let i = mid - 1; i >= 0; i--) {
        if (str[i] === '0') zero++
    }
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        return 'ALICE'
    }
    // 00x00 -> 10x00 -> 10x01, same with 0x0
    return 'BOB'
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)
    let zero = 0
    for (let i = mid - 1; i >= 0; i--) {
        if (str[i] === '0') zero++
    }
    return (zero & 1) ? 'BOB' : 'DRAW'
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 05/20/21 morning
 * https://codeforces.com/contest/1527/problem/B1
 */

const solve = (n, s) => {
    let se = new Set();
    for (let i = 0; i < n; i++) {
        if (s[i] == '0') se.add(i);
    }
    let a = s.split("");
    let Alice = Bob = 0;
    // replace '0' to '1' make s still palidrome in first priority
    let isP = true;
    let round = 1;
    let pre;
    // pr(a, se);
    // for (let i = 0; i <= 10; i++) {
    while (se.size) {
        if (isP == false && pre != 'rv') {
            // pr("reverse")
            a.reverse();
            pre = 'rv';
        } else {
            let did = false;
            for (const i of se) {
                if (i == n - 1 - i || a[n - 1 - i] == '1') {
                    a[i] = '1';
                    did = true; // still keep palidrome
                    // pr("111")
                    se.delete(i);
                    break;
                }
            }
            // pr(did)
            if (!did) {
                let first = se.values().next().value;
                // pr("2222", first, se)
                a[first] = '1';
                se.delete(first);
                isP = false;
            }
            round & 1 ? Alice++ : Bob++;
            pre = 'rp';
        }
        round++;
        // pr("next", a, se, isP, pre, Alice, Bob);
    }
    // pr(Alice, Bob);
    if (Alice > Bob) {
        pr("BOB");
    } else if (Alice < Bob) {
        pr("Alice");
    } else {
        pr("DRAW")
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 05/20/21 morning
 * https://codeforces.com/contest/1527/problem/B1
 */

const solve = (n, s) => {
    let se = new Set();
    for (let i = 0; i < n; i++) {
        if (s[i] == '0') se.add(i);
    }
    let a = s.split("");
    let Alice = Bob = 0;
    // replace '0' to '1' make s still palidrome in first priority
    let isP = true;
    let round = 1;
    let pre;
    // pr(a, se);
    // for (let i = 0; i <= 10; i++) {
    while (se.size) {
        if (isP == false && pre != 'rv') {
            // pr("reverse")
            a.reverse();
            pre = 'rv';
        } else {
            let did = false;
            for (const i of se) {
                if (a[n - 1 - i] == '1') {
                    a[i] = '1';
                    did = true; // still keep palidrome
                    // pr("111")
                    se.delete(i);
                    break;
                }
            }
            // pr(did)
            if (!did) {
                let first = se.values().next().value;
                // pr("2222", first, se)
                a[first] = '1';
                se.delete(first);
                isP = false;
            }
            round & 1 ? Alice++ : Bob++;
            pre = 'rp';
        }
        round++;
        // pr("next", a, se, isP, pre, Alice, Bob);
    }
    // pr(Alice, Bob);
    if (Alice > Bob) {
        pr("BOB");
    } else if (Alice < Bob) {
        pr("Alice");
    } else {
        pr("DRAW")
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

var e=readline();
for(var iq=0;iq<e;iq++){
  var n=parseInt(readline());
  var s=readline();
  var r=true;
  for(var i=0;i<s.length;i++){
    if(s[i]=='0') {
      r=false;
    }
  }
  if(r){
  print('DRAW');
  }else{
    print('BOB');
  }
}


You are given array $$$a_1, a_2, \dots, a_n$$$. Find the subsegment $$$a_l, a_{l+1}, \dots, a_r$$$ ($$$1 \le l \le r \le n$$$) with maximum arithmetic mean $$$\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$$$ (in floating-point numbers, i.e. without any rounding).If there are many such subsegments find the longest one.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the array $$$a$$$.

Print the single integer — the length of the longest subsegment with maximum possible arithmetic mean.

NoteThe subsegment $$$[3, 4]$$$ is the longest among all subsegments with maximum arithmetic mean.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
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);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}

function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));

  let [maxLen, count, max] = [0, 0, Math.max(...arr)];

  for (let i = 0; i < len; i++) {
    if (arr[i] === max) {
      count++;
    } else {
      count = 0;
    }

    maxLen = Math.max(maxLen, count);
  }

  console.log(maxLen);
}

(function() {
    var read = {
        number: function() {
            return +readline();
        },
        arr: function(divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function(divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();
    var a = read.arrNumber(' ');

    var max = a[0];
    for(var i = 1; i < n; i++) {
        if(max < a[i]) max = a[i];
    }

    var count = [1];
    var countIndex = 0;
    for(var i = 1; i < n; i++) {
        if(a[i] === max) {
            if(a[i] === a[i - 1]) {
                count[countIndex] += 1;
            }
            else {
                countIndex++;
                count[countIndex] = 1;
            }
        }
    }

    max = count[0];
    for(var i = 1; i < n; i++) {
        if(max < count[i]) max = count[i];
    }
    print(max);

}());

readline();
var inp = readline().split(' ').map(x => parseInt(x));

var max = Math.max(...inp);
var l_when_max = 0;

var indexes = [], i = -1;
while ((i = inp.indexOf(max, i+1)) != -1){
    indexes.push(i);
}

for(var j = 0 in indexes)
{
    var k = parseInt(j);
    var l = 1;
    while(k < indexes.length - 1 && indexes[k + 1] - indexes[k] === 1)
    {
        l++;
        k++;
    }

    if (l > l_when_max)
    {
        l_when_max = l;
    }
    if(l_when_max > indexes.length / 2)
    {
        break;
    }
}

print(l_when_max);

write((readline().split(" ").map(function(x) { return parseInt(x); })[0]*0 + readline().split(" ").reduce(function(acc, item) { var val = parseInt(item);  if (val > acc.mx) { acc.mx = val; acc.mx_cnt = 1; acc.ans = 1;} else if (val === acc.mx)	acc.mx_cnt++; else acc.mx_cnt = 0; acc.ans = Math.max(acc.ans, acc.mx_cnt); return acc;}, {mx: -1, mx_cnt: 0, ans: 1}).ans) + "\n");

function calc(arr) {
  // find max
  var max = 0;
  for (var i = 0; i< arr.length; i++) {
    max = max > arr[i] ? max : arr[i];
  }

  // find max count
  var count = 0;
  var countMax = 1;
  for (var i = 0; i< arr.length; i++) {
    if (arr[i] === max) {
      count++;
    } else {
      count = 0;
    }

    countMax = countMax > count ? countMax : count;
  }

  return countMax;
}

var n = parseInt(readline());
var arr = readline().split(" ").map(el => parseInt(el));

print(calc(arr));

var n = parseInt(readline(), 10),
    a = readline().split(' ').map(el => parseInt(el, 10)),
    max_mean = 0,
    max_len = 0,
    local_len = 0,
    local_mean = 0,
    local_sum = 0;

for(var i=0; i<n; i++) {
    if(a[i] > max_mean) {
        local_len = 1;
        local_sum = a[i];
        local_mean = local_sum / local_len;
    } else {
        local_len++;
        local_sum += a[i];
        local_mean = local_sum / local_len;
    }

    if(local_mean > max_mean) {
        max_mean = local_mean;
        max_len = local_len;

    } else if(local_mean === max_mean) {
        if(local_len > max_len) max_len = local_len;
    } else {
        local_len = 1;
        local_sum = a[i];
        local_mean = local_sum / local_len;

        if(local_mean > max_mean) {
            max_mean = local_mean;
            max_len = local_len;

        } else if(local_mean === max_mean) {
            if(local_len > max_len) max_len = local_len;
        }
    }
}

print(max_len);

readline();
var inp = readline().split(' ').map(x => parseInt(x));

var max = Math.max(...inp);
var l_when_max = 0;

var indexes = [], i = -1;
while ((i = inp.indexOf(max, i+1)) != -1){
    indexes.push(i);
}

print(indexes);

for(var j = 0 in indexes)
{
    var k = parseInt(j);
    var l = 1;
    while(k < indexes.length - 1 && indexes[k + 1] - indexes[k] === 1)
    {
        l++;
        k++;
    }

    if (l > l_when_max)
    {
        l_when_max = l;
    }
}

print(l_when_max);

write((readline().split(" ").map(function(x) { return parseInt(x); })[0]*0 + readline().split(" ").reduce(function(acc, item) { var val = parseInt(item);  if (val > acc.mx) { acc.mx = val; acc.mx_cnt = 1; } else if (val === acc.mx)	acc.mx_cnt++; else acc.mx_cnt = 0; acc.ans = Math.max(acc.ans, acc.mx_cnt); return acc;}, {mx: -1, mx_cnt: 0, ans: 1}).ans) + "\n");


Tokitsukaze has a sequence $$$a$$$ of length $$$n$$$. For each operation, she selects two numbers $$$a_i$$$ and $$$a_j$$$ ($$$i \ne j$$$; $$$1 \leq i,j \leq n$$$).   If $$$a_i = a_j$$$, change one of them to $$$0$$$.  Otherwise change both of them to $$$\min(a_i, a_j)$$$. Tokitsukaze wants to know the minimum number of operations to change all numbers in the sequence to $$$0$$$. It can be proved that the answer always exists.

The first line contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the sequence $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the sequence $$$a$$$.

For each test case, print a single integer — the minimum number of operations to change all numbers in the sequence to $$$0$$$.

NoteIn the first test case, one of the possible ways to change all numbers in the sequence to $$$0$$$:In the $$$1$$$-st operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = a_1 = 1$$$. Now the sequence $$$a$$$ is $$$[1,1,3]$$$.In the $$$2$$$-nd operation, $$$a_1 = a_2 = 1$$$, after the operation, $$$a_1 = 0$$$. Now the sequence $$$a$$$ is $$$[0,1,3]$$$.In the $$$3$$$-rd operation, $$$a_1 < a_2$$$, after the operation, $$$a_2 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,3]$$$.In the $$$4$$$-th operation, $$$a_2 < a_3$$$, after the operation, $$$a_3 = 0$$$. Now the sequence $$$a$$$ is $$$[0,0,0]$$$.So the minimum number of operations is $$$4$$$.

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++];
}

const main = () => {
  let tc = parseInt(readline());
  while(tc--){
    const n = parseInt(readline());
    const a = readline().split(' ').map(Number);
    let zero = 0;
    for(let i = 0; i < n; i++){
      if(!a[i]) zero++;
    }
    if(zero){
      console.log(n-zero);
    }
    else{
      let same = false;
      for(let i = 0; i < n; i++){
        for(let j = i+1; j < n; j++){
          if(a[i] === a[j]) same = true;
        }
      }
      if(same){
        console.log(n);
      }
      else{
        console.log(n+1);
      }
    }
  }
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = readline().split(' ').map(Number);

        let zero = arr.findIndex(x => x === 0) > -1;
        let nonZero = arr.filter(x => x !== 0).length;

        let hash = {};

        let duplicate = false;
        for (let i = 0; i < n; i++) {
            if (arr[i] !== 0) {
                if (hash[arr[i]]) {
                    duplicate = true;
                } else {
                    hash[arr[i]] = 1;
                }
            }
        }

        output((zero || duplicate) ? nonZero : nonZero + 1);
    }
}

let readline = require("readline");
let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let lines = 0;
const hasUniqueElements = (arr) => {
  const cache = {};
  for (let index = 0; index < arr.length; index++) {
    const element = arr[index];
    if (!cache[element]) {
      cache[element] = true;
    } else {
      return false;
    }
  }
  return true;
};

const countAllZeros = (arr) => {
  zeros = 0;
  for (let index = 0; index < arr.length; index++) {
    const element = arr[index];
    if (element === 0) zeros++;
  }
  return zeros;
};

rl.on("line", function (line) {
  if (lines !== 0 && lines % 2 === 0) {
    let input = line.split(" ").map(Number);
    const zeros = countAllZeros(input);
    if (zeros > 0) {
      console.log(input.length - zeros);
    } else if (hasUniqueElements(input)) {
      console.log(input.length + 1);
    } else {
      console.log(input.length);
    }
  }
  lines++;
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    readLine();
    let arr = readLine().split(" ").map(i => parseInt(i)).sort((a, b) => a - b);
    let dup = false;
    let noofzeros = 0;
    let cnt = 0;
    if (arr[0] === 0) noofzeros = 1;
    for (let i = 1; i < arr.length; i++) {
        if ((arr[i] === arr[i - 1]) && !dup) dup = true;
        if (arr[i] === 0) noofzeros++;
    }
    cnt = arr.length - noofzeros;
    if (noofzeros == 0 && !dup)  return cnt + 1;
    if (noofzeros == 0 && dup) return cnt;
    else return cnt;
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const map = {}
    let zero = 0
    let hasDup = 0
    arr.forEach(x => {
        if (!x) zero++
        if (map[x]) hasDup = 1
        map[x] = 1
    })
    if (zero) {
        return n - zero
    } else if (hasDup) {
        return n
    } else {
        return 1 + n
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var nzero = 0;
		for(var i = 0; i < N; i++){
			if(list[i] != 0){
				nzero++;
			}
		}
		if(nzero < N){
			myout(nzero);
		}else{
			var map = getCountMap(list);
			var key = Object.keys(map);
			if(key.length != N){
				myout(nzero);
			}else{
				myout(nzero + 1);
			}
		}
	}
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, a) {
  let zero = 0,
      repeat = 0,
      set = new Set();
  for (let num of a) {
    if (num === 0) {
      zero++;
    } else if (set.has(num)) {
      repeat = 1;
    }
    set.add(num);
  }
  if (zero > 0) {
    return n - zero;
  } else if (repeat > 0) {
    return n;
  } else {
    return n + 1;
  }
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const n = Number(await read());
    const a = (await read()).split(' ').map(Number);
    res.push(solve(n, a));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

/*---------------------------------------------------*/

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

/*---------------------------------------------------*/

const calc = (n, a)=>{
    let zero = 0;
    let equal = false;

    a.sort((x, y) => x - y);

    let i = 0;
    while (i < n && a[i] === 0) {
        zero++;
        i++;
    }

    for (; i < n; i++) {
        if (i > 0 && a[i] === a[i - 1]) {
            equal = true;
            break;
        }
    }

    if (zero > 0) {
        return n - zero;
    } else {
        return equal ? n : n + 1;
    }
};

function main() {
    let T = +readline();
    // let out = [];
    for (let t = 1; t <= T; t++){
        let n = +readline();
        // let s = readline();
        let a = ra();
        // out.push(calc(n, s, a));
        process.stdout.write(`${calc(n, a)}\n`);
    }
    // process.stdout.write(out.join('\n')+'\n');
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n] = ra();
  let A = ra();
  LT({n, A});

  // PROCESSING:
  let ans = 0;
  let left = 0;
  let cnt = {};
  let max = 0;
  for (let i=0; i<n; i++){
    let a = A[i];
    if (a>0)
      left++;
    cnt[a] = (cnt[a]||0)+1;
    max = Math.max(max, cnt[a])
  }
  if (left<n)
    return left;
  if (max>1){
    return n;
  }
  return n+1;
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var i = _a[_i];
    var n = +readline();
    var a = readline().split(' ').map(function (v) { return +v; }).sort();
    if (a[0] === 0) {
        for (var j = 1; j < n; j++) {
            if (a[j] !== 0) {
                print(n - j);
                continue root;
            }
        }
        print(0);
        continue;
    }
    for (var i_1 = 1; i_1 < n; i_1++) {
        if (a[i_1] === a[i_1 - 1]) {
            print(n);
            continue root;
        }
    }
    print(n + 1);
}

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

let inputString = '';
let inputData = [];

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

process.stdin.on('end', () => {
  inputData = inputString.trim().split('\n').map(s => s.trim());
  main();
});

const input = (() => {
  let line = 0;
  return () => inputData[line++];
})();

const main = () => {
  let tc = parseInt(input());
  while(tc--){
    const n = parseInt(input());
    const a = input().split(' ').map(Number);
    let zero = 0;
    for(let i = 0; i < n; i++){
      if(!a[i]) zero++;
    }
    if(zero){
      console.log(n-zero);
    }
    else{
      let same = false;
      for(let i = 0; i < n; i++){
        for(let j = i+1; j < n; j++){
          if(a[i] === a[j]) same = true;
        }
      }
      if(same){
        console.log(n);
      }
      else{
        console.log(n+1);
      }
    }
  }
};

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

let inputString = '';
let inputData = [];

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

process.stdin.on('end', () => {
  inputData = inputString.trim().split('\n').map(s => s.trim());
  main();
});

const input = (() => {
  let line = 0;
  return () => inputData[line++];
})();

const main = () => {
  let tc = parseInt(input());
  while(tc--){
    const n = parseInt(input());
    const a = input().split(' ').map(Number);
    let zero = 0;
    for(let i = 0; i < n; i++){
      if(!a[i]) zero++;
    }
    if(zero){
      console.log(n-zero);
    }
    else{
      let same = false;
      for(let i = 0; i < n; i++){
        for(let j = 0; j < n; j++){
          if(i === j) continue;
          if(a[i] === a[j]) same = true;
        }
      }
      if(same){
        console.log(n);
      }
      else{
        console.log(n+1);
      }
    }
  }
};

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

let inputString = '';
let inputData = [];

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

process.stdin.on('end', () => {
  inputData = inputString.trim().split('\n').map(s => s.trim());
  main();
});

const input = (() => {
  let line = 0;
  return () => inputData[line++];
})();

const main = () => {
  let tc = parseInt(input());
  while(tc--){
    let n = parseInt(input());
    const a = input().split(' ').map(Number);
    let zero = 0;
    for(let i = 0; i < n; i++){
      if(!a[i]) zero++;
    }
    if(zero){
      console.log(n-zero);
    }
    else{
      let same = false;
      for(let i = 0; i < n-1; i++){
        if(a[i] === a[i+1]) same = true;
      }
      if(same){
        console.log(n);
      }
      else{
        console.log(n+1);
      }
    }
  }
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        readline();
        let arr = readline().split(' ').map(Number).filter(a => a !== 0);

        const freq = {};
        let equalPairs = 0;

        for (let i = 0; i < arr.length; i++) {
            if (freq[arr[i]]) {
                freq[arr[i]]++;
                if (freq[arr[i]] % 2 === 0) {
                    freq[arr[i]] = 0;
                    equalPairs++;
                }
            } else {
                freq[arr[i]] = 1;
            }
        }

        const remainingPairs = Math.ceil((arr.length - equalPairs * 2) / 2);

        output(equalPairs + remainingPairs * 2);
    }
}

let readline = require("readline");
let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});

let lines = 0;
const hasUniqueElements = (arr) => {
  const cache = {};
  for (let index = 0; index < arr.length; index++) {
    const element = arr[index];
    if (!cache[element]) {
      cache[element] = true;
    } else {
      return false;
    }
  }
  return true;
};

rl.on("line", function (line) {
  if (lines !== 0 && lines % 2 === 0) {
    let input = line.split(" ").map(Number);
    if (input.indexOf(0) !== -1) {
      console.log(input.length - 1);
    } else if (hasUniqueElements(input)) {
      console.log(input.length + 1);
    } else {
      console.log(input.length);
    }
  }
  lines++;
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    readLine();
    let arr = readLine().split(" ").map(i => parseInt(i));
    let hasZero = false;
    let dup = false;
    for (let i = 1; i < arr.length; i++) {
        if ((arr[i] === arr[i - 1]) && !dup) dup = true;
        if ((arr[i] == 0 || arr[i - 1] == 0) && !hasZero) hasZero = true;
    }
    if (hasZero) return arr.length - 1;
    else if (dup) return arr.length;
    else return arr.length + 1;
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var i = _a[_i];
    var n = +readline();
    var a = readline().split(' ').map(function (v) { return +v; }).sort();
    if (a[0] === 0) {
        print(n - 1);
        continue;
    }
    for (var i_1 = 1; i_1 < n; i_1++) {
        if (a[i_1] === a[i_1 - 1]) {
            print(n);
            continue root;
        }
    }
    print(n + 1);
}


You are given a string $$$s$$$. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if your goal is to reverse the string "abddea", you should get the string "aeddba". To accomplish your goal, you can swap the neighboring elements of the string. Your task is to calculate the minimum number of swaps you have to perform to reverse the given string.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the length of $$$s$$$. The second line contains $$$s$$$ — a string consisting of $$$n$$$ lowercase Latin letters.

Print one integer — the minimum number of swaps of neighboring elements you have to perform to reverse the string.

NoteIn the first example, you have to swap the third and the fourth elements, so the string becomes "aazaa". Then you have to swap the second and the third elements, so the string becomes "azaaa". So, it is possible to reverse the string in two swaps.Since the string in the second example is a palindrome, you don't have to do anything to reverse it.

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) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = 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 a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  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;
}
function inv(b, m) {
  for (var a = m, 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 + m) % m;
}

// let MOD = 1e9 + 7
// 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[MOD % 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;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async 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, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let n = +$(), s = [...$()], sr = [...s].reverse(), a = Arr(n, i => 0)
  let m = {}, id = {}
  let alpha = [..."abcdefghijklmnopqrstuvwxyz"];
  alpha.forEach(c => {
    m[c] = [];
    id[c] = 0;
  })
  For(n, i => {
    m[sr[i]].push(i)
  })
  // log(m)
  For(n, i => {
    a[i] = m[s[i]][id[s[i]]++]
  })
  // log(a)
  let res = 0;
  let bit = Arr(n + 1, i => 0)
  let set = i => {
    for (; i <= n; i += i & -i) bit[i]++;
  }
  let cal = i => {
    let ans = 0;
    for (; i; i -= i & -i) ans += bit[i];
    return ans;
  }
  ForR(n, i => {
    res += cal(a[i]);
    set(a[i] + 1)
  })
  log(res)
}


You are given $$$k$$$ sequences of integers. The length of the $$$i$$$-th sequence equals to $$$n_i$$$.You have to choose exactly two sequences $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $$$i$$$ (its length will be equal to $$$n_i - 1$$$) equals to the sum of the changed sequence $$$j$$$ (its length will be equal to $$$n_j - 1$$$).Note that it's required to remove exactly one element in each of the two chosen sequences.Assume that the sum of the empty (of the length equals $$$0$$$) sequence is $$$0$$$.

The first line contains an integer $$$k$$$ ($$$2 \le k \le 2 \cdot 10^5$$$) — the number of sequences. Then $$$k$$$ pairs of lines follow, each pair containing a sequence. The first line in the $$$i$$$-th pair contains one integer $$$n_i$$$ ($$$1 \le n_i < 2 \cdot 10^5$$$) — the length of the $$$i$$$-th sequence. The second line of the $$$i$$$-th pair contains a sequence of $$$n_i$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, n_i}$$$. The elements of sequences are integer numbers from $$$-10^4$$$ to $$$10^4$$$. The sum of lengths of all given sequences don't exceed $$$2 \cdot 10^5$$$, i.e. $$$n_1 + n_2 + \dots + n_k \le 2 \cdot 10^5$$$.

If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $$$i$$$, $$$x$$$ ($$$1 \le i \le k, 1 \le x \le n_i$$$), in the third line — two integers $$$j$$$, $$$y$$$ ($$$1 \le j \le k, 1 \le y \le n_j$$$). It means that the sum of the elements of the $$$i$$$-th sequence without the element with index $$$x$$$ equals to the sum of the elements of the $$$j$$$-th sequence without the element with index $$$y$$$. Two chosen sequences must be distinct, i.e. $$$i \ne j$$$. You can print them in any order. If there are multiple possible answers, print any of them.

NoteIn the first example there are two sequences $$$[2, 3, 1, 3, 2]$$$ and $$$[1, 1, 2, 2, 2, 1]$$$. You can remove the second element from the first sequence to get $$$[2, 1, 3, 2]$$$ and you can remove the sixth element from the second sequence to get $$$[1, 1, 2, 2, 2]$$$. The sums of the both resulting sequences equal to $$$8$$$, i.e. the sums are equal.

'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()
{
    const k=parseInt(readLine());
    let mp=new Map();
    for(let t=0;t<k;++t)
    {
        const n=parseInt(readLine());
        let arr=readLine().trim().split(' ').map(x=>{return +(x.trim());});
        let sum=arr.reduce((a,b)=>a+b);
        for(let i=0;i<n;++i)
        {
            if(mp.get(sum-arr[i])!==undefined)
            {
                if(mp.get(sum-arr[i])[0]!=t)
                {
                    console.log("YES");
                    console.log((mp.get(sum-arr[i])[0]+1)+' '+(mp.get(sum-arr[i])[1]+1));
                    console.log((t+1)+' '+(i+1));
                    return;
                }
            }
            else
            {
                mp.set(sum-arr[i],[t,i]);
            }
        }
    }
    console.log("NO");
}

'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()
{
    const K=parseInt(readLine());

    var seqSums = [];
    var seqs = []

    var map = new Map(); // key: sum - num, value: ["seqNo,removeItem", "seqNo,removeItem"]

    for (var i = 0; i < K; i++) {
        var len = parseInt(readLine());
        var seq=readLine().trim().split(' ').map(x=>{return +(x.trim());});
        var seqSum = 0;

        for (var j = 0; j < len; j++) {
            seqSum += seq[j];
        }

        for (var j = 0; j < len; j++) {
            if (map.get(seqSum - seq[j]) != undefined) {
                var tmp = map.get(seqSum - seq[j]);

                console.log("YES");
                tmp.forEach(function(item) {
                    console.log(item.split(',')[0] + " " + item.split(',')[1]);
                    console.log((i + 1) + " " + (j + 1));
                });

                map.set(seqSum - seq[j], tmp.push(i + "," + seq[j]));
                return;
            }
        }

        for (var j = 0; j < len; j++) {
            var tmp = [(i + 1) + "," + (j + 1)];
            map.set(seqSum - seq[j], tmp);
        }
    }
    console.log("NO");
}

'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()
{
    const K=parseInt(readLine());

    var seqSums = [];
    var seqs = []

    var map = new Map(); // key: sum - num, value: ["seqNo,removeItem", "seqNo,removeItem"]

    for (var i = 0; i < K; i++) {
        var len = parseInt(readLine());
        var seq=readLine().trim().split(' ').map(x=>{return +(x.trim());});
        var seqSum = 0;

        for (var j = 0; j < len; j++) {
            seqSum += seq[j];
        }

        for (var j = 0; j < len; j++) {
            if (map.get(seqSum - seq[j]) != undefined) {
                var tmp = map.get(seqSum - seq[j]);

                console.log("YES");
                tmp.forEach(function(item) {
                    console.log((parseInt(item.split(',')[0]) + 1) + " " + item.split(',')[1]);
                    console.log((i + 1) + " " + seq[j]);
                });

                map.set(seqSum - seq[j], tmp.push(i + "," + seq[j]));
                return;
            }
        }

        for (var j = 0; j < len; j++) {
            var tmp = [i + "," + seq[j]];
            map.set(seqSum - seq[j], tmp);
        }
    }
    console.log("NO");
}


Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the y-th column as a pair of numbers (x, y). The table corners are cells: (1, 1), (n, 1), (1, m), (n, m).Simon thinks that some cells in this table are good. Besides, it's known that no good cell is the corner of the table. Initially, all cells of the table are colorless. Simon wants to color all cells of his table. In one move, he can choose any good cell of table (x1, y1), an arbitrary corner of the table (x2, y2) and color all cells of the table (p, q), which meet both inequations: min(x1, x2) ≤ p ≤ max(x1, x2), min(y1, y2) ≤ q ≤ max(y1, y2).Help Simon! Find the minimum number of operations needed to color all cells of the table. Note that you can color one cell multiple times.

The first line contains exactly two integers n, m (3 ≤ n, m ≤ 50). Next n lines contain the description of the table cells. Specifically, the i-th line contains m space-separated integers ai1, ai2, ..., aim. If aij equals zero, then cell (i, j) isn't good. Otherwise aij equals one. It is guaranteed that at least one cell is good. It is guaranteed that no good cell is a corner.

Print a single number — the minimum number of operations Simon needs to carry out his idea.

NoteIn the first sample, the sequence of operations can be like this:    For the first time you need to choose cell (2, 2) and corner (1, 1).  For the second time you need to choose cell (2, 2) and corner (3, 3).  For the third time you need to choose cell (2, 2) and corner (3, 1).  For the fourth time you need to choose cell (2, 2) and corner (1, 3). In the second sample the sequence of operations can be like this:    For the first time you need to choose cell (3, 1) and corner (4, 3).  For the second time you need to choose cell (2, 3) and corner (1, 1).

print(function(n, m) {

	var a = [];
	for (var i = 0; i < n; i++)
		a.push(readline().split(' ').map(Number));

	for (var i = 0; i < n; i++)
		for (var j = 0; j < m; j++)
			if ((i === 0 || i === n - 1 || j === 0 || j === m - 1) && a[i][j] === 1) return 2;

	return 4;

} .apply(0, readline().split(' ').map(Number)));

;(function () {
	print(function () {
		var l = readline().split(' ').map(Number), n = l[0], m = l[1];

		if (readline().split(' ').indexOf('1') !== -1) return 2;
		else n -= 2;

		while (n--) {
			l = readline().split(' ');
			if (l.indexOf('1') === 0 || l.lastIndexOf('1') === m - 1) return 2;
		}

		return readline().split(' ').indexOf('1') !== -1 ? 2 : 4;
	}());
}).call(this);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1];
	for (var r = 0; r < rowNum; ++r) {
		var row = tokenizeIntegers(readline());
		for (var c = 0; c < colNum; ++c) {
			if (row[c] == 1) {
				if (r == 0 || r == rowNum-1 || c == 0 || c == colNum-1) {
					print(2);
					return;
				}
			}
		}
	}
	print(4);
}

main();

;(function () {
	print(function () {
		var l = readline().split(' ').map(Number), n = l[0], m = l[1];

		l = readline().split(' ');
		if (l.indexOf('1') !== -1) return 2;
		else n -= 2;

		while (n--) {
			var i = readline().split(' ').indexOf('1');
			if (i === 0 || i === m - 1) return 2;
		}

		return readline().split(' ').indexOf('1') !== -1 ? 2 : 4;
	}());
}).call(this);


A permutation is a sequence of $$$n$$$ integers from $$$1$$$ to $$$n$$$, in which all the numbers occur exactly once. For example, $$$[1]$$$, $$$[3, 5, 2, 1, 4]$$$, $$$[1, 3, 2]$$$ are permutations, and $$$[2, 3, 2]$$$, $$$[4, 3, 1]$$$, $$$[0]$$$ are not.Polycarp was given four integers $$$n$$$, $$$l$$$, $$$r$$$ ($$$1 \le l \le r \le n)$$$ and $$$s$$$ ($$$1 \le s \le \frac{n (n+1)}{2}$$$) and asked to find a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$ that satisfies the following condition:   $$$s = p_l + p_{l+1} + \ldots + p_r$$$. For example, for $$$n=5$$$, $$$l=3$$$, $$$r=5$$$, and $$$s=8$$$, the following permutations are suitable (not all options are listed):   $$$p = [3, 4, 5, 2, 1]$$$;  $$$p = [5, 2, 4, 3, 1]$$$;  $$$p = [5, 2, 1, 3, 4]$$$.  But, for example, there is no permutation suitable for the condition above for $$$n=4$$$, $$$l=1$$$, $$$r=1$$$, and $$$s=5$$$.Help Polycarp, for the given $$$n$$$, $$$l$$$, $$$r$$$, and $$$s$$$, find a permutation of numbers from $$$1$$$ to $$$n$$$ that fits the condition above. If there are several suitable permutations, print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. Each test case consist of one line with four integers $$$n$$$ ($$$1 \le n \le 500$$$), $$$l$$$ ($$$1 \le l \le n$$$), $$$r$$$ ($$$l \le r \le n$$$), $$$s$$$ ($$$1 \le s \le \frac{n (n+1)}{2}$$$). It is guaranteed that the sum of $$$n$$$ for all input data sets does not exceed $$$500$$$.

For each test case, output on a separate line:    $$$n$$$ integers — a permutation of length $$$n$$$ that fits the condition above if such a permutation exists;  -1, otherwise.  If there are several suitable permutations, print any of them.

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 [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (ans.length == l - 1) ans.push(...ar);
			if (!ss.has(i)) ans.push(i);
		}
		if (ans.length < n) ans.push(...ar);

		console.log(ans ? ans.join(' ') : -1);
	}
}

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 [n, l, r, s] = rna();

		const d = r - l + 1;
		const ar = Array.from(Array(d), (_, i) => i + 1);

		let need = s - d*(d+1)/2;
		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const mvs = Math.min(n - d, need);
			ar[i] += mvs;
			need -= mvs;
		}

		for (let i = 0, next = 1; ar.length < n; next++) {
			if (next != ar[i]) {
				ar.push(next);
			} else {
				i++;
			}
		}

		const ans = need == 0 && [...ar.slice(n - l + 1), ...ar].slice(0, n);

		console.log(ans ? ans.join(' ') : -1);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    //  printf("n %d m %d mn %d mx %d s %d l %d r %d\n", n, m, mn, mx, s, l, r);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    m--;
    for (let x = n; x >= 1; x--) {
        mn = Math.trunc(m * (m + 1) / 2);
        if (mn + x > s) {
            continue;
        }
        m--;
        s -= x;
        used[x] = 1;
        a.push(x);
    }
    // printf("a: %j\n", a);
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    //  printf("n %d m %d mn %d mx %d s %d l %d r %d\n", n, m, mn, mx, s, l, r);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = Math.min(n, s - mn);
        while (used[x]) {
            x--;
        }
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'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++];
}

var maxN = 21
var mod = 1000000007

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const xx = readline();

  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());
    var [n, l, r, s] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    l--
    r--
    var length = r - l + 1
    var lower = n - length + 1
    var ans = new Array(n).fill(false)
    var min = (((r - l + 1) + 1) * (r - l + 1)) / 2
    var max = (lower - 1) * length + ((length + 1) * (r - l + 1)) / 2
    var used = new Array(n + 1).fill(false)
    if (s < min || s > max) return console.log(-1)

    var a = []
    for (let j = 0; j < length; j++) {
      a[j] = j + 1
      s=s-a[j]
    }

    for (let j = length-1; j >=0; j--) {
      while (s>0 && a[j] < n - (length -j-1)){
        s--
        a[j]++
      }
    }
    for (let j = l; j <=r; j++) {
      ans[j] = a[j-l]
      used[ans[j]] = true
    }
    // console.log(ans.join(' '))

    for (let j = 1; j <= n; j++) {
      if (!used[j])
        for (let i = 0; i < n; i++) {
          if (ans[i] === false) {
            ans[i] = j
            break
          }
        }
    }
    console.log(ans.join(' '))

  })
}

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 [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (ans.length == l - 1) {
				ans.push(...ar);
			}
			if (!ss.has(i)) {
				ans.push(i);
			}
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

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 [n, l, r, s] = rna();

		const d = r - l + 1;

		let need = s;
		const ar = [];
		for (let i = 1; i <= d; i++) {
			ar.push(i);
			need -= i;
		}

		for (let i = d - 1; need > 0 && i >= 0; i--) {
			const chng = Math.min(n - d, need);
			ar[i] += chng;
			need -= chng;
		}

		const ss = new Set(ar);
		const ans = need == 0 && [];
		for (let i = 1; ans && i <= n; i++) {
			if (!ss.has(i)) {
				ans.push(i);
			}
			if (ans.length == l - 1) {
				ans.push(...ar);
			}
		}

		console.log(ans ? ans.join(' ') : -1);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    // printf("m %d n %d mn %d mx %d\n", m, n, mn, mx);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = s - mn;
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
function reverse(a, i, j) {
    while (i < j) {
        let t = a[i];
        a[i] = a[j];
        a[j] = t;
        i++;
        j--;
    }
}
const INIT = -1;
let n;
let l;
let r;
let s;
function solve() {
    let m = r - l + 1;
    let mn = m * (m + 1) / 2;
    let hi = n - m;
    let mx = hi * m + mn;
    printf("m %d n %d mn %d mx %d\n", m, n, mn, mx);
    if (s < mn || s > mx) {
        return false;
    }
    let used = af(n + 1).fill(0);
    let a = [];
    while (s > 0) {
        m--;
        mn = m * (m + 1) / 2;
        let x = s - mn;
        used[x] = 1;
        a.push(x);
        s -= x;
    }
    for (let x = 1; x <= n; x++) {
        if (used[x] == 0) {
            a.push(x);
        }
    }
    // printf("a: %j\n", a);
    reverse(a, 0, n - l);
    reverse(a, n - l + 1, n - 1);
    reverse(a, 0, n - 1);
    // printf("a: %j\n", a);
    for (let i = 0; i < n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        l = nextInt();
        r = nextInt();
        s = nextInt();
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}