A median of an array of integers of length $$$n$$$ is the number standing on the $$$\lceil {\frac{n}{2}} \rceil$$$ (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with $$$1$$$. For example, a median of the array $$$[2, 6, 4, 1, 3, 5]$$$ is equal to $$$3$$$. There exist some other definitions of the median, but in this problem, we will use the described one.Given two integers $$$n$$$ and $$$k$$$ and non-decreasing array of $$$nk$$$ integers. Divide all numbers into $$$k$$$ arrays of size $$$n$$$, such that each number belongs to exactly one array.You want the sum of medians of all $$$k$$$ arrays to be the maximum possible. Find this maximum possible sum.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of test cases. The first line of the description of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 1000$$$). The second line of the description of each test case contains $$$nk$$$ integers $$$a_1, a_2, \ldots, a_{nk}$$$ ($$$0 \leq a_i \leq 10^9$$$) — given array. It is guaranteed that the array is non-decreasing: $$$a_1 \leq a_2 \leq \ldots \leq a_{nk}$$$. It is guaranteed that the sum of $$$nk$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print a single integer — the maximum possible sum of medians of all $$$k$$$ arrays.

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));
const sub = (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 pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, numberOfArr] = readLine().split(" ").map(Number);
    const arr = readLine().split(" ").map(Number);
    let mid = Math.floor(len / 2);
    if (len % 2 === 0) {
      mid = mid - 1;
    }
    // console.log(`mid`, mid);
    let count = 0;
    let i = 0;
    if (mid === 0) i = len * numberOfArr - len;
    else i = len * numberOfArr - 1 - Math.floor(len / 2);
    let t = numberOfArr;
    while (t--) {
      // console.log(arr[i]);
      count += arr[i];
      if (mid === 0) i -= len;
      else i -= Math.floor(len / 2) + 1;
    }

    console.log(count);
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		var count = 0;
		var list = nextIntArray();
		var sum = 0;
		while(count < K){
			for(var j = 0; j < Math.floor(N / 2); j++){
				list.pop();
			}
			sum += list.pop();
			count++;
		}
		output[i] = sum;
	}
	myout(myconv(output, 9));
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=i.default.nextNumbers(),n=Math.ceil(t/2);i.default.debug(n);let o=0,s=(n-1)*e;for(let i=0;i<e;++i)o+=r[s],s+=t-n+1;i.default.puts(o)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n, k] = io.nextNumbers()
//   let a = io.nextNumbers()
//
//   let m = Math.ceil(n / 2)
//
//   io.debug(m)
//   // io.debug(a)
//
//   let s = 0
//
//   let i = (m - 1) * k
//
//   for (let j = 0; j < k; ++j) {
//     s += a[i]
//
//     i += n - m + 1
//   }
//
//   io.puts(s)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const T = parseInt(lines[curLine++])
  for (let t = 0; t < T; t++) {
    const [n, k] = lines[curLine++].split(' ').map((x) => parseInt(x))
    const arr = lines[curLine++].split(' ').map((x) => parseInt(x)).sort((a, b) => a - b)

    const cLow = Math.floor((n - 1) / 2)
    let ans = 0n
    let curIdx = k * cLow
    for (let i = 0; i < k; i++) {
      ans += BigInt(arr[curIdx])
      curIdx += n - cLow
    }
    console.log(ans.toString())
  }
})

var sizeOfData = readline();
for (var dataI = 0; dataI < sizeOfData; dataI++) {
    var first = readline().split(" ");
    var n = first[0];
    var k = first[1];
    var arr = readline().split(" ");
    var sum = 0;
    var start = arr.length;
    for (var i = 0; i <  k; i++) {
        start = start - (Math.floor(n/2) + 1)
        sum += parseInt(arr[start]);
    }
    print(sum);
}


Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

Print the maximum possible even sum that can be obtained if we use some of the given integers.

NoteIn the first sample, we can simply take all three integers for a total sum of 6.In the second sample Wet Shark should take any four out of five integers 999 999 999.

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  let arr = d.split(' ').map(Number);
  arr.sort((a, b) => b - a);
  arr = arr.map(BigInt);

  let odd = 0;
  let lastOddIdx = 0;
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] % 2n === 1n) {
      odd++;
      lastOddIdx = i;
    }
  }

  let ans = arr.reduce((a, x) => a + x, 0n);

  if (odd % 2) {
    ans -= arr[lastOddIdx];
  }

  console.log(ans.toString());

  c++;
});

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

let input = []
process.stdin.on("data", function (chunk) {
    input += chunk
})

process.stdin.on("end", function () {
    const sentence = input.split('\n')
    const n = sentence[0]
    const integers = sentence[1].split(' ')
    let sum = 0
    let countOdd = 0
    let minOdd = Infinity
    for (let i = 0; i < integers.length; i++) {
        sum += parseInt(integers[i])
        if (parseInt(integers[i]) % 2 === 1) {
            countOdd += 1
            if (parseInt(integers[i]) < minOdd) {
                minOdd = parseInt(integers[i])
            }
        }

    }
    if (countOdd % 2 === 1) {
        sum -= minOdd
    }
    console.log(sum);
})

/**
 * Created by ishanarora on 22/11/18.
 */

const stdin = process.openStdin();
let content = ``;
stdin.addListener('data', d => {
  content += d.toString();
});

stdin.addListener('end', () => {
 content =  content.split("\n");
content[0] = (parseInt(content[0]));
content[1] = content[1].split(" ");
content[1] = content[1].map(elem => parseInt(elem));

console.log(wetShark(content[0], content[1]))

});

function wetShark(count , elems) {

    let sum = 0;
    let deduct = Number.MAX_SAFE_INTEGER;
    for (var i = count - 1; i >= 0; i--) {
        sum += elems[i];
        if (elems[i] % 2 != 0) {
            deduct = Math.min(deduct, elems[i]);
        }
    }

    if (sum % 2 != 0) {
        sum -= deduct;
    }

    return sum;
}

var n = +readline(), a = readline().split(" ").map(Number);

var minOdd = 999999999;
var sum = 0;
for(var i = 0; i < n; ++i){
    sum += a[i];
    if(a[i]%2 == 1){
        minOdd = Math.min(minOdd, a[i]);
    }
}

if(sum%2 == 1){
    sum -= minOdd;
}

write(sum);

function main(n,arr) {

    all_sum = 0;
    smallest_odd = Infinity;

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

      all_sum += arr[i];
      if(arr[i] % 2 === 1)smallest_odd = Math.min(smallest_odd,arr[i]);
    }

    if(all_sum % 2 === 1){
      all_sum -= smallest_odd;
    }

    print(all_sum);

}

var n = parseInt(readline());
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n,arr);

readline();
main.call(0, readNums());
function main(nums) {
    var sum = 0;
    var least = 2000000000;
    for (var i = 0; i < nums.length; i++) {
        var n = nums[i];
        sum += n;
        if ((n & 1) && n < least) {
            least = n;
        }
    }
    if (sum & 1) {
        sum -= least;
    }
    print(sum);
}
function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}
//function readline() {
//    return '999999999 999999999 999999999 999999999 999999999'
//}
//function print(v) {
//    console.log(v)
//}

var n = Number(readline());
var array = readline().split(' ').map(Number);

var sum = 0;

for (var i = 0; i < n; i++) {
	sum += array[i];
}

var even_sum = sum;

if (sum % 2 == 1) {
	array.sort(function(a, b){return a - b;});
	var i = 0;
	while (array[i] % 2 < 1) {
		i++;
	}
	even_sum = sum - array[i];
}

print(even_sum);

var n = readline();
var a = readline().split(" ");
var sum = 0;
var odd = 0;
for (var i = 0; i < n; i++) {
	var t = parseInt(a[i]);
	sum += t;
	odd = (( (odd == 0)|| (t < odd) ) && (t&1)) ? t  : odd;
}
sum = ( !(sum&1) ) ? sum : sum - odd;
print(sum);

var n = parseInt(readline());
var integers = readline().split(' ').map(Number);
var ans = integers.reduce(function(l, r){
    return l + r;
});
var flag = ans;
for(var i = 0; i < integers.length; ++i){
    if(integers[i] & 1){
        flag = Math.min(flag, integers[i]);
    }
}
print(ans & 1 ? ans - flag : ans);

'use strict';

const n = parseInt(readline())
const integers = readline().split(' ').map(Number);

let even = integers.filter((x) => x % 2 === 0)
let odd = integers.filter((x) => x % 2 !== 0)
odd.sort((x,y) => y - x);

let odd_count = odd.length % 2 === 0 ? odd.length : odd.length - 1;
odd = odd.slice(0, odd_count);

let result = even.reduce((p, c) => p + c, 0)
result += odd.reduce((p, c) => p + c, 0);

print(result);

var n = Number(readline());
var str = readline().split(" ", n);
var num = new Array(n);
for (var i = 0; i < n; ++i) {
    num[i] = Number(str[i]);
}

var sum = 0;
var minOdd = 999999999;

for (var i = 0; i < n; ++i) {
    sum += num[i];
    if (num[i] % 2 === 1) {
        minOdd = Math.min(minOdd, num[i]);
    }
}

if (sum % 2 === 0) {
    print(sum);
} else {
    print(sum - minOdd);
}

var n = parseInt(readline());
var numbers = readline().split(' ');

var sum = 0;
var min = Math.pow(10,9);
var count = 0;
var current;

for (var i = 0; i < n; i++) {
    current = parseInt(numbers[i]);
    if (numbers[i] % 2 == 0) sum += current
    else {
        sum += current;
        count++;
        min = Math.min(min, current);
    }
}

if (count % 2 == 1) sum -= min;

print(sum);

/**
 * Created by ishanarora on 22/11/18.
 */

const stdin = process.openStdin();
let content = ``;
stdin.addListener('data', d => {
  content += d.toString();
});

stdin.addListener('end', () => {
 content =  content.split("\n");
content[0] = (parseInt(content[0]));
content[1] = content[1].split(" ");
content[1] = content[1].map(elem => parseInt(elem));

console.log(wetShark(content[0], content[1]))

});

function wetShark(count , elems) {

    elems.sort();

    var prev = -1;
    var sum = 0;
    for (var i = count - 1; i >= 0; i--) {
        if (elems[i] % 2 === 0) {
            sum += elems[i];
        } else {
            if (prev === -1) {
                prev = elems[i];
            } else {
                sum += prev + elems[i];
                prev = -1;
            }
        }
    }
    return sum;
}

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

let input = []
process.stdin.on("data", function (chunk) {
    input += chunk
})

process.stdin.on("end", function () {
    const sentence = input.split('\n')
    const n = sentence[0]
    const integers = sentence[1].split(' ')
    let sum = 0
    let countOdd = 0
    let minOdd = Infinity
    for (let i = 0; i < integers.length; i++) {
        sum += parseInt(integers[i])
        if(parseInt(integers[i])  % 2 === 1) {
            countOdd += 1
        }
        if (parseInt(integers[i]) < minOdd) {
            minOdd = parseInt(integers[i])
        }
    }
    if (countOdd % 2 === 1) {
        sum -= minOdd
    }
    console.log(sum);
})

/**
 * Created by ishanarora on 22/11/18.
 */

const stdin = process.openStdin();
let content = ``;
stdin.addListener('data', d => {
  content += d.toString();
});

stdin.addListener('end', () => {
 content =  content.split("\n");
content[0] = (parseInt(content[0]));
content[1] = content[1].split(" ");
content[1] = content[1].map(elem => parseInt(elem));

console.log(wetShark(content[0], content[1]))

});

function wetShark(count , elems) {

    elems.sort();

    var prev = -1;
    var sum = 0;
    for (var i = count - 1; i >= 0; i--) {
        if(elems[i] < 0){
            continue;
        }
        if (elems[i] % 2 === 0) {
            sum += elems[i];
        } else {
            if (prev === -1) {
                prev = elems[i];
            } else {
                sum += prev + elems[i];
                prev = -1;
            }
        }
    }
    return sum;
}

var n = +readline(), a = readline().split(" ").map(Number);

var minOdd;
var sum = 0;
for(var i = 0; i < n; ++i){
    sum += a[i];
    if(minOdd == undefined && a[i]%2 == 1){
        minOdd = a[i];
    }
}

if(sum%2 == 1){
    sum -= minOdd;
}

write(sum);

var n = +readline(), a = readline().split(" ").map(Number).sort();

var minOdd;
var sum = 0;
for(var i = 0; i < n; ++i){
    sum += a[i];
    if(minOdd == undefined && a[i]%2 == 1){
        minOdd = a[i];
    }
}

if(sum%2 == 1){
    sum -= minOdd;
}

write(sum);

var n = +readline(), a = readline().split(" ").map(Number).sort(function(a, b){ return a < b; });

var minOdd;
var sum = 0;
for(var i = 0; i < n; ++i){
    sum += a[i];
    if(minOdd == undefined && a[i]%2 == 1){
        minOdd = a[i];
    }
}

if(sum%2 == 1){
    sum -= minOdd;
}

write(sum);

function main(n,arr) {

    var total = 0;
    var ans = 0;

    arr.sort();
    for(var i = 0 ; i < n ; i++){
      total += arr[i];

      total % 2 === 0 ? ans = total : ans = ans;
    }

    print(ans);

}

var n = parseInt(readline());
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n,arr);

function main(n,arr) {

    var total = 0;
    var ans = 0;

    for(var i = 0 ; i < n ; i++){
      total += arr[i];

      total % 2 === 0 ? ans = total : ans = ans;
    }

    print(ans);

}

var n = parseInt(readline());
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(n,arr);

var n = readline();
var a = readline().split(" ");
var sum = 0;
var odd = 0;
for (var i = 0; i < n; i++) {
	var t = parseInt(a[i]);
	sum += t;
	odd = ( (odd == 0 && t&1 )|| (t < odd) ) ? t  : odd;
}
sum = ( !(sum&1) ) ? sum : sum - odd;
print(sum);

var n = parseInt(readline());
var integers = readline().split(' ').map(Number);
var ans = integers.reduce(function(l, r){
    return l + r;
});
var flag = ans;
for(var i = 0; i < integers.length; ++i){
    if(integers[i] & 1){
        flag = Math.min(flag, integers[i]);
        break;
    }
}
print(ans & 1 ? ans - flag : ans);

var n = parseInt(readline());
var integers = readline().split(' ').map(Number);
var ans = integers.reduce(function(l, r){
    return l + r;
});
integers = integers.sort();
for(var i = 0; i < integers.length; ++i){
    if(integers[i] & 1){
        ans -= integers[i];
        break;
    }
}
print(ans & 1 ? 0 : ans);

var n = parseInt(readline());
var numbers = readline().split(' ');

var evens = [];
var odds = [];

var sum = 0;

for (var i = 0; i < n; i++) {
    if (numbers[i] % 2 == 0) evens.push(parseInt(numbers[i]))
    else odds.push((parseInt(numbers[i])));
}

for (var i = 0; i < evens.length; i++) {
    sum += evens[i];
}

var isOddsEven = odds.length % 2 == 0 ? 0 : 1;

for (var i = 0; i < odds.length - isOddsEven; i++) {
    sum += odds[i];
}

print(sum);

var n = parseInt(readline());
var numbers = readline().split(' ');

var evens = [];
var odds = [];

var sum = 0;

for (var i = 0; i < numbers.length; i++) {
    if (numbers[i] % 2 == 0) evens.push(parseInt(numbers[i]))
    else odds.push((parseInt(numbers[i])));
}

for (var i = 0; i < evens.length; i++) {
    sum += evens[i];
}

var isOddsEven = odds.length % 2 == 0 ? 0 : 1;

for (var i = 0; i < odds.length - isOddsEven; i++) {
    sum += odds[i];
}

print(sum);


Given the integer $$$n$$$ — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of $$$3$$$ platforms for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places respectively. The platform for the $$$1$$$-st place must be strictly higher than for the $$$2$$$-nd place, and the platform for the $$$2$$$-nd place must be strictly higher than for the $$$3$$$-rd place. Also, the height of each platform must be greater than zero (that is, each platform must contain at least one block).    Example pedestal of $$$n=11$$$ blocks: second place height equals $$$4$$$ blocks, first place height equals $$$5$$$ blocks, third place height equals $$$2$$$ blocks.Among all possible pedestals of $$$n$$$ blocks, deduce one such that the platform height for the $$$1$$$-st place minimum as possible. If there are several of them, output any of them.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case contains a single integer $$$n$$$ ($$$6 \le n \le 10^5$$$) — the total number of blocks for the pedestal. All $$$n$$$ blocks must be used. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^6$$$.

For each test case, output $$$3$$$ numbers $$$h_2, h_1, h_3$$$ — the platform heights for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places on a pedestal consisting of $$$n$$$ blocks ($$$h_1+h_2+h_3=n$$$, $$$0 < h_3 < h_2 < h_1$$$).  Among all possible pedestals, output the one for which the value of $$$h_1$$$ minimal. If there are several of them, output any of them.

NoteIn the first test case we can not get the height of the platform for the first place less than $$$5$$$, because if the height of the platform for the first place is not more than $$$4$$$, then we can use at most $$$4 + 3 + 2 = 9$$$ blocks. And we should use $$$11 = 4 + 5 + 2$$$ blocks. Therefore, the answer 4 5 2 fits. In the second set, the only suitable answer is: 2 3 1.

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());

        if (n % 3 === 0) {
            console.log(n/3, n/3+1, n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);
            } else {
                console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);
            }
        } else {
            console.log((n-2)/3+1, (n-2)/3+2, (n-2)/3-1);
        }
    }

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let input = parseInt(readline());
    Build(input);
  }
}

function Build(n) {
  if (n % 3 == 0) {
    let comp = n / 3;
    print(`${comp} ${comp + 1} ${comp - 1}`);
  } else {
    let comp = Math.ceil(n / 3);
    let mul = 2 * comp;
    if (comp - (n - mul) > 1) print(`${comp - 1} ${comp + 1} ${n - mul}`);
    else print(`${comp} ${comp + 1} ${n - mul - 1}`);
  }
}

/// using js code
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    while (t-- > 0) {
        var a = parseInt(readline());

        var x = parseInt((a+5)/3);
        var y = parseInt(x-1);
        var z = parseInt(a-x-y);
        if(z==0){
            y--;
            z++;
        }
        console.log(`${y} ${x} ${z}`);
    }
}

let response = [];
let solve = function(blocks) {
    let third = Math.floor(blocks / 3);

    if (blocks % 3 === 0) {
        return [third, third + 1, third - 1];
    } else if (blocks % 3 === 1) {
        return [third, third + 2, third - 1];
    } else {
        return [third + 1, third + 2, third - 1]
    }
}

var readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);

let tests = -2;
let test = 0;
rl.on('line', function(line) {
    if (tests < 0) {
        tests = parseInt(line);
    } else {
        response.push(solve(parseInt(line)));

        ++test;
        if (test === tests) {
            rl.close();
        }
    }

    // console.log(tests);
}).on('close',function(){
    response.forEach((list) => {
        list.forEach((item) => {
            process.stdout.write(item + " ");
        })
        process.stdout.write("\n");
    });

    process.exit(0);
});

"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 = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let n = parseInt(readline());
       let a =  Math.floor(n/3);
       let b = Math.floor((n - a)/2);
       let c = n - a -b;
       if(b===c){
            b++;
            c--;
       }
       else{
           if(b<c) [b,c] = [c,b];
       }
       while((a<=b)||(b<=c)||(a<=c)){
            if(a<=b){
                 a++;
                 b--;
            }
            else if(a<=c){
                 a++;
                 c--;
            }
            else if(b<=c){
                 b++;
                 c--;
            }
       }
       console.log(`${b} ${a} ${c}`);
  }
};
solve();

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {
	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;

	/**
	 * readNumber()        - int
	 * readArray()         - generic space separated array
	 * readBoolean()       - bool
	 * readChar()          - char
	 * readLine()          - string
	 * readNumberArray()   - numeric array
	 */

	const solve = () => {
	    let n = inputReader.readNumber();
	    let res = [3, 2, 1];
	    n -= 6;

	    let add = Math.floor(n / 3);
	    res[0] += add + (n % 3 >= 1);
	    res[1] += add + (n % 3 >= 2);
	    res[2] += add;

	    process.stdout.write(res[1] + ' ' + res[0] + ' ' + res[2] + '\n');
	};

	let tc = inputReader.readNumber();

	for(let t = 0; t < tc; ++t)
	    solve();
}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	return {
		readNumber,
	}
}

/** Common Template Starts */

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 => string.trim());
    main();
});

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

/** Commnon Template Ends */

const solve = () => {
    let n = +(readLine());
    let res = [3, 2, 1];
    n -= 6;

    let add = Math.floor(n / 3);

    res[0] += add + (n % 3 >= 1);
    res[1] += add + (n % 3 >= 2);
    res[2] += add;

    process.stdout.write(res[1] + ' ' + res[0] + ' ' + res[2] + '\n');
};

const main = () => {
    const tc = +(readLine());

    for(let t = 0; t < tc; ++t)
        solve();
};

'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 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 d = Math.floor(n/3);
        let r = n%3;

        if (r === 0) {
            output([d, (d+1), (d-1)].join(' '));
        } else if (r === 1) {
            output([d, (d+2), (d-1)].join(' '));
        } else if (r === 2) {
            output([(d+1), (d+2), (d-1)].join(' '));
        }
    }
}

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0 ; i < t; i++){
		let n = nl.num();
		let s = Math.floor(n/3);
		let x = n - s * 3;
		ans.push([s + Math.floor(x/2), s + 1 + Math.ceil(x/2), s-1]);

	}
	console.log(ans.map(e => e.join(' ')).join('\n'));
};

process.stdin.on('end', sol);

let stdinput = '';
process.stdin.on('data', c => stdinput += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = stdinput.split(EOL) /*your input text, split by lines*/
    sol(lines);
});

let getAnswer = (m) => {
  let ost = m%3;
  let v = (m - ost) / 3;
  if (ost === 0) {
    return [v, v+1, v-1];
  } else if (ost === 1) {
    return [v, v+2, v-1];
  } else {
    return [v+1, v+2, v-1];
  }
}

let sol = (input) => {
  let n = parseInt(input[0], 10);
  let mList = [];
  for (let i=1; i<=n; i++) {
    mList.push(parseInt(input[i], 10));
  }

  mList.forEach(m => console.log(getAnswer(m).join(' ')));

}

'use strict';

function solve(n) {
  const a = Math.ceil(n / 3) + 1,
        b = Math.floor((n - a) / 2) + 1,
        c = n - a - b;
  return `${b} ${a} ${c}`;
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', () => {
  inputs = str.split('\n').values();
  main(read);
});

//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 C = Math.floor(N / 3);
		if(N % 3 == 0){
			myout(C + " " + (C + 1) + " " + (C - 1));
		}else if(N % 3 == 1){
			myout(C + " " + (C + 2) + " " + (C - 1));
		}else{
			myout((C + 1) + " " + (C + 2) + " " + (C - 1));
		}
	}
}

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++]
        output[i] = solve(n).join(' ')
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    const r = n % 3
    const k = Math.floor(n / 3)
    if (!r) {
        return [k, k + 1, k - 1]
    } else if (r === 1) {
        return [k, k + 2, k - 1]
    } else if (r === 2) {
        return [k + 1, k + 2, k - 1]
    }
}

function solution(num) {
    fi = 3, se = 2, th = 1;
    many = parseInt((num - 6) / 3);
    rest = parseInt((num - 6) % 3);
    fi += many;
    se += many;
    th += many;
    while(rest > 0) {
        if(rest > 0) {
            fi++;
            rest--;
        }
        if(rest > 0) {
            se++;
            rest--;
        }
        if(rest > 0) {
            th++;
            rest--;
        }
    }
    print(se + " " + fi + " " + th);
}

n = readline()
for( k = 0; k < n ;k++) {
  num = readline();
  solution(num);
}

 var tests = parseInt(readline());
    var n;
    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        var h = Math.floor(n / 3);
        var ans = new Array(3).fill(h);
        var mod = n % 3;
        if (mod == 0) {
            ans[1]++;
            ans[2]--;
        } else if (mod == 1) {
            ans[1]+=2;
            ans[0]+=1;
            ans[2]-=2;
        } else if (mod == 2) {
            ans[1]+=2;
            ans[0]++;
            ans[2]--;
        }
        if (ans[2] == 0) {
            ans[0]--;
            ans[2]++;
        }
        print(ans.join(' '));
    }

var n = parseInt(readline());

while (n--) {
	var m = parseInt(readline());
	var div = parseInt(m / 3);
	var mod = parseInt(m % 3);
	var left = div + (mod - 1 >= 1);
	var mid = div + 1 + (mod >= 1);
	var right = div - 1;
	write(left + " " + mid + " " + right);
	print();
}

T = readline()
while (T--) {
   x = readline()
   a = Math.ceil(x/3)
   b = a+1
   c = x - (a+b)
   if(c ===0){
      a--
      c++
   }
   print(a,b,c)
}

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());

        if (n % 3 === 0) {
            console.log(n/3, n/3+1, n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);
            } else {
                console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);
            }
        } else {
            if ((n-2)/3 > 2) {
                console.log((n-2)/3-1, (n-2)/3+2, (n-2)/3-2);
            } else {
                console.log((n-2)/3, (n-2)/3+1, (n-2)/3-2);
            }
        }
    }

}

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());

        if (n % 3 === 0) {
            console.log(n/3, n/3+1, n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);
            } else {
                console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);
            }
        } else {
            if ((n+1)/3 > 2) {
                console.log((n+1)/3-1, (n+1)/3+2, (n+1)/3-2);
            } else {
                console.log((n+1)/3, (n+1)/3+1, (n+1)/3-2);
            }
        }
    }

}

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());

        if (n % 3 === 0) {
            console.log(n/3 + ' ' +  n/3+1 + ' ' + n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-2);
            } else {
                console.log((n-1)/3 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-1);
            }
        } else {
            if ((n+1)/3 > 2) {
                console.log((n+1)/3-1 + ' ' + (n+1)/3+2 + ' ' + (n+1)/3-2);
            } else {
                console.log((n+1)/3 + ' ' + (n+1)/3+1 + ' ' + (n+1)/3-2);
            }
        }
    }

}

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

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

        if (n % 3 === 0) {
            console.log(n/3 + ' ' +  n/3+1 + ' ' + n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-2);
            } else {
                console.log((n-1)/3 + ' ' + (n-1)/3+2 + ' ' + (n-1)/3-1);
            }
        } else {
            if ((n+1)/3 > 2) {
                console.log((n+1)/3-1 + ' ' + (n+1)/3+2 + ' ' + (n+1)/3-2);
            } else {
                console.log((n+1)/3 + ' ' + (n+1)/3+1 + ' ' + (n+1)/3-2);
            }
        }
    }

}

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

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());

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

        if (n % 3 === 0) {
            console.log(n/3, n/3+1, n/3-1);
        } else if (n % 3 === 1) {
            if ((n-1)/3 > 2) {
                console.log((n-1)/3+1, (n-1)/3+2, (n-1)/3-2);
            } else {
                console.log((n-1)/3, (n-1)/3+2, (n-1)/3-1);
            }
        } else {
            if ((n+1)/3 > 2) {
                console.log((n+1)/3-1, (n+1)/3+2, (n+1)/3-2);
            } else {
                console.log((n+1)/3, (n+1)/3+1, (n+1)/3-2);
            }
        }
    }

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let input = parseInt(readline());
    Build(input);
  }
}

function Build(n) {
  if (n % 3 === 0) {
    let comp = n / 3;
    print(`${comp} ${comp + 1} ${comp - 1}`);
  } else {
    let comp = Math.ceil(n / 3);
    if (comp - (n - 2 * comp) > 1) print(`${comp - 1} ${comp + 1} ${n - (2 * comp)}`);
    else print(`${comp} ${comp + 1} ${n - (2 * comp) - 1}`);
  }
}

Build(8);

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let input = parseInt(readline());
    Build(input);
  }
}

function Build(n) {
  if (n % 3 === 0) {
    let comp = n / 3;
    print(`${comp} ${comp + 1} ${comp - 1}`);
  } else {
    let comp = Math.ceil(n / 3);
    print(`${comp - 1} ${comp + 1} ${n - (2 * comp)}`);
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let input = parseInt(readline());
    Build(input);
  }
}

function Build(n) {
  if (n % 3 == 0) {
    let comp = n / 3;
    print(`${comp} ${comp + 1} ${comp - 1}`);
  } else {
    let comp = Math.ceil(n / 3);
    print(`${comp} ${comp + 1} ${comp - 2}`);
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let input = parseInt(readline());
    Build(input);
  }
}

function Build(n) {
  if (n % 3 === 0) {
    let comp = n / 3;
    print(`${comp} ${comp + 2} ${comp - 1}`);
  } else {
    let comp = Math.ceil(n / 3);
    print(`${comp} ${comp + 2} ${comp - 2}`);
  }
}

/// using js code
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

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

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    while (t-- > 0) {
        var a = parseInt(readline());

        var x = parseInt((a+5)/3);
        var y = parseInt(x-1);
        var z = parseInt(a-x-y);
        if(z==0){
            y--;
            z++;
        }
        console.log(`${x} ${y} ${z}`);
    }
}

let response = [];
let solve = function(blocks) {
    let third = Math.floor(blocks / 3);

    if (blocks % 3 === 0) {
        return [third, third + 1, third - 1];
    } else if (blocks % 3 === 1) {
        return [third, third + 2, third - 1];
    } else {
        return [third + 1, third + 2, third - 1]
    }
}

var readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);

let tests = -2;
let test = 0;
rl.on('line', function(line) {
    if (tests < 0) {
        tests = parseInt(line);
    } else {
        response.push(solve(parseInt(line)));

        ++test;
        if (test === tests) {
            rl.close();
        }
    }

    // console.log(tests);
}).on('close',function(){
    response.forEach((list) => {
        list.forEach((item) => {
            rl.write(item + " ");
        })
        rl.write("\n");
    });

    process.exit(0);
});

let response = [];
let solve = function(blocks) {
    let third = Math.floor(blocks / 3);

    if (blocks % 3 === 0) {
        return [third, third + 1, third - 1];
    } else if (blocks % 3 === 1) {
        return [third, third + 2, third - 1];
    } else {
        return [third + 1, third + 2, third - 1]
    }
}

var readline = require('readline');
var rl = readline.createInterface(process.stdin, process.stdout);

let tests = -2;
let test = 0;
rl.on('line', function(line) {
    if (tests < 0) {
        tests = parseInt(line);
    } else {
        response.push(solve(parseInt(line)));

        ++test;
        if (test === tests) {
            rl.close();
        }
    }

    // console.log(tests);
}).on('close',function(){
    response.forEach((list) => {
        list.forEach((item) => {
            rl.write(item + " ");
        })
        rl.write("\n");
    });
});

"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 = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let n = parseInt(readline());
       let a = n%2===0 ? Math.floor(n/2) : Math.ceil(n/2);
       let b = n - a - 1;
       console.log(`${b} ${a} ${n-(a+b)}`);
  }
};
solve();

function solution(num) {
    fi = 3, se = 2, th = 1;
    many = (num - 6) / 3;
    rest = (num - 6) % 3;
    fi += many;
    se += many;
    th += many;
    while(rest > 0) {
        if(rest > 0) {
            fi++;
            rest--;
        }
        if(rest > 0) {
            se++;
            rest--;
        }
        if(rest > 0) {
            th++;
            rest--;
        }
    }
    print(se + " " + fi + " " + th);
}

n = readline()
for( k = 0; k < n ;k++) {
  num = readline();
  solution(num);
}

function solution(num) {
    fi = 3, se = 2, th = 1;
    many = (num - 6) / 3;
    rest = (num - 6) % 3;
    fi += many;
    se += many;
    th += many;
    while(rest > 0) {
        if(rest > 0) {
            fi++;
            rest--;
        }
        if(rest > 0) {
            se++;
            rest--;
        }
        if(rest > 0) {
            th++;
            rest--;
        }
    }
    console.log(se + " " + fi + " " + th);
}

n = readline()
for( k = 0; k < n ;k++) {
  num = readline();
  print(num);
}


You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings <s1>s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.

The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.

If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.

// 'use strict';

// var s = '[][][{([)})]';
var s = readline();

var impossible = false;

function get_opp(par) {
    if (par == '[') return ']';
    if (par == '<') return '>';
    if (par == '{') return '}';
    if (par == '(') return ')';
    if (par == ']') return '[';
    if (par == ')') return '(';
    if (par == '>') return '<';
    if (par == '}') return '{';
};

function is_op(par) {
    return par == '[' || par == '<' || par == '{' || par == '(';
};

function is_cl(par) {
    return par == ']' || par == '>' || par == '}' || par == ')';
};

var cl = [];
var op = [];

// function find_last_op() {
//     var max = -1;
//     for (var i in queues) {
//         if (is_op(i)) {
//             if (queues[i][queues[i].length - 1] > max) {
//                 max = queues[i][queues[i].length - 1];
//             }
//         }
//     }
//     return max;
// };

// function find_last_cl() {
//     var max = s.length;
//     for (var i in queues) {
//         if (is_cl(i)) {
//             if (queues[i][queues[i].length - 1] < max) {
//                 max = queues[i][queues[i].length - 1];
//             }
//         }
//     }
//     return max;
// };

function check_if_clear() {
    return !(op.length > 0 || cl.length > 0);
};

var cor_l = 0;

for (var i = 0; i < s.length && !impossible; i++) {
    if (is_cl(s[i])) {
        var last_op = op.pop();

        if (last_op === false) {
            impossible = false;
            break;
        }

        if (s[last_op] != get_opp(s[i])) {
            cor_l++;
        }
    } else {
        op.push(i)
    }
}
var cor_r = 0;
impossible = !check_if_clear() || impossible;

for (var i = s.length - 1; i >= 0 && !impossible; i--) {
    if (is_op(s[i])) {
        var last_cl = cl.pop();

        if (last_cl === false) {
            impossible = true;
            break;
        }
        if (s[last_cl] != get_opp(s[i])) {
            cor_r++;
        }
    } else {
        cl.push(i);
    }
}
impossible = !check_if_clear() || impossible;

// console.log(impossible ? 'Impossible' : Math.min(cor_r, cor_l));
print(impossible ? 'Impossible' : Math.min(cor_r, cor_l));

// console.log(cor_l);
// console.log(cor_r);

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        switch (input[i]) {
            case '[': { stack.push(library.BOX); break; }
            case '(': { stack.push(library.ROUND); break; }
            case '{': { stack.push(library.CURLY); break; }
            case '<': { stack.push(library.ANGLE); break; }
            case ']': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.BOX) { counter++ };
                }
                break;
            }
            case ')': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ROUND) { counter++ };
                }
                break;
            }
            case '}': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.CURLY) { counter++ };
                }
                break;
            }
            case '>': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ANGLE) { counter++ };
                }
                break;
            }
        }
    }
    if(stack.length != 0) { return -1; }
    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if (replaces >= 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

var s = readline().split("");
var pairs = { "<": ">", "{": "}", "[": "]", "(": ")" };
var isOpen = b => pairs.hasOwnProperty(b);
var stack = [];
var result = s.reduce((substitutions, b, i) => {
    if ( isOpen(b) ) {
        stack.push(b);
        return substitutions;
    } else {
        var previousB = stack.pop();
        if (previousB) {
            if (pairs[previousB] === b) {
                return substitutions;
            } else {
                return substitutions + 1;
            }
        }
    }
}, 0);

if ( typeof result === "undefined" || stack.length ) {
    result = "Impossible";
}
print(result);

// O(n) time complexity, O(n) additional space, where n is input string length.
var s = [...readline()];
var pairs = { "<": ">", "{": "}", "[": "]", "(": ")" };
var isOpen = b => pairs.hasOwnProperty(b);
var stack = [];
var answer = 0;

for (var b of s) {
    if ( isOpen(b) ) {
        stack.push(b);
    } else {
        var previousB = stack.pop();
        if (previousB) {
            if (pairs[previousB] != b) {
                ++answer;
            }
        } else {
            // Stack is empty - to many close braces.
            answer = undefined;
            break;
        }
    }
}
if ( typeof answer === "undefined" || stack.length ) {
    // If stack is not empty - too many open braces.
    answer = "Impossible";
}
print(answer);

/**
 *  CodeForces/312 C. Replace To Make Regular Bracket Sequence
 *
 *  @author Brooks Mershon
 *
 */

// return Impossible or the least amount of exchanges to fix bracket sequence
function replace(x) {
  var N = x.length,
      count = 0,
      invalid = "Impossible";

  var open  = ['<', '{', '[', '('],
      close = ['>', '}', ']', ')'];

  // scan to check whether the sequence is balanced
  var d = 0;
  for(var i = 0; i < N; i++) {
    d += (open.indexOf(x.charAt(i)) > -1) ? 1 : -1;
    if (d < 0) return invalid;
  }

  if (d !== 0) return invalid;

  var q = [];
  // greedy search for matching parenthesis
  var k = -1;
  while(k < x.length - 1) {
    while(open.indexOf(x.charAt(++k)) > -1) { // iterate to next closing bracket
      q.push(x.charAt(k));
    }
    var opener = q.pop();
    if (open.indexOf(opener) !== close.indexOf(x.charAt(k))) count++;
  }

  return count;
}

// Codeforces I/O
print(replace(readline()));

//module.exports = replace;

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        switch (input[i]) {
            case '[': { stack.push(library.BOX); break; }
            case '(': { stack.push(library.ROUND); break; }
            case '{': { stack.push(library.CURLY); break; }
            case '<': { stack.push(library.ANGLE); break; }
            case ']': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.BOX) { counter++ };
                }
                break;
            }
            case ')': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ROUND) { counter++ };
                }
                break;
            }
            case '}': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.CURLY) { counter++ };
                }
                break;
            }
            case '>': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ANGLE) { counter++ };
                }
                break;
            }
        }
    }
    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if (replaces >= 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        switch (input[i]) {
            case '[': { stack.push(library.BOX); break; }
            case '(': { stack.push(library.ROUND); break; }
            case '{': { stack.push(library.CURLY); break; }
            case '<': { stack.push(library.ANGLE); break; }
            case ']': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.BOX) { counter++ };
                }
                break;
            }
            case ')': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ROUND) { counter++ };
                }
                break;
            }
            case '}': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.CURLY) { counter++ };
                }
                break;
            }
            case '>': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ANGLE) { counter++ };
                }
                break;
            }
        }
    }
    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if (replaces > 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        switch (input[i]) {
            case '[': { stack.push(library.BOX); break; }
            case '(': { stack.push(library.ROUND); break; }
            case '{': { stack.push(library.CURLY); break; }
            case '<': { stack.push(library.ANGLE); break; }
            case ']': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.BOX) { counter++ };
                }
                break;
            }
            case ')': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ROUND) { counter++ };
                }
                break;
            }
            case '}': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.CURLY) { counter++ };
                }
                break;
            }
            case '>': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ANGLE) { counter++ };
                }
                break;
            }
        }
    }
    if (counter !== 0) return -1;
    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if (replaces > 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        switch (input[i]) {
            case '[': { stack.push(library.BOX); break; }
            case '(': { stack.push(library.ROUND); break; }
            case '{': { stack.push(library.CURLY); break; }
            case '<': { stack.push(library.ANGLE); break; }
            case ']': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.BOX) { counter++ };
                }
                break;
            }
            case ')': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ROUND) { counter++ };
                }
                break;
            }
            case '}': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.CURLY) { counter++ };
                }
                break;
            }
            case '>': {
                if (stack.length == 0) { return -1; } else {
                    if (stack.pop() !== library.ANGLE) { counter++ };
                }
                break;
            }
        }
    }
    if (counter === 0) return -1;
    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if (replaces > 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

var input = readline();
var stack = new Array();

var library = {
    ROUND: { value: '()' },
    BOX: { value: '[]' },
    ANGLE: { value: '<>' },
    CURLY: { value: '{}' }
};

function GetNumberOfReplaces(input) {
    var counter = 0;
    for (var i = 0; i <= input.length; i++) {
        if (input[i] == '[') { stack.push(library.BOX); break; }
        if (input[i] == '(') { stack.push(library.ROUND); break; }
        if (input[i] == '{') { stack.push(library.CURLY); break; }
        if (input[i] == '<') { stack.push(library.ANGLE); break; }
        if (input[i] == ']') {
            if (stack.length == 0) { return -1; } else {
                if (stack.pop() === library.BOX) counter++;
            }
            break;
        }
        if (input[i] == ')') {
            if (stack.length == 0) { return -1; } else {
                if (stack.pop() === library.ROUND) counter++;
            }
            break;
        }
        if (input[i] == '}') {
            if (stack.length == 0) { return -1; } else {
                if (stack.pop() === library.CURLY) counter++;
            }
            break;
        }
        if (input[i] == '>') {
            if (stack.length == 0) { return -1; } else {
                if (stack.pop() === library.ANGLE) counter++;
            }
            break;
        }
    }

    if(counter === 0) return -1;

    return counter;
}

var replaces = GetNumberOfReplaces(input);
var result = '';
if(replaces > 0) {
    result = replaces + '';
} else {
    result = 'Impossible';
}

print(result);

// O(n) time complexity, O(n) additional space, where n is input string length.
var s = [...readline()];
var pairs = { "<": ">", "{": "}", "[": "]", "(": ")" };
var isOpen = b => pairs.hasOwnProperty(b);
var stack = [];
var answer = 0;

for (var b of s) {
    if ( isOpen(b) ) {
        stack.push(b);
    } else {
        var previousB = stack.pop();
        if (previousB) {
            if (pairs[previousB] != b) {
                ++answer;
            }
        } else {
            // Stack is empty - to many close braces.
            answer = undefined;
            break;
        }
    }
}
if ( typeof answer === "undefined" || stack.length ) {
    // If stack is not empty - too many open braces.
    result = "Impossible";
}
print(answer);


A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k.You're given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.

The first line of the input contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109). The next line contains a list of n distinct positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). All the numbers in the lines are separated by single spaces.

On the only line of the output print the size of the largest k-multiple free subset of {a1, a2, ..., an}.

NoteIn the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.

var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
var n = inp[0], k = inp[1];
var a = {}, len = new Array(n);
inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
inp.sort(function(a,b){return a - b;});

for(var i = 0; i < n; i++) {
    a[inp[i]] = i;
    if(inp[i] % k == 0 && a[inp[i] / k] != undefined){
        var t = a[inp[i] / k];
        len[i] = len[t] + 1;
        len[t] = 0;
    }
    else len[i] = 1;
}
var ans = 0;
for(var i = 0; i < n; i++)
    ans += Math.floor((len[i] + 1) / 2);
print((k == 1)? n : ans);

var bsearch = function(A, x) {
    var l = 0;
    var r = A.length - 1;
    while (l <= r) {
        var m = Math.floor((r+l) / 2);
        if (A[m] == x) {
            return m;
        }
        else if (A[m] < x) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }
    return -1;
}

var main = function(n, k) {
    if (k == 1) {
        return n;
    }
    A = readline().split(' ').map(Number);
    A.sort(function(a, b) {
        return a - b;});

    var F = Array.apply(null, {length: n}).map(function(x) {return 0});

    var cnt = 0;
    for (var i = n-1; i >= 0; i--) {
        var m = bsearch(A, A[i] * k);
        if (m >= 0 && F[m] == 0) {
            F[i] = 1;
        }
        else {
            cnt += 1;
        }
    }
    return cnt;
}

print(main.apply(null, readline().split(' ').map(Number)));

var bsearch = function(A, x) {
    var l = 0;
    var r = A.length - 1;
    while (l <= r) {
        var m = Math.floor((r+l) / 2);
        if (A[m] == x) {
            return m;
        }
        else if (A[m] < x) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }
    return -1;
}

var main = function(n, k) {
    if (k == 1) {
        return n;
    }
    A = readline().split(' ').map(Number);
    A.sort(function(a, b) {
        return a - b;});

    var F = Array.apply(null,
            new Array(n)).map(Number.prototype.valueOf, 0);

    var cnt = 0;
    for (var i = n-1; i >= 0; i--) {
        var m = bsearch(A, A[i] * k);
        if (m >= 0 && F[m] == 0) {
            F[i] = 1;
        }
        else {
            cnt += 1;
        }
    }
    return cnt;
}

print(main.apply(null, readline().split(' ').map(Number)));

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/
function max(a,b){
    if (a>b)
        return a
        return b
}
function main(input) {
    a=input[0].split(' ')
    n=+a[0]
    k=+a[1]
    a=input[1].split(' ').map(x => +x)
    E=new Object()
    for (i=0;i<n;i++){
        x=0
        if (k>1)
        while(a[i]%k==0){
            a[i]/=k
            ++x
        }
        if (E[a[i]]==undefined){
            E[a[i]]=new Array()
        }
        E[a[i]].push(x)
    }
    ans=0
    function solve(arr,key){
        sort(arr)
        dp=new Array(32)
        for (i=0;i<32;i++)
            dp[i]=0
        K=new Object()
        for (i=0;i<32;i++){
            K[i]=0
        }
        for (i=0;i<arr.length;i++)
        {
            ++K[arr[i]]
        }
        x=0
        for (i=0;i<32;i++)
        {
            dp[i]=K[i]
            if (i==2){
                dp[i]+=dp[i-2]
            } else if (i>2){
                dp[i]+=max(dp[i-2],dp[i-3])
            }
            if (dp[i]>x)
                x=dp[i]
        }
        ans+=x
    }

    for (key in E){
        solve(E[key],key)
    }
    wr(ans)
}

function sort(ar, n, f) {
    var p = Math.ceil(Math.random() * n);
    var i = 0, j = n - 1;
    while(i < j) {
        while(f(ar[i], ar[p]) <= 0) i++;
        while(f(ar[j], ar[p]) > 0) j--;
        if(i < j) {
            var c = ar[i];
            ar[i] = ar[j], ar[j] = c;
        }
        i++; j--;
    }
}

var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
var n = inp[0], k = inp[1];
var a = {}, len = new Array(n);
inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
sort(inp, n, function(a,b){return a - b;});

for(var i = 0; i < n; i++) {
    a[inp[i]] = i;
    if(inp[i] % k == 0 && a[inp[i] / k] != undefined){
        var t = a[inp[i] / k];
        len[i] = len[t] + 1;
        len[t] = 0;
    }
    else len[i] = 1;
}
var ans = 0;
for(var i = 0; i < n; i++)
    ans += Math.floor((len[i] + 1) / 2);
print((k == 1)? n : ans);

var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
var n = inp[0], k = inp[1];
var a = {}, len = new Array(n);
inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
inp.sort(function(a,b){return a - b;});

for(var i = 0; i < n; i++) {
    a[inp[i]] = i;
    if(inp[i] % k == 0 && a[inp[i] / k] != undefined){
        var t = a[inp[i] / k];
        len[i] = len[t] + 1;
        len[t] = 0;
    }
    else len[i] = 1;
}
var ans = 0;
for(var i = 0; i < n; i++)
    ans += Math.floor((len[i] + 1) / 2);
print(ans);

var inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur.trim());});
var n = inp[0], k = inp[1];
var a = {}, c = -1, len = new Array(n);
inp = readline().split(' ').map(function(cur,i,ar){return parseInt(cur);});
inp.sort(function(a,b){return a - b;});

for(var i = 0; i < n; i++) {
    a[inp[i]] = ++c;
    //print(inp[i] + ' ' + c);
    if(inp[i] % k == 0 && a[inp[i] / k] != undefined){
        len[c] = len[a[inp[i] / k]] + 1;
        len[a[inp[i] / k]] = 0;
    }
    else len[c] = 1;
}
var ans = 0;
for(var i = 0; i < n; i++)
    ans += Math.floor((len[i] + 1) / 2);
print(ans);

var bsearch = function(A, x) {
    var l = 0;
    var r = A.length - 1;
    while (l <= r) {
        var m = Math.floor((r+l) / 2);
        if (A[m] == x) {
            return true;
        }
        else if (A[m] < x) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }
    return false;
}

var main = function(n, k) {
    if (k == 1) {
        return n;
    }
    A = readline().split(' ').map(Number);
    A.sort(function(a, b) {
        return a - b;});

    var cnt = 0;
    for (i in A) {
        if (bsearch(A, A[i] * k)) {
            //
        }
        else {
            cnt += 1;
        }
    }
    return cnt;
}

print(main.apply(null, readline().split(' ').map(Number)));

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/
function max(a,b){
    if (a>b)
        return a
        return b
}
function main(input) {
    a=input[0].split(' ')
    n=+a[0]
    k=+a[1]
    a=input[1].split(' ').map(x => +x)
    E=new Object()
    for (i=0;i<n;i++){
        x=0
        if (k>1)
        while(a[i]%k==0){
            a[i]/=k
            ++x
        }
        if (E[a[i]]==undefined){
            E[a[i]]=new Array()
        }
        E[a[i]].push(x)
    }
    ans=0
    function solve(arr,key){
        sort(arr)
        dp=new Array(32)
        for (i=0;i<32;i++)
            dp[i]=0
        K=new Object()
        for (i=0;i<32;i++){
            K[i]=0
        }
        for (i=0;i<arr.length;i++)
        {
            ++K[arr[i]]
        }
        x=0
        for (i=0;i<32;i++)
        {
            dp[i]=K[i]
            if (i==2){
                dp[i]+=dp[i-2]
            } else if (i>2){
                dp[i]+=max(dp[i-2],dp[i-1])
            }
            if (dp[i]>x)
                x=dp[i]
        }
        wr(key,arr,x)
        ans+=x
    }

    for (key in E){
        solve(E[key],key)
    }
    wr(ans)
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/
function max(a,b){
    if (a>b)
        return a
        return b
}
function main(input) {
    a=input[0].split(' ')
    n=+a[0]
    k=+a[1]
    a=input[1].split(' ').map(x => +x)
    E=new Object()
    for (i=0;i<n;i++){
        x=0
        while(a[i]%k==0){
            a[i]/=k
            ++x
        }
        if (E[a[i]]==undefined){
            E[a[i]]=new Array()
        }
        E[a[i]].push(x)
    }
    ans=0
    function solve(arr){
        sort(arr)
        dp=new Array(32)
        for (i=0;i<32;i++)
            dp[i]=0
        K=new Object()
        for (i=0;i<32;i++){
            K[i]=0
        }
        for (i=0;i<arr.length;i++)
        {
            ++K[arr[i]]
        }
        x=0
        for (i=0;i<32;i++)
        {
            dp[i]=K[i]
            if (i==2){
                dp[i]+=dp[i-2]
            } else if (i>2){
                dp[i]+=max(dp[i-2],dp[i-1])
            }
            if (dp[i]>x)
                x=dp[i]
        }
        ans+=x
    }

    for (key in E){
        solve(E[key])
    }
    wr(ans)
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/
function max(a,b){
    if (a>b)
        return a
        return b
}
function main(input) {
    a=input[0].split(' ')
    n=+a[0]
    k=+a[1]
    a=input[1].split(' ').map(x => +x)
    E=new Object()
    for (i=0;i<n;i++){
        x=0
        if (k>1)
        while(a[i]%k==0){
            a[i]/=k
            ++x
        }
        if (E[a[i]]==undefined){
            E[a[i]]=new Array()
        }
        E[a[i]].push(x)
    }
    ans=0
    function solve(arr,key){
        sort(arr)
        dp=new Array(32)
        for (i=0;i<32;i++)
            dp[i]=0
        K=new Object()
        for (i=0;i<32;i++){
            K[i]=0
        }
        for (i=0;i<arr.length;i++)
        {
            ++K[arr[i]]
        }
        x=0
        for (i=0;i<32;i++)
        {
            dp[i]=K[i]
            if (i==2){
                dp[i]+=dp[i-2]
            } else if (i>2){
                dp[i]+=max(dp[i-2],dp[i-1])
            }
            if (dp[i]>x)
                x=dp[i]
        }
        ans+=x
    }

    for (key in E){
        solve(E[key],key)
    }
    wr(ans)
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

/*/====================
var fs = require('fs');

fs.readFile('input.txt', 'utf8', function(err, arr) {
    main(arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, '')))
})
//====================*/
function max(a,b){
    if (a>b)
        return a
        return b
}
function main(input) {
    a=input[0].split(' ')
    n=+a[0]
    k=+a[1]
    a=input[1].split(' ').map(x => +x)
    E=new Object()
    for (i=0;i<n;i++){
        x=0
        if (k>1)
        while(a[i]%k==0){
            a[i]/=k
            ++x
        }
        if (E[a[i]]==undefined){
            E[a[i]]=new Array()
        }
        E[a[i]].push(x)
    }
    ans=0
    function solve(arr,key){
        sort(arr)
        dp=new Array(32)
        for (i=0;i<32;i++)
            dp[i]=0
        K=new Object()
        for (i=0;i<32;i++){
            K[i]=0
        }
        for (i=0;i<arr.length;i++)
        {
            ++K[arr[i]]
        }
        x=0
        for (i=0;i<32;i++)
        {
            dp[i]=K[i]
            if (i==2){
                dp[i]+=dp[i-2]
            } else if (i>2){
                dp[i]+=max(dp[i-2],dp[i-1])
            }
            if (dp[i]>x)
                x=dp[i]
        }
        wr(key,arr,x)
        ans+=x
    }

    for (key in E){
        solve(E[key],key)
    }
}


You have a string $$$s$$$ consisting of digits from $$$0$$$ to $$$9$$$ inclusive. You can perform the following operation any (possibly zero) number of times:   You can choose a position $$$i$$$ and delete a digit $$$d$$$ on the $$$i$$$-th position. Then insert the digit $$$\min{(d + 1, 9)}$$$ on any position (at the beginning, at the end or in between any two adjacent digits). What is the lexicographically smallest string you can get by performing these operations?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ of the same length if and only if the following holds:   in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a smaller digit than the corresponding digit in $$$b$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then the test cases follow. Each test case consists of a single line that contains one string $$$s$$$ ($$$1 \le |s| \le 2 \cdot 10^5$$$) — the string consisting of digits. Please note that $$$s$$$ is just a string consisting of digits, so leading zeros are allowed. It is guaranteed that the sum of lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Print a single string — the minimum string that is possible to obtain.

NoteIn the first test case:   Delete $$$8$$$ and insert $$$9$$$ at the end of the notation. The resulting notation is $$$04299$$$.  Delete $$$4$$$ and insert $$$5$$$ in the $$$3$$$-rd position of the notation. The resulting notation is $$$02599$$$. Nothing needs to be done in the second and third test cases.

var t = +readline()
while (t--) {
    var str = readline()
    min = 9

    var tmp = []

    for (var i = str.length - 1; i >= 0; i--) {
        if (str[i] <= min) {
            min = str[i]
            tmp.push(min)
        } else {
            tmp.push(Math.min(Number(str[i]) + 1, 9))
        }
    }

    var ans = tmp.sort(function (a, b) { return a - b }).join("")
    print(ans)
}

var t = +readline()
while (t--) {
    var str = readline()
    min = 9

    var tmp = []
    var tmp2 = []

    for (var i = str.length - 1; i >= 0; i--) {
        if (str[i] <= min) {
            min = str[i]
            tmp2.push(min)
        } else {
            tmp.push(Math.min(Number(str[i]) + 1, 9))
        }
    }

    var ans = tmp.concat(tmp2).sort(function (a, b) { return a - b }).join("")
    print(ans)
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(read) {
  const nums = read().split('').map((s, i) => [Number(s), i]),
        n = nums.length;
  const a = new Heap((a, b) => {
    if (a[0] !== b[0]) return a[0] - b[0];
    return a[1] - b[1];
  });
  for (let i = 0; i < n; i++) a.push(nums[i]);
  const b = new Heap((a, b) => a - b);
  const res = [];
  for (let i = 0; i < n; i++) {
    while (a.size() && a.top()[1] < i) a.pop();
    if (!a.size()) break;
    while (b.size() && b.top() <= a.top()[0]) {
      res.push(b.pop());
    }
    if (a.top()[0] === nums[i][0]) {
      res.push(nums[i][0]);
      a.pop();
    } else {
      b.push(Math.min(nums[i][0] + 1, 9));
    }
  }
  while (b.size()) {
    res.push(b.pop());
  }
  return res.join('');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

"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 arr = readline().trim().split("").map(cur=>parseInt(cur));
          for(let i=0;i<arr.length;i++) arr[i] = [arr[i],i];
          arr.sort((a,b)=>{
               if(a[0]===b[0]) return a[1]-b[1];
               else return a[0]-b[0];
               });
          let max = arr[0][1];
          for(let i=0;i<arr.length;i++){
               if(arr[i][1]<max) arr[i][0] = Math.min(arr[i][0]+1,9);
               max = Math.max(max,arr[i][1]);
          }
          arr.sort((a,b)=>a[0]-b[0]);
          let res = [];
          for(let i=0;i<arr.length;i++) res.push(arr[i][0]);
          console.log(res.join(""));
     }
};
solve();

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(read) {
  const nums = read().split('').map((s, i) => [Number(s), i]),
        n = nums.length;
  const a = new Heap((a, b) => {
    if (a[0] !== b[0]) return a[0] - b[0];
    return a[1] - b[1];
  });
  for (let i = 0; i < n; i++) a.push(nums[i]);
  const b = new Heap((a, b) => a - b);
  const res = [];
  for (let i = 0; i < n; i++) {
    while (a.size() && a.top()[1] < i) a.pop();
    if (!a.size()) break;
    while (b.size() && b.top() === a.top()[0]) {
      res.push(b.pop());
    }
    if (a.top()[0] === nums[i][0]) {
      res.push(nums[i][0]);
      a.pop();
    } else {
      b.push(Math.min(nums[i][0] + 1, 9));
    }
  }
  while (b.size()) {
    res.push(b.pop());
  }
  return res.join('');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

"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 arr = readline().trim().split("").map(cur=>parseInt(cur));
          for(let i=0;i<arr.length;i++) arr[i] = [arr[i],i];
          arr.sort((a,b)=>{
               if(a[0]===b[0]) return a[1]-b[1];
               else return a[0]-b[0];
               });
          let max = arr[0][1];
          for(let i=0;i<arr.length;i++){
               if(arr[i][1]<max) arr[i][0] = Math.min(arr[i][0]+1,9);
               max = Math.max(max,arr[i][1]);
          }
          let res = [];
          for(let i=0;i<arr.length;i++) res.push(arr[i][0]);
          console.log(res.join(""));
     }
};
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 arr = readline().trim().split("").map(cur=>parseInt(cur));
          for(let i=0;i<arr.length;i++) arr[i] = [arr[i],i];
          arr.sort((a,b)=>{
               if(a[0]===b[0]) return a[1]-b[1];
               else return a[0]-b[0];
               });
          let flag = 0;
          for(let i=1;i<arr.length;i++){
               if(flag===1){
                    arr[i][0] = Math.min(arr[i][0]+1,9);
                    continue;
               }
               if(arr[i-1][1]>arr[i][1]){
                    flag = 1;
                    arr[i][0] = Math.min(arr[i][0]+1,9);
               }
          }
          let res = [];
          for(let i=0;i<arr.length;i++) res.push(arr[i][0]);
          console.log(res.join(""));
     }
};
solve();