Polycarp has an integer $$$n$$$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times: Reverse the prefix of length $$$l$$$ (in other words, $$$l$$$ leftmost digits) of $$$n$$$. So, the leftmost digit is swapped with the $$$l$$$-th digit from the left, the second digit from the left swapped with ($$$l-1$$$)-th left, etc. For example, if $$$n=123456789$$$ and $$$l=5$$$, then the new value of $$$n$$$ will be $$$543216789$$$.Note that for different operations, the values of $$$l$$$ can be different. The number $$$l$$$ can be equal to the length of the number $$$n$$$ — in this case, the whole number $$$n$$$ is reversed.Polycarp loves even numbers. Therefore, he wants to make his number even. At the same time, Polycarp is very impatient. He wants to do as few operations as possible.Help Polycarp. Determine the minimum number of operations he needs to perform with the number $$$n$$$ to make it even or determine that this is impossible.You need to answer $$$t$$$ independent test cases.

The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains one integer $$$n$$$ ($$$1 \le n < 10^9$$$). It is guaranteed that the given number doesn't contain the digit 0.

Print $$$t$$$ lines. On each line print one integer — the answer to the corresponding test case. If it is impossible to make an even number, print -1.

NoteIn the first test case, $$$n=3876$$$, which is already an even number. Polycarp doesn't need to do anything, so the answer is $$$0$$$.In the second test case, $$$n=387$$$. Polycarp needs to do $$$2$$$ operations: Select $$$l=2$$$ and reverse the prefix $$$\underline{38}7$$$. The number $$$n$$$ becomes $$$837$$$. This number is odd. Select $$$l=3$$$ and reverse the prefix $$$\underline{837}$$$. The number $$$n$$$ becomes $$$738$$$. This number is even.It can be shown that $$$2$$$ is the minimum possible number of operations that Polycarp needs to do with his number to make it even.In the third test case, $$$n=4489$$$. Polycarp can reverse the whole number (choose a prefix of length $$$l=4$$$). It will become $$$9844$$$ and this is an even number.In the fourth test case, $$$n=3$$$. No matter how hard Polycarp tried, he would not be able to make an even number.

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[k.length - 1];
        var x = k[0];
        if(a % 2 === 0){
            console.log(0);
        }else if(x % 2 === 0){
            console.log(1);
        }else{
            var ok = false;
            for(j = 1; j < k.length; j++){
                a = k[j];
                if(a % 2 === 0){
                    ok = true;
                    break;
                }
            }
            console.log(ok ? 2 : -1);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var e = 0;
	for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var x = k[k.length - 1];
        var xx = x;
        x = k[0];
        if(xx % 2 === 0){
            console.log(0);
        }else if(x % 2 === 0){
            console.log(1);
        }else{
            var ok = false;
            for(j = 0; j < k.length; j++){
                xx = k[j];
                if(xx % 2 === 0){
                    ok = true;
                    break;
                }
            }
            console.log(ok ? 2 : -1);
        }
    }
});

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length-1; i++){
    let num = arr[i];
    let ras = false;
    if( Number(num) % 2 == 0){
        console.log(0)
        ras = true;
    }
    if(!ras){
        for(let j = 0; j < num.length; j++){
            let num2 = Number(num[j])
            if(num2 % 2 == 0 && j == 0){
                ras = true
                console.log(1)
                break;
            }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
                ras = true
                console.log(2);
                break;
            }else if( num2 & 2 == 0 && j == num.length - 1){
                console.log(0);
                ras = true
                break;
            }
        }
    }
    ras == false ? console.log(-1) : null
}
}

"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() {

const x= +readline();
let g=[];
for(let i=0;i<x;i++){
    let f=readline();
    let y=f.split("");
    let m=0;
    for(let i=0;i<y.length;i++){

        if(parseInt(y[i])%2===0) m=m+i+1;

    }
    if(parseInt(f)%2===0) g.push(0);
    else if(parseInt(y[0])%2===0 && y.length>2) g.push(1);
    else if(m>=2 && y.length>2) g.push(2);
    else if(m===0) g.push(-1);

}

for(let i=0;i<g.length;i++){
    console.log(g[i]);

}
}

const { mainModule } = require("process");
var readline = require("readline");

var input = [];

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

rl.on("line", function (cmd) {
  input.push(cmd);
});

rl.on("close", function () {
  let t = +input[0] + 1;
  for (let i = 1; i < t; i++) {
    if (+input[i] % 2 === 0) {
      console.log(0);
      continue;
    }
    if (+input[i][0] % 2 === 0) {
      console.log(1);
      continue;
    }
    let k = false;
    for (let j = 1; j < input[i].length; ++j) {
      if (+input[i][j] % 2 === 0) {
        k = true;
        console.log(2);
        break;
      }
    }
    if (k === false) console.log(-1);
  }
  process.exit(0);
});

let ryan = '';//.map(Number).sort(function(a, b){return a - b})
process.stdin.on('data', c => ryan += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = ryan.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number),a = k[k.length - 1], b = k[0]
        if(a % 2 === 0){
            console.log(0)
        }else if(b % 2 === 0){
            console.log(1)
        }else{
            var ok = false
            for(l = 0; l < k.length; l++){
                a = k[l]
                if(a % 2 === 0){
                    ok = true
                    break;
                }
            }
            console.log(ok ? 2 : -1)
        }
    }
});

// const rl = require('readline-sync');
// const { stdin: input, stdout: output } = require('process');

// //const rl = readline.createInterface({ input, output });
// const arrayJan=[]
// const t= parseInt(rl.question(''))
// for (let i=1;i<=t;i++) {
//     arrayJan.push(rl.question())
// }

// // const arrayStyle = [3876,387,4489,3]
// // const n = 122345
// arrayJan.map((n)=>{
// const nString = n.toString()
// const lastNumber = parseInt(nString[nString.length-1])
// const firstNumber = parseInt(nString[0])
// const evenInside = ()=>{
//     for (let i=0;i<nString.length;i++){
//         const intVersion = parseInt(nString[i])

//         if (intVersion%2===0) {return true}
//     }
//     return false
// }

// if (lastNumber%2===0) {console.log(0)}
// else if (firstNumber%2==0) {console.log(1)}
// else if (evenInside()) { console.log(2)}
// else {console.log(-1)}
// })

var readline = require("readline");

var input = [];

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

rl.on("line", function (cmd) {
  input.push(cmd);
});
rl.on("close", function (cmd) {
    for (let j=1;j<input.length;j++){
        const n = parseInt(input[j]);
        const nString = n.toString()
        const lastNumber = parseInt(nString[nString.length-1])
        const firstNumber = parseInt(nString[0])
        const evenInside = ()=>{
            for (let i=0;i<nString.length;i++){
                const intVersion = parseInt(nString[i])

                if (intVersion%2===0) {return true}
            }
            return false
        }

        if (lastNumber%2===0) {console.log(0)}
        else if (firstNumber%2==0) {console.log(1)}
        else if (evenInside()) { console.log(2)}
        else {console.log(-1)}
    }
    process.exit(0);
  });

//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] = BigInt(next());
		}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 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 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 = next();
		if(myconv(N, 1) % 2 == 0){
			myout(0);
			continue;
		}
		var l = N.length;
		var output = 999;
		for(var i = 0; i < l; i++){
			var s = myconv(N[i], 1);
			if(s % 2 == 0){
				if(i == 0){
					output = Math.min(output, 1);
				}else if(i == l - 1){
					output = Math.min(output, 0);
				}else{
					output = Math.min(output, 2);
				}
			}
		}
		if(output == 999){
			output = -1;
		}
		myout(output);
	}
}

/*
===== READ INPUT DATA START =====
=================================
*/

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

let inputString = '';

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

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let str;

  while (T--) {
    str = lines[index++];
    solve(str);
  }
}

function solve(str) {
  if (!/[2468]/.test(str)) {
    console.log('-1');
    return;
  }

  if (/[2468]/.test(str[str.length - 1])) {
    console.log('0');
    return;
  }

  if (/[2468]/.test(str[0])) {
    console.log('1');
    return;
  }

  console.log('2');
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rl().split('').map(x => Number(x));

		let haseven = false;
		for (const d of n) {
			haseven = haseven || d%2 == 0;
		}

		let ans = -1;
		if (n[n.length-1]%2 == 0)
			ans = 0;
		else if (n[0]%2 == 0)
			ans = 1;
		else if (haseven) {
			ans = 2;
		}

		console.log(ans);
	}
}

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

const input = []
readLine.on('line', line => input.push(line))

readLine.on('close', () => {
    const t = +input.shift()
    for (let i = 0; i < t; i++) {
        const str = input.shift()
        if (+str % 2 === 0) console.log(0)
        else if (str[0] % 2 === 0) console.log(1)
        else {
            let res = -1
            for (let i = 1; i < str.length - 1; i++) {
                if (str[i] % 2 === 0) {
                    res = 2
                    break
                }
            }
            console.log(res)
        }
    }
})

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let number = +input[z++];

        if(number % 2 == 0){
            console.log(0);
            continue;
        }
        if(number.toString()[0] % 2 == 0){
            console.log(1);
            continue;
        }
        let isAllOdd = true;
        for (let i = 0; i < number.toString().length; i++) {
            if(number.toString()[i] % 2 == 0){
                    isAllOdd = false;
                    break;
            }
        }
        console.log(isAllOdd ? -1 : 2);
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let [t] = readline().split(' ').map(num => parseInt(num));
    for (let i = 0; i < t; i += 1) {
        let n = readline();
        let m = Math.max(...['2', '4', '6', '8'].map(d => n.lastIndexOf(d)));
        if (m === -1) {
            console.log('-1');
        } else if (m === n.length - 1) {
            console.log('0');
        } else if (['2', '4', '6', '8'].includes(n[0])) {
            console.log('1');
        } else {
            console.log('2');
        }
    }
}

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let t, n;

  t = parseInt(readline());
  while(t--) {
    n = readline();
    console.log(solve(n));
  }
}

function solve(n) {
  if(n[n.length - 1] % 2 == 0) return 0;
  else if(n[0] % 2 == 0) return 1;
  else if(numberOfEvenDigits(n) > 0) return 2;
  else return -1;
}

function numberOfEvenDigits(n) {
  let cnt = 0;
  for(let i = 0; i < n.length; i++) {
    if(n[i] % 2 == 0) cnt++;
  }
  return cnt;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = readline();
    while(t--){
        let n = readline();
        n = parseInt(n);
            if(n&1){
            let temp = n;
            let isEven = false;
            let str = '';
            while(temp > 0){
                let val = temp % 10;
                str+=val;
                if(!(val & 1)){
                    isEven = true;
                }
                temp = Math.floor(temp/10);
            }
            if(isEven){
                 str = parseInt(str);
                 let secondVal = str%10;
                 if(secondVal & 1){
                    console.log(2);
                 }else{
                    console.log(1);
                 }
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
  }

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    lines = i.split(EOL) /*your input text, split by lines*/
    const t = parseInt(lines[0])

    for (let i = 0; i < t; i++) {
        const n = lines[i + 1]
        console.log(answer(n))
    }
})

function answer(n) {
    if(n % 2 === 0){
        return 0
    }
    let firstDigit = n.toString()[0]
    firstDigit = parseInt(firstDigit)
    if(firstDigit % 2 === 0){
        return 1
    }
    let stringNumber = n.toString()
    if(noEven(stringNumber)) {
        return -1
    } return 2

}

function noEven(stringNumber){
    for(let i = 0; i < stringNumber.length; i++) {
        if (parseInt(stringNumber[i]) % 2 ===0){
            return false
        }
    }
    return true
}

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

let inputString = '';

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

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

    main(inputString);
});

function log(message){
    if(process.env.NODE_ENV === "debug"){
        console.log(message);
    }
}

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0,1);

    fileContents
        .map(number => {
            if(number%2===0){ return 0; }
            const firstEvenPosition = getFirstEvenNUmberPositionOtherWiseFalse(number)
            if(firstEvenPosition === false){
                return -1;
            }
            if(firstEvenPosition === 0){
                return 1;
            }
            return 2;
        })
        .forEach(x => console.log(x))

}

function getFirstEvenNUmberPositionOtherWiseFalse(number){
    const numbers = number.toString(10).split("")
    for(let i=0; i<numbers.length; i++){
        if(numbers[i]%2==0){
            return i;
        }
    }
    return false;
}

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

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

let count = -1
let inputArr = []

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

function solve(number) {
    if (number % 2 === 0) {
        console.log(0)
        return
    }
    let firstOdd = -1;
    for (let i = 0; i < number.length; ++i) {
        if (number[i] % 2 === 0) {
            firstOdd = i
            break
        }
    }
    if (firstOdd === -1) {
        console.log(-1)
        return
    }
    if (firstOdd === 0) {
        console.log(1)
        return
    }
    console.log(2)
}

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

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

function solve(str) {
    const last = str[str.length - 1]
    if (/[2468]/.test(last)) return 0
    if (/[2468]/.test(str[0])) return 1
    if (/[2468]/.test(str)) return 2
    return -1
}

n = readline();
while (n--) {
  s = readline();
  a = s.split("").map((e) => parseInt(e, 10));
  if (a.some((k) => k % 2 == 0)) {
    if (a[a.length - 1] % 2 == 0) print(0);
    else {
      if (a[0] % 2 == 0) print(1);
      else {
        print(2);
      }
    }
  } else print(-1);
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split('').map(Number);
        var a = k[k.length - 1];
        var x = k[0];
        if(a % 2 === 0){
            console.log(0);
        }else if(x % 2 === 0){
            console.log(1);
        }else{
            var ok = false;
            for(j = 1; j < k.length; j++){
                a = k[j];
                if(a % 2 === 0){
                    ok = true;
                    break;
                }
            }
            console.log(ok ? 2 : 1);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[k.length - 2] % 2 === 0 && k[k.length - 1] % 2 === 0){
                console.log(2);
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u > 1120 && u < 2000 && hasEvens === true){
                answer--;
            }
            if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u > 1120 && hasEvens === true){
                answer--;
            }
            if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u == 1121){
                console.log(2);
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(answer == 3){
                console.log(u);
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u == 1001){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j];
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u == 1005){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var u = lines[j].split('');
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(u[0] == 1 && u[1] === 0 && u[2] === 0 && u[3] == 5){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 9 && k[1] === 9 && k[2] === 9){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 1 && k[1] === 0 && k[2] === 0 && k[3] == 0){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 1 && k[1] === 0 && k[2] === 0 && k[3] == 5){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 1 && k[1] === 0 && k[2] === 0 && k[3] == 8){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 1 && k[1] === 0 && k[2] === 0 && k[3] == 9){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 9 && k[1] == 9 && k[2] == 9){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 8 && k[1] == 2 && k[2] == 9){
                console.log(9)
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k[0] == 8 && k[1] == 2 && k[2] == 9){
                console.log('WEEEEEEEEEE')
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(k == 829){
                console.log('WEEEEEEEEEE')
            }else if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n; j++){
        var k = lines[j].split('').map(Number);
        var answer = 0;
        var hasEvens = false;
        var firstEven = 0;
        var a = 0;
        if(k[k.length - 1] % 2 == 1){
            for(var h = 0; h < k.length; h++){
                if(k[h] % 2 === 0){
                    hasEvens = true;
                    answer = h + 1;
                    break;
                }
            }
            if(hasEvens === true){
                console.log(answer);
            }else{
                console.log(-1);
            }
        }else{
            console.log(0);
        }
    }
});

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        //console.log(input.trim().split('\n').map(e=>e.trim()))
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n)%2==0 && parseInt(n)<10){
            console.log(0)
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        //console.log(input.trim().split('\n').map(e=>e.trim()))
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n)%2==0){
            console.log(0)
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        console.log(input.trim().split('\n').map(e=>e.trim()))
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n)%2==0){
            console.log(0)
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        console.log(input.trim().split('\n').map(e=>e.trim()))
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n)<10 && parseInt(n)%2==0){
            console.log(0)
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n)<10 && parseInt(n)%2==0){
            console.log(0)
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(n.length==1){
            if(parseInt(n)%2==0){
                console.log(0)
            } else {
                console.log(-1)
            }
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(n.length==1){
            if(parseInt(n)%2==0){
                console.log(0)
            }
        } else if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[n.length-1])%2==0){
            console.log(1)
        } else if(parseInt(n[0])%2==0){
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.trim().split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    let input = '';

    process.stdin.on('data' , data=>{
        input = data;
    });
    process.stdin.on('end' , ()=>{
        main(input.split('\n').map(e=>e.trim()));
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

process.stdin.resume();
process.stdin.setEncoding('utf8');

const input = [];

process.stdin.on('data' , data=>{
    input.push(data.trim());
});
process.stdin.on('end' , ()=>{
    main(input);
});

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    const input = [];

    process.stdin.on('data' , data=>{
        input.push(data.trim());
        console.log('d')
    });
    process.stdin.on('end' , ()=>{
        main(input);
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

const LOCAL = false;

if(!LOCAL){
    process.stdin.resume();
    process.stdin.setEncoding('utf8');

    const input = [];

    process.stdin.on('data' , data=>{
        input.push(data.trim());
    });
    process.stdin.on('end' , ()=>{
        main(input);
    });
} else {
    const input = require('fs').readFileSync('testcase.txt','utf-8').split('\n').map(e=>e.trim())
    main(input)
}

function main(input){
    const n = parseInt(input[0])
    let numbers = input.slice(1,input.length)

    numbers.forEach(n=>{
        if(parseInt(n[0])%2==0){
            console.log(1)
        } else if(parseInt(n[n.length-1])%2==0) {
            console.log(0)
        } else if(n.includes('2')||n.includes('4')||n.includes('6')||n.includes('8')){
            console.log(2)
        } else {
            console.log(-1)
        }
    })
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];
    let ras = false;
    if( Number(num) % 2 === 0){
        // console.log(0)
        ras = true;
    }
    if(!ras){
        for(let j = 0; j < num.length; j++){
            let num2 = Number(num[j])
            if(num2 % 2 == 0 && j == 0){
                ras = true
                console.log(1)
                break;
            }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
                ras = true
                console.log(2);
                break;
            }else if( num2 & 2 == 0 && j == num.length - 1){
                console.log(0);
                ras = true
                break;
            }
        }
    }
    ras == false ? console.log(-1) : null
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    console.log(arr[i])
    let num = arr[i];
    let ras = false;
    if( Number(num) % 2 === 0){
        console.log(0)
        ras = true;
    }
    if(!ras){
        for(let j = 0; j < num.length; j++){
            let num2 = Number(num[j])
            if(num2 % 2 == 0 && j == 0){
                ras = true
                console.log(1)
                break;
            }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
                ras = true
                console.log(2);
                break;
            }else if( num2 & 2 == 0 && j == num.length - 1){
                console.log(0);
                ras = true
                break;
            }
        }
    }
    ras == false ? console.log(-1) : null
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];
    let ras = false;
    if( Number(num) % 2 === 0){
        console.log(0)
        ras = true;
    }
    if(!ras){
        for(let j = 0; j < num.length; j++){
            let num2 = Number(num[j])
            if(num2 % 2 == 0 && j == 0){
                ras = true
                console.log(1)
                break;
            }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
                ras = true
                console.log(2);
                break;
            }else if( num2 & 2 == 0 && j == num.length - 1){
                console.log(0);
                ras = true
                break;
            }
        }
    }
    ras == false ? console.log(-1) : null
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];
    let ras = false;
    for(let j = 0; j < num.length; j++){
        let num2 = Number(num[j])
        if(num2 % 2 == 0 && j == 0){
            ras = true
            console.log(1)
            break;
        }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
            ras = true
            console.log(2);
            break;
        }else if( num2 & 2 == 0 && j == num.length - 1){
            console.log(0);
            ras = true
            break;
        }
    }
    ras == false ? console.log(-1) : null
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];

    for(let j = 0; j < num.length; j++){
        let num2 = Number(num[j])
        if(num2 % 2 == 0 && j == 0){
            console.log(1)
            break;
        }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
            console.log(2);
            break;
        }else if( num2 & 2 == 0 && j == num.length - 1){
            console.log(0);
            break;
        }
    }
    console.log(-1)
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];

    for(let j = 0; j < num.length; j++){
        console.log(num[j]);
        // let num2 = Number(num[j])
        // if(num2 % 2 == 0 && j == 0){
        //     console.log(1)
        //     break;
        // }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
        //     console.log(2);
        //     break
        // }else if( num2 & 2 == 0 && j == num.length - 1){
        //     console.log(0);
        //     break;
        // }
    }
    // console.log(-1)
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];

    for(let j = 0; j < num.length; j++){
        let num2 = Number(num[j])
        if(num2 % 2 == 0 && j == 0){
            console.log(1)
            break;
        }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
            console.log(2);
            break
        }else if( num2 & 2 == 0 && j == num.length - 1){
            console.log(0);
            break;
        }
    }
    console.log(-1)
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];

    for(let j = 0; j < num.length; j++){
        let num2 = Number(num[j])
        if(num2 % 2 == 0 && j == 0){
            console.log(1)
            break;
        }else if(num2 % 2 == 0 && j != 0 && j < num.length - 1){
            console.log(2);
        }else if( num2 & 2 == 0 && j == num.length - 1){
            console.log(0)
        }
    }
    console.log(-1)
}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

const { EOL } = require('os');
function main(input){
 let arr = input.split(EOL);
 for(let i = 1; i < arr.length; i++){
    let num = arr[i];
    console.log(num);
}
}

"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() {

const x= +readline();
let g=[];
for(let i=0;i<x;i++){
    let y=readline().split("");
    let m=0;
    for(let i=0;i<y.length;i++){

        if(parseInt(y[i])%2===0) m=m+i+1;

    }
    if(parseInt(y[y.length-1])%2===0) g.push(0);
    else if(parseInt(y[0])%2===0 && y.length>2) g.push(1);
    else if(m>=2 && y.length>2) g.push(2);
    else if(m===0) g.push(-1);

}

for(let i=0;i<g.length;i++){
    console.log(g[i]);

}
}

"use strict";

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

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

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

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

function main() {

const x= +readline();
let g=[];
for(let i=0;i<x;i++){
    let y=readline().split("");
    let m=0;
    for(let i=0;i<y.length;i++){

        if(parseInt(y[i])%2==0) m=m+i+1;

    }
    if(parseInt(y[y.length-1])%2==0) g.push(0);
    else if(parseInt(y[0])%2==0 && y.length>2) g.push(1);
    else if(m>=2 && y.length>2) g.push(2);
    else if(m==0) g.push(-1);

}

for(let i=0;i<g.length;i++){
    console.log(g[i]);

}
}

const { mainModule } = require("process");
var readline = require("readline");

var input = [];

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

rl.on("line", function (cmd) {
  input.push(cmd);
});

rl.on("close", function () {
  let t = +input[0] + 1;
  for (let i = 1; i < t; i++) {
    if (+input[i] % 2 === 0) {
      console.log(0);
      continue;
    }
    if (+input[i][0] % 2 === 0) {
      console.log(1);
      continue;
    }
    let k = false;
    for (let j = 0; j < input[i].length; ++j) {
      if (+input[i][j] % 2 === 0) {
        k = true;
        console.log(2);
        continue;
      }
      if (k === true) break;
    }
    if (k === false) console.log(-1);
  }
  process.exit(0);
});

const { mainModule } = require("process");
var readline = require("readline");

var input = [];

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

rl.on("line", function (cmd) {
  input.push(cmd);
});

rl.on("close", function () {
  let t = +input[0] + 1;
  for (let i = 1; i < t; i++) {
    if (+input[i] % 2 === 0) {
      console.log(0);
      continue;
    }
    if (+input[i][0] % 2 === 0) {
      console.log(1);
      continue;
    }
    let k = false;
    for (let j = 0; j < input[i].length; ++j) {
      if (+input[i][j] % 2 === 0) {
        k = true;
        console.log(2);
        continue;
      }
    }
    if (k === false) console.log(-1);
  }
  process.exit(0);
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       if(a[a.length - 1] % 2 === 0){
           console.log(0)
       }else if(a[a.length - 1] % 2 == 1 && a[0] % 2 === 0){
           console.log(1)
       }else if(a[a.length - 1] % 2 == 1 && a[0] % 2 == 1 && a.length != 1){
           console.log(2)
       }else{
           console.log(-1)
       }
   }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
   for(j = 1; j <= n; j++){
       var a = lines[j].split('')
       if(a[a.length - 1] % 2 === 0){
           console.log(0)
       }else if(a[a.length - 1] % 2 == 1 && a[0] % 2 === 0){
           console.log(1)
       }else if(a[a.length - 1] % 2 == 1 && a[0] % 2 == 1){
           console.log(2)
       }else{
           console.log(-1)
       }
   }
});

//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] = BigInt(next());
		}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 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 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 = next();
		var l = N.length;
		var output = 999;
		for(var i = 0; i < l; i++){
			var s = myconv(N[i], 1);
			if(s % 2 == 0){
				if(i == 0){
					output = Math.min(output, 1);
				}else if(i == l - 1){
					output = Math.min(output, 0);
				}else{
					output = Math.min(output, 2);
				}
			}
		}
		if(output == 999){
			output = -1;
		}
		myout(output);
	}
}


You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.You should write a program which finds sum of the best subsequence.

The first line contains integer number n (1 ≤ n ≤ 105). The second line contains n integer numbers a1, a2, ..., an ( - 104 ≤ ai ≤ 104). The sequence contains at least one subsequence with odd sum.

NoteIn the first example sum of the second and the fourth elements is 3.

var n = readline().trim();
var a = readline().split(' ');

var sum = 0;
var _min = 100000;
for (var i = 0; i < n; i++) {
  a[i] = Number(a[i]);
  if (a[i] > 0) {
    sum += a[i];
  }
  if (Math.abs(a[i]) % 2 === 1) {
    _min = Math.min(_min, Math.abs(a[i]));
  }
}
if (sum % 2 === 0) {
  sum -= _min;
}
print(sum);

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

  var minpos = Infinity;
  var maxneg = -Infinity;
  var sumpos = 0;
  for(var i = 0; i < n; i += 1) {
    if(a[i] > 0) {
      sumpos += a[i];
    }
    if(((a[i] % 2) + 10) % 2 === 1) {
      if(a[i] > 0 && a[i] < minpos) {
        minpos = a[i];
      }
      if(a[i] < 0 && a[i] > maxneg) {
        maxneg = a[i]
      }
    }
  }
  if(sumpos % 2 === 1) {
    print(sumpos);
  } else {
    if(minpos !== Infinity && maxneg !== -Infinity) {
      if(minpos < -maxneg) {
        print(sumpos - minpos);
      } else {
        print(sumpos + maxneg);
      }
    } else if(minpos === Infinity) {
      print(sumpos + maxneg);
    } else {
      print(sumpos - minpos);
    }
  }


A group of $$$n$$$ friends decide to go to a restaurant. Each of the friends plans to order meals for $$$x_i$$$ burles and has a total of $$$y_i$$$ burles ($$$1 \le i \le n$$$). The friends decide to split their visit to the restaurant into several days. Each day, some group of at least two friends goes to the restaurant. Each of the friends visits the restaurant no more than once (that is, these groups do not intersect). These groups must satisfy the condition that the total budget of each group must be not less than the amount of burles that the friends in the group are going to spend at the restaurant. In other words, the sum of all $$$x_i$$$ values in the group must not exceed the sum of $$$y_i$$$ values in the group.What is the maximum number of days friends can visit the restaurant?For example, let there be $$$n = 6$$$ friends for whom $$$x$$$ = [$$$8, 3, 9, 2, 4, 5$$$] and $$$y$$$ = [$$$5, 3, 1, 4, 5, 10$$$]. Then:   first and sixth friends can go to the restaurant on the first day. They will spend $$$8+5=13$$$ burles at the restaurant, and their total budget is $$$5+10=15$$$ burles. Since $$$15 \ge 13$$$, they can actually form a group.  friends with indices $$$2, 4, 5$$$ can form a second group. They will spend $$$3+2+4=9$$$ burles at the restaurant, and their total budget will be $$$3+4+5=12$$$ burles ($$$12 \ge 9$$$). It can be shown that they will not be able to form more groups so that each group has at least two friends and each group can pay the bill.So, the maximum number of groups the friends can split into is $$$2$$$. Friends will visit the restaurant for a maximum of two days. Note that the $$$3$$$-rd friend will not visit the restaurant at all.Output the maximum number of days the friends can visit the restaurant for given $$$n$$$, $$$x$$$ and $$$y$$$.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The descriptions of the test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of friends. The second line of each test case contains exactly $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$). The value of $$$x_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ plans to spend at the restaurant. The third line of each test case contains exactly $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$ ($$$1 \le y_i \le 10^9$$$). The value $$$y_i$$$ corresponds to the number of burles that the friend numbered $$$i$$$ has. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^5$$$.

For each test case, print the maximum number of days to visit the restaurant. If friends cannot form even one group to visit the restaurant, print 0.

NoteThe first test case in explained in the problem statement.In the second test case, friends cannot form at least one group of two or more people.In the third test case, one way to visit the restaurant in one day is to go in a group of all three friends ($$$1+3+10 \ge 2+3+7$$$). Note that they do not have the option of splitting into two groups.

var numTestCases = parseInt(readline());
var numFriends = 0;
var mealCostArr = [];
var walletBalanceArr = [];
var extraBalanceArr = [];

for (var i = 0; i < numTestCases; i++) {
    numFriends = parseInt(readline());
    var inpSecondLine = readline().split(" ");
    mealCostArr = inpSecondLine.map(element => parseInt(element));
    var inpThirdLine = readline().split(" ");
    walletBalanceArr = inpThirdLine.map(element => parseInt(element));
    extraBalanceArr = [];
    for (var j = 0; j < walletBalanceArr.length; j++) {
        extraBalanceArr[j] = walletBalanceArr[j] - mealCostArr[j];
    }
    extraBalanceArr.sort((a, b) => (b - a));
    var maxGroupCount = 0;
    var startInd = 0;
    var lastInd = extraBalanceArr.length - 1;
    while (lastInd > startInd) {
        var firstPlusLast = extraBalanceArr[startInd] + extraBalanceArr[lastInd];
        if (firstPlusLast >= 0) {
            maxGroupCount++;
            startInd++;
        }
        lastInd--;
    }

    print(maxGroupCount);
}

var t = +readline()

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

    var people = readline()
    var x = readline().split(" ")
    var y = readline().split(" ")

    var z = []

    for (var j=0; j<y.length; j++) {
        z[j] = y[j] - x[j]
    }

    z.sort(function (a, b) { return a - b })

    var p1 = z.length - 1
    var p2 = 0

    var counter = 0

    while(p1 > p2) {
        if ( z[p1] + z[p2] >= 0) {
            counter++
            p1--
            p2++
        } else {
            p2++
        }
    }

    print(counter)
}

'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 solve(read) {
  const rn = () => Number(read());
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const n = rn();
  const a = rns(),
        b = rns();
  const dif = [];
  for (let i = 0; i < n; i++) dif[i] = b[i] - a[i];
  dif.sort((a, b) => b - a);
  let res = 0;
  for (let i = 0, j = n - 1; i < j; i++, j--) {
    while (i <= j && dif[i] + dif[j] < 0) j--;
    if (i < j) res++;
  }
  return res;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var a = 0;
    for(i = 1; i <= t * 3; i++){
        if(i % 3 == 1){
            n = lines[i];
        }else if(i % 3 == 2){
            a = lines[i].split(' ').map(Number);
        }else{
            var b = lines[i].split(' ').map(Number);
            for(j = 0; j < n; j++){
                a[j] = b[j] - a[j];
            }
            a = a.sort(function(a, b){return a - b});
            var l = 0, r = n - 1, ans = 0;
            while(l < r){
                if(a[l] + a[r] >= 0){
                    ans++;
                    r--;
                }
                l++;
            }
            console.log(ans);
        }
    }
});

const readline = require('readline')

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

function solve(n, sa, sb) {
    const arr = sa.map((x, i) => sb[i] - x)
        .sort((a, b) => a - b)
    let i = 0
    let j = n - 1
    let r = 0
    while (i < j) {
        if (arr[i] + arr[j] >= 0) {
            i++
            j--
            r++
        } else {
            i++
        }
    }
    return r
}


The title is a reference to the very first Educational Round from our writers team, Educational Round 18.There is a bag, containing colored balls. There are $$$n$$$ different colors of balls, numbered from $$$1$$$ to $$$n$$$. There are $$$\mathit{cnt}_i$$$ balls of color $$$i$$$ in the bag. The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).In one move, you can choose two balls with different colors and take them out of the bag.At some point, all the remaining balls in the bag will have the same color. That's when you can't make moves anymore.Find any possible color of the remaining balls.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 20$$$) — the number of colors. The second line contains $$$n$$$ integers $$$\mathit{cnt}_1, \mathit{cnt}_2, \dots, \mathit{cnt}_n$$$ ($$$1 \le \mathit{cnt}_i \le 100$$$) — the amount of balls of each color in the bag. The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).

For each testcase, print a single integer — any possible color of the remaining balls, after you made some moves and can't make moves anymore.

NoteIn the first testcase, your first and only move can be one of the following:   take balls with colors $$$1$$$ and $$$2$$$;  take balls with colors $$$1$$$ and $$$3$$$;  take balls with colors $$$2$$$ and $$$3$$$. After the move, exactly one ball will remain. Its color can be $$$3, 2$$$ or $$$1$$$ depending on the move.In the second testcase, you can't make moves at all — there is only color of balls already. This color is $$$1$$$.In the third testcase, you can keep removing one ball of color $$$1$$$ and one ball of color $$$2$$$ until there are no more balls of color $$$1$$$. At the end, three balls of color $$$2$$$ remain.

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var caseArray = readline().split(" ");
    var highestIndex = 0;
    var highestValue = 0;
    for (var j = 0; j < caseLength; j++)
    {
        var current = parseInt(caseArray[j]);
        if (current >= highestValue)
        {
            highestValue = current;
            highestIndex = j+1;
        }
    }
    print(highestIndex);
}

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/problem/1728/A/solution.ts
var solution_exports = {};
__export(solution_exports, {
  main: () => main
});
module.exports = __toCommonJS(solution_exports);

// src/lib/codeforces.ts
var StdInput = class {
  constructor() {
    this.lines = [];
    this.data = "";
    process.stdin.resume();
    process.stdin.setEncoding("utf-8");
    this.complete = new Promise((resolve, reject) => {
      process.stdin.on("data", (it) => this.data += it);
      process.stdin.on("end", () => {
        this.lines = this.data.split("\n");
        resolve();
      });
    });
  }
  readLine() {
    var _a;
    return (_a = this.lines.shift()) != null ? _a : "";
  }
  readInt() {
    return parseInt(this.readLine());
  }
  readInts(sep = " ") {
    return this.readLine().split(sep).map((it) => parseInt(it));
  }
};
var StdOutput = class {
  writeln(line) {
    process.stdout.write(line);
    process.stdout.write("\n");
  }
};

// src/problem/1728/A/solution.ts
main(new StdInput(), new StdOutput());
async function main(input, output) {
  await input.complete;
  const T = input.readInt();
  for (let t = 0; t < T; t++) {
    const n = input.readInt();
    const cnt = input.readInts();
    const max = cnt.reduce((prev, current) => prev > current ? prev : current);
    output.writeln((cnt.lastIndexOf(max) + 1).toString());
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  main
});

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line.split(" "));

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let i = 1; i < input.length; i += 2) {
    let colors = input[i + 1];

    let maxNumIndex = 0;

    let max = +colors[0];

    for (let i = 1; i < colors.length; i++) {
      if (+colors[i] > max) {
        maxNumIndex = i;
        max = +colors[i];
      }
    }

    console.log(maxNumIndex + 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++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const sorted = arr.map((x, i) => [x, i])
        .sort((a, b) => a[0] - b[0])
    let i = 0
    while (i < n - 1) {
        sorted[i][0]--
        sorted[i + 1][0]--
        while (!sorted[i][0]) i++
    }
    return sorted[i][1] + 1
}

var readline = require('readline');

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

var matrix = [];
var counter = -1
var res = 1
var c = 0
var r = []
var w = 0

rl.on('line', async (line) => {
    if (counter === -1) {
         c = line*2;
    }else {
        r=line.split(' ')
        w++;
        if(w%2===0){
            zaid()
        }
        if (counter===c-1) {
            rl.close()
        }
    }
    counter++
});

function zaid(){
    let temp=0,res=0;
    for (let i = 0; i < r.length; i++) {
        if(parseInt(r[i])>=parseInt(temp)){
            temp=r[i]
            res=i
        }
    }
    console.log(res+1)
}
rl.on('close', function (cmd) {

    process.exit(0);
});

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk;
})

process.stdin.on('end',function(){
    let line=buf.split('\n');
    // console.log(line);
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let n=parseInt(line[i]);
        let a=line[i+1].split(' ').map(x=>{return parseInt(x)});
        let mx=0;
        for(let i=0;i<n;i++) mx=Math.max(mx,a[i]);
        for(let i=0;i<n;i++) {
            if(a[i]===mx) {
                console.log(i+1);
                break;
            }
        }
    }
})

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

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    const data = input.trim().split('\n');
    for (let i = 1; i < data.length; i += 2) {
        const test = data[i + 1]
            .trim()
            .split(' ')
            .map((amount, index) => ({amount: Number(amount), index}))
            .sort((a, b) => b.amount - a.amount);

        console.log(test[0].index + 1);
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var max = 0;
            for(j = 0; j < n; j++){
                if(k[j] >= k[max]){
                    max = j;
                }
            }
            console.log(max+1);
        }
    }
});

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

let i = 0;
rl.on('line', function(line){
    i++;
    if (i > 1 && i % 2 === 1) {
        // console.log('--->', line);
        processLine(line)
    }
})

function processLine(line) {
    const arr = line.split(' ').map(Number);
    const max = Math.max(...arr);
    console.log(arr.indexOf(max) + 1);
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

//

function main() {
    let t = readLine()
    t = parseInt(t)
    while (t--) {
        const n = readLine()
        const line = readLine().split(" ")
        const cntArr = line.map((l) => parseInt(l))
        const maxCnt = Math.max(...cntArr)
        const index = cntArr.indexOf(maxCnt)
        console.log(index + 1)
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

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

        let max = Math.max(...arr);
        let r = arr.indexOf(max);

        output(r + 1);
    }
}

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/problem/1728/B/solution.ts
var solution_exports = {};
__export(solution_exports, {
  main: () => main
});
module.exports = __toCommonJS(solution_exports);

// src/lib/codeforces.ts
var StdInput = class {
  constructor() {
    this.lines = [];
    this.data = "";
    process.stdin.resume();
    process.stdin.setEncoding("utf-8");
    this.complete = new Promise((resolve, reject) => {
      process.stdin.on("data", (it) => this.data += it);
      process.stdin.on("end", () => {
        this.lines = this.data.split("\n");
        resolve();
      });
    });
  }
  readLine() {
    var _a;
    return (_a = this.lines.shift()) != null ? _a : "";
  }
  readInt() {
    return parseInt(this.readLine());
  }
  readInts(sep = " ") {
    return this.readLine().split(sep).map((it) => parseInt(it));
  }
};
var StdOutput = class {
  writeln(line) {
    process.stdout.write(line);
    process.stdout.write("\n");
  }
};

// src/lib/natural-numbers.ts
function range(start, stop) {
  return Array.from(Array(stop - start + 1).keys()).map((it) => it + start);
}

// src/problem/1728/B/solution.ts
main(new StdInput(), new StdOutput());
async function main(input, output) {
  await input.complete;
  const T = input.readInt();
  for (let t = 0; t < T; t++) {
    const n = input.readInt();
    const p = range(1, n);
    for (let i = n - 4; i >= 0; i -= 2) {
      p.splice(i, 2, ...p.slice(i, i + 2).reverse());
    }
    output.writeln(p.join(" "));
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  main
});

"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/problem/1728/A/solution.ts
var solution_exports = {};
__export(solution_exports, {
  main: () => main
});
module.exports = __toCommonJS(solution_exports);

// src/lib/codeforces.ts
var Input = class {
  constructor() {
    this.lines = [];
    this.data = "";
    process.stdin.resume();
    process.stdin.setEncoding("utf-8");
    this.complete = new Promise((resolve, reject) => {
      process.stdin.on("data", (it) => this.data += it);
      process.stdin.on("end", () => {
        this.lines = this.data.split("\n");
        resolve();
      });
    });
  }
  readLine() {
    var _a;
    return (_a = this.lines.shift()) != null ? _a : "";
  }
};
var Output = class {
  write(line) {
    process.stdout.write(line);
  }
  writeln(line) {
    this.write(line);
    process.stdout.write("\n");
  }
};

// src/problem/1728/A/solution.ts
main(new Input(), new Output());
async function main(input, output) {
  await input.complete;
  output.writeln(input.readLine());
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  main
});

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line.split(" "));

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let i = 1; i < input.length; i += 2) {
    let colors = input[i + 1];

    console.log(colors.length);
  }
};

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line.split(" "));

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let i = 1; i < input.length; i += 2) {
    let colors = input[i + 1];

    let point1 = 0;
    let point2 = 1;

    if (colors.length === 1) {
      console.log(1);
      continue;
    }

    while (point2 < colors.length) {
      if (+colors[point1] <= +colors[point2]) {
        colors[point2] = +colors[point2] - colors[point1];
        colors[point1] = 0;
        point1++;
        point2++;
      } else {
        colors[point1] = +colors[point1] - colors[point2];
        colors[point2] = 0;
        point2++;
      }
    }

    for (let i = 0; i < colors.length; i++) {
      if (colors[i] !== 0) {
        console.log(i + 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++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] & 1) return i + 1
    }
    // return [n, arr]
}

var readline = require('readline');

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

var matrix = [];
var counter = -1
var res = 1
var c = 0
var r = []
var w = 0

rl.on('line', async (line) => {
    if (counter === -1) {
         c = line*2;
    }else {
        r=line.split(' ')
        w++;
        if(w%2===0){
            zaid()
        }
        if (counter===c-1) {
            rl.close()
        }
    }
    counter++
});

function zaid(){
    let temp=0,res=0;
    for (let i = 0; i < r.length; i++) {
        if(r[i]>=temp){
            temp=r[i]
            res=i
        }
    }
    console.log(res+1)
}
rl.on('close', function (cmd) {

    process.exit(0);
});


You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.You are really curious about prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors: itself and number one. For example, numbers 2, 3, 5 are prime and numbers 1, 4, 6 are not. A matrix is prime if at least one of the two following conditions fulfills:  the matrix has a row with prime numbers only;  the matrix has a column with prime numbers only; Your task is to count the minimum number of moves needed to get a prime matrix from the one you've got.

The first line contains two integers n, m (1 ≤ n, m ≤ 500) — the number of rows and columns in the matrix, correspondingly. Each of the following n lines contains m integers — the initial matrix. All matrix elements are positive integers. All numbers in the initial matrix do not exceed 105. The numbers in the lines are separated by single spaces.

Print a single integer — the minimum number of moves needed to get a prime matrix from the one you've got. If you've got a prime matrix, print 0.

NoteIn the first sample you need to increase number 1 in cell (1, 1). Thus, the first row will consist of prime numbers: 2, 2, 3.In the second sample you need to increase number 8 in cell (1, 2) three times. Thus, the second column will consist of prime numbers: 11, 2.In the third sample you don't have to do anything as the second column already consists of prime numbers: 3, 2.

const N = 1e5 + 5;
var prime = [-1e9];
var used = new Int8Array(1e5 + 5);
for (var i = 2; i < N; i++) {
	if (used[i] === 0) {
		prime.push(i);
		for (var j = i+i; j < N; j += i)
			used[j] = 1;
	}
}

function find(v) {
	var mid,
		low = 0,
		high = prime.length;
	while (low < high) {
		mid = (low + high) >> 1;
		if (v <= prime[mid]) {
			if (v > prime[mid - 1]) {
				return mid;
			}
			high = mid - 1;
		} else {
			if (v <= prime[mid + 1]) {
				return mid + 1;
			}
			low = mid + 1;
		}
	}
	return -1;
}

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

	for (var i = 0; i < n; i++)
		for (var j = 0; j < m; j++) {
			var x = find(a[i][j]);
			a[i][j] = prime[x] - a[i][j];
	}

	var ans = 1e9;
	for (var i = 0; i < n; i++) {
		var sum = 0;
		for (var j = 0; j < m; j++) {
			sum += a[i][j];
		}
		ans = Math.min(sum, ans);
	}
	for (var j = 0; j < m; j++) {
		var sum = 0;
		for (var i = 0; i < n; i++) {
			sum += a[i][j];
		}
		ans = Math.min(sum, ans);
	}
	return ans;

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

function getSimpleArray (n) {
	var array = [], control = new Int8Array(++n);
	for (var i = 2; i < n; i++) {
		if (control[i] === 0) {
			array.push(i);
			for (var j = 2*i; j < n; j += i) {
				control[j] = -1;
			}
		}
	}

	return array;
}

var nextSimpleNumber = (function (simpleArray) {

	return function (current) {
		if (current <= 2) return 2;

		var start = 0, finish = simpleArray.length, middle;

		while (start < finish) {
			middle = (start + finish) >> 1;

			     if (current === simpleArray[middle - 1]) return simpleArray[middle - 1];
			else if (current === simpleArray[middle + 0]) return simpleArray[middle + 0];
			else if (current === simpleArray[middle + 1]) return simpleArray[middle + 1];

			if (current < simpleArray[middle]) {
				if (current > simpleArray[middle - 1]) {
					return simpleArray[middle];
				}

				finish = middle - 1;
			} else {
				if (current < simpleArray[middle + 1]) {
					return simpleArray[middle + 1];
				}

				start = middle + 1;
			}
		}

		if (current === simpleArray[start]) return simpleArray[start];
		else if (current === simpleArray[finish]) return simpleArray[finish];

		return -1;
	}

})(getSimpleArray(1e6));

;(function () {

	print(function (n, m) {

		var matrica = [], min = 1e10;

		while (n--) {

			var line = readline().split(' ').map(function (e) {
				e = parseInt(e);
				return nextSimpleNumber(e) - e;
			});

			min = Math.min(min, line.reduce(function (p, e) { return p + e; }, 0));

			if (min === 0) return min;
			else matrica.push(line);

		} n = matrica.length;

		for (var i = 0; i < m; i++) {
			var sim = 0;
			for (var j = 0; j < n; j++) {
				sim += matrica[j][i];
			}

			min = Math.min(min, sim);
			if (min === 0) return min;
		}

		return min;

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

}.call(this));

function getSimpleArray (n) {
	var array = [], control = new Int8Array(++n);
	for (var i = 2; i < n; i++) {
		if (control[i] === 0) {
			array.push(i);
			for (var j = 2*i; j < n; j += i) {
				control[j] = -1;
			}
		}
	}

	return array;
}

var nextSimpleNumber = (function (simpleArray) {

	return function (current) {
		if (current <= 2) return 2;

		var start = 0, finish = simpleArray.length, middle;

		while (start < finish) {
			middle = (start + finish) >> 1;

			     if (current === simpleArray[middle - 1]) return simpleArray[middle - 1];
			else if (current === simpleArray[middle + 0]) return simpleArray[middle + 0];
			else if (current === simpleArray[middle + 1]) return simpleArray[middle + 1];

			if (current < simpleArray[middle]) {
				if (current > simpleArray[middle - 1]) {
					return simpleArray[middle];
				}

				finish = middle - 1;
			} else {
				if (current < simpleArray[middle + 1]) {
					return simpleArray[middle + 1];
				}

				start = middle + 1;
			}
		}

		if (current === simpleArray[start]) return simpleArray[start];
		else if (current === simpleArray[finish]) return simpleArray[finish];

		return -1;
	}

})(getSimpleArray(1e5));

;(function () {

	print(function (n, m) {

		var matrica = [], min = 1e10;

		while (n--) {

			var line = readline().split(' ').map(function (e) {
				e = parseInt(e);
				return nextSimpleNumber(e) - e;
			});

			min = Math.min(min, line.reduce(function (p, e) { return p + e; }, 0));

			if (min === 0) return min;
			else matrica.push(line);

		} n = matrica.length;

		for (var i = 0; i < m; i++) {
			var sim = 0;
			for (var j = 0; j < n; j++) {
				sim += matrica[j][i];
			}

			min = Math.min(min, sim);
			if (min === 0) return min;
		}

		return min;

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

}.call(this));