There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (possibly none) candies from each box so that all boxes have the same quantity of candies in them. Note that you may eat a different number of candies from different boxes and you cannot add candies to any of the boxes.What's the minimum total number of candies you have to eat to satisfy the requirements?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of boxes you have. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$) — the quantity of candies in each box.

For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.

NoteFor the first test case, you can eat $$$1$$$ candy from the second box, $$$2$$$ candies from the third box, $$$3$$$ candies from the fourth box and $$$4$$$ candies from the fifth box. Now the boxes have $$$[1, 1, 1, 1, 1]$$$ candies in them and you ate $$$0 + 1 + 2 + 3 + 4 = 10$$$ candies in total so the answer is $$$10$$$.For the second test case, the best answer is obtained by making all boxes contain $$$5$$$ candies in them, thus eating $$$995 + 995 + 0 + 995 + 995 + 995 = 4975$$$ candies in total.

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

});//k[k.length - 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(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            var k = lines[j].split(' ').map(Number).sort(function(a, b){return a - b});
            var ans = 0;
            var a = k[0];
            for(i = 1; i < e; i++){
                ans += k[i] - a;
            }
            console.log(ans);
        }
    }
});

/*
File Created: Tuesday, 17 May 2022
Author: Lukas Rimkus
*/
'use strict';

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

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
     data += chunk;
});
process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '').split('\n').map(str => str.replace(/\s*$/, ''));
    let testCases = parseInt(readLine());
    while(testCases--) {
        const n = parseInt(readLine());
        const arr = get_ints();
        console.log(solve([n,arr]));
    }
});
function get_ints() {
    return data[currentLine++].split(' ').map(Number);
}

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

function solve(input){
    let candies = 0;
    const min = Math.min(...input[1]);
    for (let index = 0; index < input[1].length; index++) {
        candies+= input[1][index] - min;
    }
    return candies;
}

module.exports = solve;

const { createInterface } = require('readline');
/*
const { createWriteStream, createReadStream } = require('fs');
const { format } = require('util');
const log_file = createWriteStream('output.txt', { flags: 'w' }
);
const log_stdout = process.stdout;
console.log = function (d) {
  log_file.write(format(d) + '\n');
  log_stdout.write(format(d) + '\n');
};
const fileStream = createReadStream('input.txt');
*/
function main() {
  const readline = createInterface({
    input: process.stdin,
    output: process.stdout
  });
  let lineNb = 0;
  let n;
  let t = [];
  let currentLength = -1;
  readline.on('line', line => {
    if (!lineNb)
      n = parseInt(line) * 2;
    else if (!(lineNb % 2)) {
      let sum = 0;
      let array = line.split(" ");
      let min = parseInt(array[0])
      t = (line.split(" ").map(i => {
        let currentNumber = Number(i);
        sum += currentNumber
        if (min > currentNumber) min = currentNumber
        return Number(i);
      }));
      console.log(sum - min * currentLength)
    } else {
      currentLength = parseInt(line)
    }
    if (lineNb === n)
      readline.close();
    lineNb++;
  });

}

main()

const { createInterface } = require('readline');
/*
const { createWriteStream, createReadStream } = require('fs');
const { format } = require('util');
const log_file = createWriteStream('output.txt', { flags: 'w' }
);
const log_stdout = process.stdout;
console.log = function (d) {
  log_file.write(format(d) + '\n');
  log_stdout.write(format(d) + '\n');
};
const fileStream = createReadStream('input.txt');
*/
function main() {
  const readline = createInterface({
    input: process.stdin,
    output: process.stdout
  });
  let lineNb = 0;
  let n;
  let t = [];
  let currentLength = -1;
  readline.on('line', line => {
    if (!lineNb)
      n = parseInt(line) * 2;
    else if (!(lineNb % 2)) {
      let sum = 0;
      t = (line.split(" ").map(i => {
        var currentNumber = Number(i);
        sum += currentNumber
        return Number(i);
      }));
      const min = Math.min(...t);
      console.log(sum - min * currentLength)
    } else {
      currentLength = parseInt(line)
    }
    if (lineNb === n)
      readline.close();
    lineNb++;
  });

}

main()

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 * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            var a = k[0];
            var ans = 0;
            for(j = 1; j < e; j++){
                ans += k[j] - a;
            }
            console.log(ans);
        }
    }
});

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

const main = (input) => {
  input = input.split('\n')

  const t = Number(input[0])
  for (let i = 0; i < t; i++) {
    const n = parseInt(input[1 + i * 2])
    const a = input[1 + i * 2 + 1].split(' ').map((x) => parseInt(x))

    const ans =
      a.reduce((prev, current) => prev + current, 0) - Math.min(...a) * n
    console.log(ans)
  }
}

main(require('fs').readFileSync(0).toString())

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

let c = 0;

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

  if (c % 2 !== 0) {
    c++;
    return;
  }

  const arr = d
    .split(" ")
    .map(Number)
    .sort((a, b) => a - b);
  const min = arr[0];
  let ans = 0;

  for (let i = 1; i < arr.length; i++) {
    if (min < arr[i]) {
      ans += arr[i] - min;
    }
  }

  console.log(ans);

  c++;
});

rl.on("close", () => {});

'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 min = Math.min(...arr);

        let sum = 0;
        for (let i = 0; i < n; i++) {
            sum += arr[i] - min;
        }

        output(sum);
    }
}

const rdline = require('readline');
const rl = rdline.createInterface({
    input: process.stdin
});

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];
solve = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var a = readline().split(" ").map(Number).sort(function(a, b) {
            return a - b;
          });
        var sum = 0;
        var min = a[0];
            for (let j = 0; j < n; j++) {

                if (a[j] === min) {
                    sum = 0 + sum;
                } else {
                    sum = sum + a[j] - min;
                }
            }

        console.log(sum)
    }
}

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let n = nl.num();
		let a = nl.nums();
		let s = a.reduce((x, ac) => ac + x, 0);
		let m = a.reduce((x, ac) => x < ac?x:ac, a[0]);
		ans.push(s - m*n);
	}
	console.log(ans.join('\n'));
};

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);

    function foo (data) {
        const numberData = data.split(' ').map(Number);
        const min = Math.min(...numberData);

        return numberData.reduce((acc, value) => {
          const diff = value - min;
          return acc + diff;
        }, 0);
    }

    let testCount = 1;
    const rowsInTest = 2;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount * rowsInTest];
        let result = foo(data);
        answer += result +"\n";
        testCount += 1;
    }
    console.log(answer);
})

const solve = (arr,n) => {
     let min = Infinity,cnt = 0;
     for(let i=0;i<n;i++) if(arr[i]<min) min=arr[i];
     for(let i=0;i<n;i++){
          cnt+=arr[i]-min;
     }
     console.log(cnt);
};
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let n = parseInt(readline());
  for(let i=0;i<n;i++){
       let l = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr,l);
  }
}
main();

'use strict';

var readline = require('readline');

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

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

function solve(n, a) {
  let min = Math.min(...a);
  let res = 0;
  for (let num of a) {
    res += num - min;
  }
  return res;
}

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

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

let readline = require("readline");
let rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false,
});
const findMinimum = (array) => {
  let result = array[0];
  for (let index = 0; index < array.length; index++) {
    const element = array[index];
    if (result > element) {
      result = element;
    }
  }

  return result;
};

let lines = 0;

rl.on("line", function (line) {
  if (lines !== 0 && lines % 2 === 0) {
    let input = line.split(" ").map(Number);
    const minimum = findMinimum(input);
    console.log(input.reduce((sum, candies) => sum + candies - minimum, 0));
  }
  lines++;
});

'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    let n = parseInt(input());
    const a = input().split(' ').map(Number);
    let min_a = 1e7;
    for(let i of a) min_a = Math.min(min_a, i);
    let ans = 0;
    for(let i of a) if(i > min_a) ans += i-min_a;
    console.log(ans);
  }
}

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

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    readLine();
    let arr = readLine().split(" ").map(i => parseInt(i));
    let min = Number.MAX_VALUE;
    for (let i = 0; i < arr.length; i++) {
        min = Math.min(min, arr[i]);
    }
    let eat = 0;
    for (let i = 0; i < arr.length; i++) {
        eat += arr[i] !== min ? arr[i] - min : 0;
    }
    return eat;
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var q=1;q<=T;q++) {
  var n = readline();
  var a = readline().split(' ').map((x)=>parseInt(x));
  var ans = 0;
  var mn = 100000001;
  var sum = 0;
  for(var i=0;i<n;i++) {
    sum += a[i];
    mn = min(mn, a[i]);
  }
  ans = sum-(n*mn);
  console.log(ans);
  //fs.appendFileSync('output.txt', ans+' '+mn+'\r\n');

  //os.EOL
}
//fs.writeFileSync('output.txt', f.join(' '));

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
	const num = nextInt();
    const arr = nextIntArray(num);

    let min = Math.min(...arr);
    let sum = 0;
    for (const value of arr) {
        sum += value - min
    }
    myout(sum);
}

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

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

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

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n] = ra();
  let A = ra();
  LT({n, A});
  // PROCESSING:
  let min = Math.min.apply(null, A);
  let ans = 0;
  for (let a of A)
    ans += a-min;
  return 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 arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let min = arr[0]
    for (let i = 0; i < arr.length; i++) {
        min = Math.min(min, arr[i])
    }
    let ans = 0
    for (let i = 0; i < arr.length; i++) {
        ans += arr[i] - min
    }
    return ans
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var min = 100000000;
		for(var i = 0; i < N; i++){
			min = Math.min(min, list[i]);
		}
		var output = 0;
		for(var i = 0; i < N; i++){
			output += list[i] - min;
		}
		myout(output);
	}
}

var testCase = +readline(),counter
for(var i=0;i<testCase;i++){
    var a=+readline(),b=[],counter=0
    var sequence=readline().split(" ").map(node=>+node)
    var minValue=sequence.reduce((a,b)=>Math.min(a,b))
    for(var j=0;j<sequence.length;j++){
        if((minValue!==sequence[j])){
            counter=counter+(Math.abs(sequence[j]-minValue))
        }
    }
    print(counter)
}

var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseLength = parseInt(readline());
        var caseArray = readline().split(" ");
        var caseIntArray = new Array();
        for (var _i = 0, caseArray_1 = caseArray; _i < caseArray_1.length; _i++) {
            var element = caseArray_1[_i];
            caseIntArray.push(parseInt(element));
        }
        var sortedCaseIntArray = caseIntArray.sort(function (a, b) { return a - b; });
        var totalCandies = 0;
        for (var j = 1; j < caseLength; j++) {
            totalCandies += sortedCaseIntArray[j] - sortedCaseIntArray[0];
        }
        print(totalCandies);
    }

const readStr = () => readline();
const readStrArr = () => readline().split(' ');

const n = readStr();
for(var i = 0; i < n; i++) {
  var k = readStr();
  var a = readStrArr();
  if(k === '1'){
    print(0);
    continue;
  }
  var min = Math.min(...a), sum = 0;
  for(var j = 0; j < k; j++) {
    sum += a[j] - min;
  }
  print(sum);
}

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var n = parseInt(readline());
    var arr = readline().split(' ');

    var sum = parseInt(arr[0]);
    var min = parseInt(arr[0]);

    for (var i = 1; i < n; i++) {
        sum += parseInt(arr[i]);
        min = Math.min(min, parseInt(arr[i]));
    }

    print(sum - min * n);
}

var t = readline();
for(var i = 0 ; i < t ;i++){
    var n = readline();
    var a = readline().split(' ');
    a.sort( (a,b) => {return a-b});
    var min = a[0] , counter = 0;
    for(var  j = 0 ; j < n ; j++){
        counter+= (a[j] - a[0]);
    }
        print(counter);
}

var n = +readline()

for(var i=0;i<n;++i){
    var q = +readline();
    var arr = readline().split(" ")
    var min = 10000000;
    var max = 0;

    for(var j=0;j<arr.length;++j){
        if(+arr[j] < min){
            min = +arr[j]
        }else if(+arr[j] > max){
            max =+arr[j];
        }
    }

    if(min === max){
        print(0);
    }else{
        var op = 0;
        for(var j=0;j<arr.length;++j){
            if(+arr[j] > min){
                op += +arr[j] - min;
            }
        }
        print(op)
    }
}

T = readline()
while (T--) {
   n = +readline()
   a = readline().split(' ').map(a => +a)
   a.sort((prev, next) => prev - next)

   ans = 0
   for(i=1; i< n; i++){
      ans += a[i] - a[0]
   }
   print(ans)
}

t = parseInt(readline());
for(i = 0; i < t; i++)
{
    var n = readline();
    n = readline().split(" ");
    var min = 10000001;
    var sum = 0;
    for(j = 0; j < n.length; j++)
    {
        sum += parseInt(n[j]);
        if(parseInt(n[j]) < min) min = n[j];
    }
    print(sum - min*n.length);
}

var n = readline()

for(var i=0 ; i<n ; i++){
    var box = readline()
    var arr = readline().split(' ').map(function(x) { return parseInt(x); });
    var m = Math.min(...arr);
  //  print(m)
    var total = 0;
   for(var j=0 ; j<box ; j++){
       if(arr[j] == m)continue;
       else{
            total += (arr[j]-m);
       }
   }
   print(total);
}

var t = +readline();

for(var i = 0; i< t; i ++) {
    var a = readline();
    var b = readline().split(' ').map((t) => +t);

    print(Task2(b));
}

function Task2 (arr){

  var min = Math.min(...arr);
  var count = 0;
  for(var i = 0; i<arr.length; i++){
    count += arr[i] - min;
  }
  return count;

}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    readline();
    var a = readline().split(' ').map(function (v) { return +v; });
    print(a.reduce(function (a, b) { return a + b; }) - a.length * Math.min.apply(Math, a));
}

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

});//k[k.length - 1] == '' ||

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

function main() {
    let tc = parseInt(input());
    while(tc--){
         const n = input().split('').map(Number);
         const a = input().split('').map(Number);
         console.log(solve([n,a]))
    }
}

function solve(input){
    let candies = 0;
    const min = Math.min(...input[1]);
    for (let index = 0; index < input[1].length; index++) {
        candies+= input[1][index] - min;
    }
    console.log(candies)
    return candies;
}

module.exports = solve;

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

function main() {
    let tc = parseInt(input());
    while(tc--){
         const n = input().split('').map(Number);
         const a = input().split('').map(Number);
         ans = solve([n,a]);
         console.log(ans)
    }
}

function solve(input){
    let candies = 0;
    const min = Math.min(...input[1]);
    for (let index = 0; index < input[1].length; index++) {
        candies+= input[1][index] - min;
    }
    return candies;
}

module.exports = solve;

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

function main() {
    let tc = parseInt(input());
    while(tc--){
         const n = input().split('').map(Number);
         const a = input().split('').map(Number);
         console.log(solve([n,a]))
    }
}

function solve(input){
    let candies = 0;
    const min = Math.min(...input[1]);
    for (let index = 0; index < input[1].length; index++) {
        candies+= input[1][index] - min;
    }
    return candies;
}

module.exports = solve;

var testCase = readline().split(""),counter
for(var i=0;i<testCase;i++){
    var a=+readline(),b=[],counter=0
    var sequence=readline().split(" ").map(node=>+node)
    var minValue=sequence.reduce((a,b)=>Math.min(a,b))
    for(var j=0;j<sequence.length;j++){
        if((minValue!==sequence[j])){
            counter=counter+(Math.abs(sequence[j]-minValue))
        }
    }
    print(counter)
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. Indices of the array start from zero (i. e. the first element is $$$a_0$$$, the second one is $$$a_1$$$, and so on).You can reverse at most one subarray (continuous subsegment) of this array. Recall that the subarray of $$$a$$$ with borders $$$l$$$ and $$$r$$$ is $$$a[l; r] = a_l, a_{l + 1}, \dots, a_{r}$$$.Your task is to reverse such a subarray that the sum of elements on even positions of the resulting array is maximized (i. e. the sum of elements $$$a_0, a_2, \dots, a_{2k}$$$ for integer $$$k = \lfloor\frac{n-1}{2}\rfloor$$$ should be maximum possible).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_0, a_1, \dots, a_{n-1}$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer on the separate line — the maximum possible sum of elements on even positions after reversing at most one subarray (continuous subsegment) of $$$a$$$.

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')

    main();
});

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

const s2i = s => parseInt(s, 10)

function main() {
  let T = s2i(readLine())
  let out = ''
  while (T--) {
    const n = s2i(readLine())
    const arr = readLine().split(' ').map(s2i)

    let sumEven = arr[0]
    let sum01 = 0
    let sum12 = 0
    let max = 0
    for (let i = 1, even = false, curr = sumEven; i < n; i++, even = !even) {
      const prev = curr
      curr = arr[i]
      if (even) {
        sumEven += curr
        sum01 += prev - curr
        if (sum01 < 0) {
          sum01 = 0
        } else {
          max = Math.max(max, sum01)
        }
      } else {
        sum12 += curr - prev
        if (sum12 < 0) {
          sum12 = 0
        } else {
          max = Math.max(max, sum12)
        }
      }
    }

    out += (sumEven + max) + '\n'
  }
  console.log(out)
}

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();
    });

    D();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function C(){
    let [n,m] = ti(readline().split(' '));
    let a = ti(readline().split(' '));
    let b = ti(readline().split(' '));
    let o = new Array(10);
    let z = new Array(10);
    o.fill(0);
    z.fill(0);
    for(let i = 0; i < m; i++){
        let t = 1;
        for(let j = 0; j < 10; j++){
            if(b[i] & t !== 0)
                o[j] = 1;
            else
                z[j] = 1;

            t << 1;
        }
    }

    let c = new Array(10);
    for(let i = 0; i < n; i++){
        let t = 1;
        for(let j = 0; j < 10; j++){
            if(a[i] & t !== 0){
                if(z[j] === 1)
                    c[j] = 0;
                else
                    c[j] = 1;
            }
            t << 1;
        }
    }

    let res = 0;
    for(let i = 9; i >= 0; i--){
        res += pi(c[i])*Math.pow(2,9-i);
    }
    console.log(res);
}

function B(){
    let t = pi(readline());
    while(t){
        t--;
        let [n,k,z] = ti(readline().split(' '));
        let a = ti(readline().split(' '));

        // pre -> 0,1 -> right,left
        let dp = new Array(z+1);
        for(let i = 0; i < z+1; i++){
            dp[i] = new Array(n);
            dp[i].fill(-1);
        }

        let solve = (i,j,index,pre) => {
            if(index < 0 || index >= n)
                return 0;
            if(i > k)
                return 0;
            if(dp[j][index] !== -1)
                return dp[j][index];
            if(pre){
                return dp[j][index] = a[index] + solve(i+1, j, index+1, 0);
            }else{
                return dp[j][index] = a[index] + Math.max(j < z ? solve(i+1,j+1,index-1,1) : 0, solve(i+1,j,index+1,0));
            }
        }

        console.log(solve(0,0,0,1));
    }
}

function E1(){
    let [n,k] = ti(readline().split(' '));
    let t = new Array(n);
    for(let i = 0; i < n; i++){
        t[i] = ti(readline().split(' '));
    }
    let ab = [];
    let a = [];
    let b = [];
    let unlikeCount = 0;

    for(let i = 0; i < n; i++){
        if(t[i][1] === 1 && t[i][2] === 1){
            ab.push(t[i]);
        }else if(t[i][1] === 1){
            a.push(t[i]);
        }else if(t[i][2] === 1){
            b.push(t[i]);
        }else{
            unlikeCount += 1;
        }
    }

    ab.sort((x,y) => x[0]-y[0]);
    a.sort((x,y) => x[0]-y[0]);
    b.sort((x,y) => x[0]-y[0]);
    // let max = Math.max(max, ab.length, a.length, b.length);
    // let min = Math.min(min, ab.length, a.length, b.length);
    // let inf = 9999999999;
    // for(let i = min+1; i <= max; i++){
    //     if(i >= ab.length) ab.push(inf);
    //     if(i >= a.length) a.push(inf);
    //     if(i >= b.length) b.push(inf);
    // }

    let p1 = p2 = p3 = 0;
    let ka = k;
    let kb = k;
    let res = 0;
    while(p1 < ab.length || p2 < a.length || p3 < b.length){
        if(ka === 0 && kb === 0)
            break;
        if(p2 < a.length && p3 < b.length){
            if(p1 < ab.length){
                if(a[p2][0]+b[p3][0] > ab[p1][0]){
                    res += ab[p1][0];
                    p1++;
                }else{
                    res += a[p2][0]+b[p3][0];
                    p2++;
                    p3++;
                }
            }else{
                res += a[p2][0]+b[p3][0];
                p2++;
                p3++;
            }
            ka--;
            kb--;
        }else{
            if(p1 >= ab.length){
                console.log(-1);
                return;
            }
            res += ab[p1][0];
            ka--;
            kb--;
            p1++;
        }
    }
    if(ka !== 0 || kb !== 0){
        console.log(-1);
        return;
    }
    console.log(res);
}

function D(){
    let t = pi(readline());
    while(t){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let sum1 = new Array(n);
        let sum2 = new Array(n);
        sum1[0] = -1*a[0];
        sum2[0] = a[0];
        for(let i = 1; i < n; i++){
            if(i%2 === 0){
                sum1[i] = sum1[i-1] - a[i];
            }else{
                sum1[i] = sum1[i-1] + a[i];
            }
        }

        let min = 99999999999;
        let [l,r] = [-1,-1];
        let max = 0;
        let minIndex = 0;
        for(let i = 0; i < n; i+=2){
            if(min > sum1[i]){
                min = sum1[i];
                minIndex = i;
            }

            if(max < sum1[i]-min){
                max = sum1[i]-min;
                [l,r] = [minIndex+1,i];
            }
        }

        min = 0;
        minIndex = -1;
        for(let i = 1; i < n; i+=2){
            if(min > sum1[i]){
                min = sum1[i];
                minIndex = i;
            }

            if(max < sum1[i]-min){
                max = sum1[i]-min;
                [l,r] = [minIndex+1,i];
            }
        }

        let res = 0;
        for(let i = 0; i < n; i++){
            if(i < l || i > r){
                if(i%2 === 0)
                    res += a[i];
            }
            else{
                if(i%2 !== 0)
                    res += a[i];
            }
        }

        console.log(res);
    }
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; t++) {
      var n = Number(read());
      var a = read().split(' ').map(Number);
      var sum = a[0];
      var x = 0;
      var y = 0;
      var ans = 0;
      for (var i = 1; i < n; i += 2) {
         x += (a[i] - a[i - 1]);
         if (x > ans) {
            ans = x;
         }
         if (x < 0) {
            x = 0;
         }
         if (i + 1 < n) {
            sum += a[i + 1];
            y += (a[i] - a[i + 1]);
            if (y > ans) {
               ans = y;
            }
            if (y < 0) {
               y = 0;
            }
         }
      }
      write(ans + sum);
   }
}

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

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}


Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three digits.

The first line contains integer n (2 ≤ n ≤ 100) — amount of digits in the phone number. The second line contains n digits — the phone number to divide into groups.

Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any.

var size = readline(), number = readline(), ans = []
var go = number.length, index = 0
while (go){
	var nxt = (go%2) ? 3 : 2
	ans.push(number.slice(index,index+nxt))
	index+= nxt; go-=nxt
}
print(ans.join("-"))

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

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

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

function main() {
	var digitNum = parseInt(readline());
	var s = trim(readline());

	var pos = (digitNum%2 == 0 ? 2 : 3);
	write(s.substring(0, pos));

	while (pos < digitNum) {
		write("-"+s.substring(pos, pos+2));
		pos += 2;
	}
	print();
}

main();

'use strict'

let N = +readline()
let L = readline()

let res = []

for (let i = 0; i <= N; i = i + 2) {
  res.push(L.slice(i, i + 2))
}

res = res.filter(Boolean)

if (N % 2) {
  res[res.length - 2] += res[res.length - 1]
  res.length--
}

print(res.filter(Boolean).join('-'))

var n=readline(); n=parseInt(n);
var arr=readline();
var three=0,two=0;
for(var i=0;i<=100;i++)
{
    for(var j=0;j<=100;j++)
    {
        var temp=n-i*2-j*3;
        if(temp==0)
        {
            three=j; two=i;
        }
    }
}
var num=0; var ans="";
for(var i=0;i<three;i++){for(var j=0;j<3;j++)write(arr[num++]); if(n!=num)write('-');}
for(var i=0;i<two;i++){for(var j=0;j<2;j++)write(arr[num++]); if(n!=num)write('-');}

var n = readline();
n = parseInt(n);

var tel = readline();

var output = '' ;

if (tel.length%2 == 0){
	output += tel[0] + tel[1];
	for(var i=2; i<tel.length; i = i + 2){
		output += '-' + tel[i] + tel[i+1];
	}
} else {
	output += tel[0] + tel[1] + tel[2];
	for(var i=3; i<tel.length; i = i + 2){
		output += '-' + tel[i] + tel[i+1];
	}
}
print(output);

'use strict'

let N = +readline()
let L = readline()

let res = []

for (let i = 0; i <= N / 2 + 3; i = i + 2) {
  res.push(L.slice(i, i + 2))
}

res = res.filter(Boolean)

if (N % 2) {
  res[res.length - 2] += res[res.length - 1]
  res.length--
}

print(res.filter(Boolean).join('-'))

'use strict'

let N = +readline()
let L = readline()

let res = []

for (let i = 0; i <= N / 2 + 3; i = i + 2) {
  res.push(L.slice(i, i + 2))
}

if (N % 2) {
  res[res.length - 2] += res[res.length - 1]
  res.length--
}

print(res.filter(Boolean).join('-'))

'use strict'

let N = +readline()
let L = readline()

let res = []

for (let i = 0; i <= N / 2 + 4; i = i + 2) {
  res.push(L.slice(i, i + 2))
}

res = res.filter(Boolean)

if (N % 2) {
  res[res.length - 2] += res[res.length - 1]
  res.length--
}

print(res.filter(Boolean).join('-'))


Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n.Bob gave you all the values of ai, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.

The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the information given.

Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.

NoteIn the first case, the answer can be {1, 2} or {2, 1}.In the second case, another possible answer is {2, 4, 5, 1, 3}.

var N = parseInt(readline());
var ans = [];
for (var i = N; i--; ) {
  ans.push(Math.max.apply(this, readline().split(' ')));
}
print(ans.join(' ').replace(` ${N-1}`, ` ${N}`));

var permutationLength = readline();
var permutation = [];
var object = {};
var biggestIntegerUsed = false;

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

    var rowOfMatrix = readline().split(" ");
    object = {};

    for (var j = 0; j < permutationLength; j++) {
        if (object[rowOfMatrix[j]]) {
            permutation[i] = rowOfMatrix[j];
            break;
        } else {
            object[rowOfMatrix[j]] = true;
        }
    }

    if (!permutation[i]) {
        permutation[i] = biggestIntegerUsed ? permutationLength - 1 : permutationLength;
        biggestIntegerUsed = true;
    }
}

print(permutation.join(" "));

var N = parseInt(readline());
var q = [], max;
var updateMax = (num) => {if (num > max) max = num;}
for (var i = N; i--; ) {
  max = -Infinity;
  readline().split(' ').forEach(updateMax);
  q.push(max);
}
print(q.join(' ').replace(N-1, N));

var N = parseInt(readline());
var q = [], ans = [];
for (var i = N; i--; ) {
  q.push(' '+readline().replace(/0/g, ''));
}
for (var i = 1, flag; i < N; ++i) {
  flag = false;
  for (var j = 0; j < N; ++j) {
    q[j] = q[j].replace(new RegExp(` ${i}`, 'g'), '');
    if (q[j] === ' ' && !ans[j] && !flag) {
      ans[j] = i;
      flag = true;
    }
  }
}
for (var i = 0; i < N; ++i) {
  if (typeof ans[i] === 'undefined') {
    ans[i] = N;
  }
}
print(ans.join(' '));


There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.

The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3).

Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.

NoteIn the example all the numbers equal to 1 and 3 should be replaced by 2.

'use strict'

let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v))

let c = [0, 0, 0]
for (let i = 0; i < N; i++) {
  c[lll[i] - 1]++
}
print(c[0] + c[1] + c[2] - Math.max(c[0], c[1], c[2]))

var cnt = new Array(4).fill(0);
cnt[0] =  Number.MAX_SAFE_INTEGER;
readline();
readline().split(" ").map((x)=>{ cnt[x]++; });
var out = 0;
var min = Math.min(...cnt);
out += min;
cnt.splice(cnt.indexOf(min),1);
out += Math.min(...cnt);
print(out);

var getNums = function() {
	return readline().split(' ').map(function(a) {return parseInt(a)});
};

var n = parseInt(readline());
var input = getNums();
var hash = {};

for(var j = 1; j <= 3; j++) {
	hash[j] = 0;
}

for (var i = 0; i < n; i++) {
	hash[input[i]]++;
}

print(Math.min(hash[1] + hash[2], hash[1] + hash[3], hash[3] + hash[2]));

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let indicator = 0, N;
rl.on('line', (input) => {
    if (indicator == 0){
        N = parseInt(input);
        indicator++;
    }
    else {
        let cont = input.split(' ').map(item => parseInt(item))
        let dict = {};
        let maxval = 0;
        cont.forEach(item => {
            if (item in dict)
                dict[item]++;
            else
                dict[item] = 1;

            if (maxval < dict[item])
                maxval = dict[item];

        });
        console.log(N - maxval);
        rl.close();
    }
});

var cnt = new Array(4).fill(0);
readline();
readline().split(" ").map((x)=>{ cnt[x]++; });
var max = Math.max(...cnt);
var out = 0;
cnt.map((x)=>{if(x!=max)out+=x;});
print(out);

var cnt = new Array(4).fill(0);
cnt.splice(cnt.indexOf(0),1);
readline();
readline().split(" ").map((x)=>{ cnt[x]++; });
var out = 0;
var min = Math.min(...cnt);
out += min;
cnt.splice(cnt.indexOf(min),1);
out += Math.min(...cnt);
print(out);

var cnt = new Array(4).fill(0);
readline();
readline().split(" ").map((x)=>{ cnt[x]++; });
var out = 0;
var min = Math.min(...cnt);
out += min;
cnt.splice(cnt.indexOf(min),1);
out += Math.min(...cnt);
print(out);

var getNums = function() {
	return readline().split(' ').map(function(a) {return parseInt(a)});
};

var n = parseInt(readline());
var input = getNums();
var hash = {};

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

print(Math.min(hash[1] + hash[2], hash[1] + hash[3], hash[3] + hash[2]));


Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are n camomiles growing in the field, possessing the numbers of petals equal to a1, a2, ... an. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet.

The first line contains an integer n (1 ≤ n ≤ 100), which is the number of flowers growing in the field. The second line contains n integers ai (1 ≤ ai ≤ 100) which represent the number of petals on a given i-th camomile.

Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.

'use strict';

// let inpFileStrArr = `
// 3
// 5 6 7
// `.trim().split('\n'), inpFileCounter = 0;
// function readline() {
//   return inpFileStrArr[inpFileCounter++];
// }
// function print(x) {
//   console.log(x);
// }

var isEven = function isEven(x) {
  return x % 2 === 0;
};

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

var sum = arr.reduce(function (a, b) {
  return a + b;
}, 0);

if (!isEven(sum)) {
  print(sum);
} else {
  arr.sort(function (a, b) {
    return a - b;
  });
  var needToRemove = arr.find(function (x) {
    return !isEven(x);
  });
  print(needToRemove ? sum - needToRemove : 0);
}

'use strict'

let N = +readline()
let lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => b - a)

let ss = 0
let p = [0]
let t = false

for (let n of lll) {
  if (n % 2) {
    t = true
    p.push(n)
    if (p.length == 2) {
      ss += p[0]
      ss += p[1]
      p = []
    }
  } else {
    ss += n
  }
}

print(t ? ss : 0)

'use strict';
/*
let input = `
1
1
`.trim().split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}
*/
//code

var n = Number(readline());
var flowers = readline().split(' ').map(Number);
var sum = flowers.reduce(function (acc, curr) {
	return acc + curr;
}, 0);
var minOdd = flowers.filter(function (el) {
	return el % 2 === 1;
}).sort(function (a, b) {
	return a - b;
}).shift();
print(sum % 2 === 1 ? sum : minOdd === undefined ? 0 : sum - minOdd);

var getNums = function() {
	return readline().split(' ').map(function(a) {return parseInt(a)});
};

var n = parseInt(readline());
var nums = getNums().sort(function(a, b){return b - a});
var sumParnih = 0, sumNeparnih = 0, prob = 0;

for (var i = 0; i < n; i++) {
	if (nums[i] % 2 === 0) {
		sumParnih += nums[i];
	} else {
		if (sumNeparnih == 0) {
			sumNeparnih = nums[i];
		} else {
			if (prob) {
				sumNeparnih = sumNeparnih + prob + nums[i];
				prob = 0;
			} else {
				prob = nums[i];
			}
		}
	}
}

if (sumNeparnih === 0) {
	print(0);
} else {
	print(sumParnih + sumNeparnih);
}

readline = require('readline')
let stdinInput = '';

function file1(){
    //file
    var fs = require('fs');
   const inputfile = '_in.txt';
   const outputfile = '_out.txt';
   fs.writeFileSync(outputfile, '');
   var myInterface = readline.createInterface({
     input: fs.createReadStream(inputfile),
   });
   myInterface.on('line', function (line) {
      stdinInput += line+'\n';
    }).on('close', () => {
           main();
        process.exit(0);
    })
}

function std1(){
    process.stdin.resume();
    process.stdin.setEncoding('utf-8');
    process.stdin.on('data', (input) => { stdinInput += input; });
    process.stdin.on('end', () => { main(); });
}
   /*
   *  Api Scanner
   */
  class Scanner {
    constructor() {
      this.index = -1;
      this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
    }

    nextLine() {
      this.index += 1;
      return this.lines[this.index].trim();
    }
    nextArray(fn) {
      const array = this.nextLine().split(' ');
      return fn === String ? array : array.map(fn);
    }

    hasNext() {
      return this.index < this.lines.length;
    }
  }

// file1();
std1();

let n, a, sum1;
function main() {
    const is = new Scanner();
    n = parseInt(is.nextLine());
    a = is.nextArray(Number);

    sum1 = 0;
    minle = 101;
    for(let i=0; i<n; i++){
        sum1+= a[i];
        if(a[i]%2!=0){
            minle = Math.min(a[i], minle);
        }
    }

    if(minle==101)
        minle = sum1;
    if(sum1%2==0)
        sum1-=minle;
    console.log(sum1);

}


Riley is a very bad boy, but at the same time, he is a yo-yo master. So, he decided to use his yo-yo skills to annoy his friend Anton.Anton's room can be represented as a grid with $$$n$$$ rows and $$$m$$$ columns. Let $$$(i, j)$$$ denote the cell in row $$$i$$$ and column $$$j$$$. Anton is currently standing at position $$$(i, j)$$$ in his room. To annoy Anton, Riley decided to throw exactly two yo-yos in cells of the room (they can be in the same cell).Because Anton doesn't like yo-yos thrown on the floor, he has to pick up both of them and return back to the initial position. The distance travelled by Anton is the shortest path that goes through the positions of both yo-yos and returns back to $$$(i, j)$$$ by travelling only to adjacent by side cells. That is, if he is in cell $$$(x, y)$$$ then he can travel to the cells $$$(x + 1, y)$$$, $$$(x - 1, y)$$$, $$$(x, y + 1)$$$ and $$$(x, y - 1)$$$ in one step (if a cell with those coordinates exists).Riley is wondering where he should throw these two yo-yos so that the distance travelled by Anton is maximized. But because he is very busy, he asked you to tell him.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of each test case contains four integers $$$n$$$, $$$m$$$, $$$i$$$, $$$j$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1\le i\le n$$$, $$$1\le j\le m$$$) — the dimensions of the room, and the cell at which Anton is currently standing.

For each test case, print four integers $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$1 \leq x_1, x_2 \leq n$$$, $$$1\le y_1, y_2\le m$$$) — the coordinates of where the two yo-yos should be thrown. They will be thrown at coordinates $$$(x_1,y_1)$$$ and $$$(x_2,y_2)$$$. If there are multiple answers, you may print any.

NoteHere is a visualization of the first test case.

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);
        console.log(1, 1, k[0], k[1]);
    }
});

//  var gcd = function(a, b) {
//   if (!b) {
//     return a;
//   }

//   return gcd(b, a % b);
// }
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)
        console.log(1, 1, k[0], k[1])
    }
});

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

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

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

		console.log(1, 1, n, m);
	}
}

//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 H = nextInt();
		var W = nextInt();
		var i = nextInt();
		var j = nextInt();
		myout(H + " " + W + " 1 1");
	}
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => ((await getLineGen.next()).value);
})();

let solve = async () => {
    const nsc = parseInt(await getLine());
    for(let sc = 0; sc < nsc; sc++) {
        let n, m, i, j;
        [n, m, i, j] = (await getLine()).split(' ').map(num => parseInt(num));
        let bestDist = -1, best1x, best2x, best1y, best2y;
        let getDist = function(x,y, x2, y2) {
            return Math.abs(x-x2) + Math.abs(y-y2);
        }
        let test = function(x1, y1, x2, y2) {
            const dist = getDist(i, j, x1, y1) + getDist(x1, y1, x2, y2) + getDist(i, j, x2, y2);
            if (dist > bestDist) {
                bestDist = dist;
                best1x = x1;
                best2x = x2;
                best1y = y1;
                best2y = y2;
            }
        }
        test(1,1,n, m);
        test(1, 1, 1, m);
        test(1, 1, n, 1);
        test(n, m, n, 1);
        test(n, m, 1, m);
        test(1, m, n, 1);
        console.log([best1x, best1y, best2x, best2y].join(' '));
    }
}

solve();

var matr = 'haha';

function create(str) {
   var hahaIndexArr = [];
   for (var i = 0; i < str.length; i++) {
      var hasWrong = false;
      for (var j = 0; j < matr.length; j++) {
         if (str[i + j] !== matr[j]) {
            hasWrong = true;
            break;
         }
      }
      if (!hasWrong) {
         hahaIndexArr.push(i);
      }
   }
   if (hahaIndexArr.length === 0) {
      if (str.length < 8) {
         return [str, -1, str];
      }
      return [str.substr(0, 4), 0, str.substr(str.length - 4, 0)];
   }
   var preff = str.substr(0, Math.min(4, hahaIndexArr[0])) || 'ha';
   var suff = str.substr(Math.max(hahaIndexArr[hahaIndexArr.length - 1] + 4, str.length - 4)) || 'ha';
   return [preff, hahaIndexArr.length, suff];
}
function summ(a, b) {
   var createMiddle = create(a[2] + b[0]);
   if (a[1] === -1 && b[1] === -1) {
      return createMiddle;
   }
   var preff = a[1] === -1 ? createMiddle[0] : a[0];
   var suff = b[1] === -1 ? createMiddle[2] : b[2];
   var asum = a[1] === -1 ? 0 : a[1];
   var bsum = b[1] === -1 ? 0 : b[1];
   var midSum = createMiddle[1] === -1 ? 0 : createMiddle[1];
   return [preff, asum + bsum + midSum, suff];
}

function solve() {
   var nmij = readArray(Number);
   var n = nmij[0];
   var m = nmij[1];
   write('1 1 ' + n + ' ' + m)
}

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

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

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

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

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

var readline = require('readline');

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

function solve(row, col, r, c) {
    if (r === 1) {
        return [row, 1, row, col]
    } else if (r === row) {
        return [1, 1, 1, col]
    } else if (c === 1) {
        return [1, col, row, col]
    } else if (c === col) {
        return [1, 1, row, 1]
    } else {
        return [1, 1, row, col]
    }
}

var cases = +readline();

for (var i = 1; i<=cases; i++){
    inp = readline().split(' ').map(x=>+x);
    n = inp[0];
    m = inp[1];

    print(1,1,n,m);
}

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);
        console.log(1, 1, k[2], k[3]);
    }
});

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 q = lines[i].split(' ').map(Number);
        var n = q[0], k = q[1];
        var b = 0;
        for(j = 2; j <= n; j++){
            if(n % j === 0){
                b = j;
                break;
            }
        }
        k--;
        n += b;
        n += (2*k);
        console.log(n);
    }
});

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('')
        if(k[k.length - 2] == 'c' && k[k.length - 1] == 'h' || k[k.length - 1] == 'x' || k[k.length - 1] == 's' ||k[k.length - 1] == 'o' ){
            if(k[k.length - 2] == 'c' && k[k.length - 1] == 'h' ){
                k.push('es')
            }else{
                k.push('es')

            }
        }
        else if(k[k.length - 2] == 'e' && k[k.length - 1] == 'f' || k[k.length - 1] == 'f'){
            if(k[k.length - 2] == 'e' && k[k.length - 1] == 'f'){
                k.splice(k.length - 2, 2)
                k.push('ves')
            }else{
                k.splice(k.length - 1, 1)
                k.push('ves')
            }
        }
        else if(k[k.length - 1] == 'y'){
             k.splice(k.length - 1, 1)
                k.push('ies')
        }
        else{
                k.push('s')
        }
        s = ''
        for(l = 0; l < k.length; l++){
            s+=k[l]
        }
        console.log(s)
    }

});