function main() {
  const is = new Scanner();
  let n, word, possible, container = {};
  for (let i = 'a'.charCodeAt(); i <= 'z'.charCodeAt(); i += 1)
    container[String.fromCharCode(i)] = 0;

  for (let t = is.nextInt(); t > 0; t -= 1) {
    n = is.nextInt();
    word = is.nextLine();
    for (let i = 0; i < n / 2; i += 1) {

      for (var letter in container) {
        if (container.hasOwnProperty(letter)) {
          container[letter] = 0;
        }
      }

      if (word[i] === 'a') {
        container.b += 1;
      } else if (word[i] === 'z') {
        container.y += 1;
      } else {
        container[String.fromCharCode(word[i].charCodeAt() + 1)] += 1;
        container[String.fromCharCode(word[i].charCodeAt() - 1)] += 1;
      }

      if (word[n - i - 1] === 'a') {
        container.b += 1;
      } else if (word[n - i - 1] === 'z') {
        container.y += 1;
      } else {
        container[String.fromCharCode(word[n - i - 1].charCodeAt() + 1)] += 1;
        container[String.fromCharCode(word[n - i - 1].charCodeAt() - 1)] += 1;
      }

      possible = false;
      for (var letter in container) {
        if (container.hasOwnProperty(letter)) {
          if (container[letter] >= 2) {
            possible = true;
            break;
          }
        }
      }

      if (!possible)
        break;
    }

    console.log(possible ? 'YES' : 'NO');
  }
}

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

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

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

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

var tests = parseInt(readline());

while(tests--) {
    readline();
    var s = readline();
    solver(s);
}

function solver(s){
    var l = s.length, h = l / 2;

    while(--h > -1) {
        if(![0, 2].includes(Math.abs(s.charCodeAt(h) - s.charCodeAt(l - h - 1)))) {
            print("NO");
            return false;
        }
    }

    print("YES");
    return true;
}

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', () => {
  let t = nextInt();
  while (t--) {
    nextInt();
    console.log(checkPalindromicTwist(nextString()));
  }
});

function nextInt() {
  return Number(lines.shift());
}

function nextString() {
  return lines.shift();
}

function same(char1, char2) {
  const a = char1[0].charCodeAt(0);
  const b = char2[0].charCodeAt(0);

  if (a === b) {
    return true;
  }

  return Math.abs(a - b) === 2;
}

function checkPalindromicTwist(str) {
  for (let i = 0; i < str.length; i++) {
    if (!same(str[i], str[str.length - 1 - i])) {
      return 'NO';
    }
  }
  return 'YES';
}

module.exports = checkPalindromicTwist;

var line = '';

/** @param {string} s */
function checkPalindrome(s)  {
    for(var i = 0; i < s.length >> 1; i++) {
        var frontChar = s[i],
            backChar = s[s.length - i - 1];

        if(backChar !== frontChar)  {
            switch(frontChar) {
                case 'a':
                    if(backChar !== 'c')  return false;
                    break;
                case 'z':
                    if(backChar !== 'x')  return false;
                    break;
                default:
                    if(Math.abs(backChar.charCodeAt(0) - frontChar.charCodeAt(0)) !== 2) return false;
                    break;
            }
        }
    }

    return true;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += (input.trim() + '\n');
});

process.stdin.on('end', function () {
    line = line.split(/\n/).map(l => l.replace(/\r/, ''));

    for(var i = 0; i < Number(line[0]); i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

/** @type {{[x: string]: number}} */
var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

/** @param {string} s */
function checkPalindrome(s)  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            if(backChar !== frontChar)  {
                switch(frontChar) {
                    case 'a':
                        if(backChar !== 'c')  return false;
                        break;
                    case 'z':
                        if(backChar !== 'x')  return false;
                        break;
                    default:
                        if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                        break;
                }
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/).map(l => l.replace(/\r/, ''));
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

/** @param {string} s */
function checkPalindrome(s)  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length);

    for(var i in front) {
        var frontChar = front[i],
            backChar = back[front.length - i - 1],
            frontCharCode = frontChar.charCodeAt(0),
            backCharCode = backChar.charCodeAt(0);

        if(backChar !== frontChar)  {
            switch(frontChar) {
                case 'a':
                    if(backChar !== 'c')  return false;
                    break;
                case 'z':
                    if(backChar !== 'x')  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }
    }

    return true;
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/).map(l => l.replace(/\r/, ''));
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

function checkPalindrome(s = '')  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                case 'z':
                    if(backCharCode !== frontCharCode)  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/);
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

function checkPalindrome(s = '')  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                case 'z':
                    if(backCharCode !== frontCharCode)  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    console.log(line);
    line = line.split(/\n/);
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

function checkPalindrome(s = '')  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                case 'z':
                    if(backCharCode !== frontCharCode)  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/).map(l => l.replace(/\r/, ''));
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

/** @type {{[x: string]: number}} */
var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

/** @param {string} s */
function checkPalindrome(s)  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                    if(backChar !== frontChar && backChar !== 'c')  return false;
                    break;
                case 'z':
                    if(backChar !== frontChar && backChar !== 'x')  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/).map(l => l.replace(/\r/, ''));
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

function checkPalindrome(s = '')  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                case 'z':
                    if(backCharCode !== frontCharCode)  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/);
    console.log(line);
    var n = Number(line[0]);

    for(var i = 0; i < n; i++)  {
        console.log(checkPalindrome(line[(i + 1) * 2]) ? 'YES' : 'NO');
    }

    process.exit(0);
});

var line = '';

var A = 'a'.charCodeAt(0);
var Z = 'z'.charCodeAt(0);

var m = {};

for(var i = A; i <= Z; i++) {
    m[String.fromCharCode(i)] = i;
}

function checkPalindrome(s = '')  {
    var front = s.slice(0, s.length >> 1),
        back = s.slice(s.length - front.length).split('').reverse().join('');

    if(front === back) {
        return true;
    } else {
        for(var i in front) {
            var frontChar = front[i],
                backChar = back[i],
                frontCharCode = m[frontChar],
                backCharCode = m[backChar];

            switch(frontChar) {
                case 'a':
                case 'z':
                    if(backCharCode !== frontCharCode)  return false;
                    break;
                default:
                    if(Math.abs(backCharCode - frontCharCode) !== 2) return false;
                    break;
            }
        }

        return true;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(input) {
  line += `${input.trim()}\n`;
});

process.stdin.on('end', function () {
    line = line.split(/\n/);

    for(var i = 1; i <= Number(line[0]); i*=2)  {
        console.log(checkPalindrome(line[i + 1]) ? 'YES' : 'NO');
    }

    process.exit(0);
});


function main(){
  var citizens = readline();
  var welfares = readline().split(" ").map(Number);

  var i = 0;
  var max = -1;
  var suma = 0;
  while (i<citizens) {
    if (max<welfares[i]) {
      max = welfares[i];
    }
    suma += welfares[i];
    i++;
  }
    print((citizens*max) - suma);
}

main();

function main() {
    // write code here:
    const n = Number(stdin[0]);
    var arr = stdin[1].split(' ').map(Number);
    const max = Math.max(...arr);
    var burles = 0;
    for (let i = 0; i < n; i++) {
        burles+=(max-arr[i]);
    }
    console.log(burles);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

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

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

readLine.on('close', () => {
    const count = parseInt(input[0], 10)
    let maxNum = 0
    const peoples = input[1].split(' ')
    let nowNums = 0
    peoples.forEach(el => {
        const _el = parseInt(el, 10)
        if (_el > maxNum)
            maxNum = _el
        nowNums += _el
    })
    const result = (maxNum * count) - nowNums
    console.log(result)
})

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var max = Math.max.apply(null, list);
  var sum = 0;
  for(var i = 0; i < N; i++){
    sum += max - list[i];
  }
  myout(sum);
}

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

  const arr = d.split(' ').map(Number);
  const max = Math.max(...arr);
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    ans += max - arr[i];
  }

  console.log(ans);

  c++;
});

function solve() {
	n = readline()
	a = readline().split(' ')
	v = Math.max.apply(Math, a)
	print(a.reduce((r,x) => r + v-x, 0))
}

if (typeof readline !== 'function') {
    let input = [],
            i = 0;
    function print() {
        console.log.apply(null, arguments);
    }
    function readline() {
        return input[i++];
    };

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

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

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

const input = [];

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

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

RL.on('close', () => {
  const nums = input[1].split(' ').map(x => parseInt(x));
  const max = nums.reduce((prev, next) => next > prev ? next : prev, 0);
  let ans = 0;

  nums.forEach(x => ans += max-x);
  console.log(ans);
});

// Sample code to perform I/O:

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

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let citizenCount = +inputs[0];
    let citizensWealth = inputs[1].split(' ');
    let max = Math.max(...citizensWealth);
    let add = 0;
    for (let row of citizensWealth) {
        add += max - row;
    }
    return add.toString();

}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let arr = readLine().split(' ').map(v => parseInt(v));
    arr.sort((a, b) => {
        return b - a;
    })
    let ans = arr.reduce((sum, value) => {
        return sum + Math.max(...arr) - value;
    }, 0)
    console.log(ans);
}

var n = parseInt(readline());
	var welfare = readline().split(" ").map(x=>+x);
	var spend=0;
	if(welfare.length === 1){
		spend = 0;
	}
	else{
		var sum = 0;
		var maximum = 0;
		for(var i = 0; i < n; i++){
			sum += welfare[i];
			maximum = Math.max(maximum, welfare[i]);
		}
		spend = n*maximum-sum;
	}
	print(spend);

var res = sol(readline(), readline());
print(res);

function sol(line1, line2) {
    var input1 = line1.split(" ").map((x) => Number(x));
    var input2 = line2.split(" ").map((x) => Number(x));

    var n = input1[0];
    var welfare = input2;

    var max = -1;
    welfare.map((x) => {
        max = Math.max(max, x)
    });

    var sum = 0;
    welfare.map((x) => {
        sum += Math.abs(max - x);
    });

    return sum;
}

(function() {
    'use strict';
    const n = readline();
    const z = readline().split(' ').map(Number);
    var x = Math.max.apply(null, z);
    var y = 0;
    for (let i = 0; i < n; ++i) {
        if (z[i] != x) {
            y += x - z[i];
        }
    }
    print(y);

}());

function main(){
  var citizens = readline();
  var welfares = readline().split(" ").map(Number);

  var max = welfares.reduce((a,b) => a > b ? a : b);

  var sum = 0;
  welfares.forEach(function(welfare){
    if(welfare < max)
      sum += (max - welfare);
  });

  print(sum);
}

main();

function readIntTabLine() {
  var l = readline().split(' ')
  for (var i = 0 ; i < l.length ; i++) {
    l[i] = parseInt(l[i])
  }
  return l
}

var n = parseInt(readline()),
    as = readIntTabLine(),
    max = as.reduce((s,v,i,a) => Math.max(s,v))

print(as.reduce((s,v,i,a) => s + max - v, 0))

'use strict';

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

function getMaxMoneyAmount(array) {
  var max = array[0];
  array.map(function (value) {
    if (value > max) {
      max = value;
    }
  });
  return max;
}

function getMoneyToBalancePeople(people) {
  var maxMoneyAmount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getMaxMoneyAmount(people);
  var sum = 0;
  people.map(function (value) {
    if (value < maxMoneyAmount) {
      sum += maxMoneyAmount - value;
    }
  });
  return sum;
}

readline();
var people = readline().getNumArray();
write(getMoneyToBalancePeople(people));

'use strict'

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

function getMaxMoneyAmount (array) {
  let max = array[0];
  array.map((value) => {
    if (value > max) {
      max = value
    }
  });
  return max;
}

function getMoneyToBalancePeople (people) {
  let maxMoneyAmount = getMaxMoneyAmount(people);
  let sum = 0;
  people.map((value) => {
    if (value < maxMoneyAmount) {
      sum += maxMoneyAmount - value;
    }
  });
  return sum;
}

readline();
let people = readline().getNumArray();
write(getMoneyToBalancePeople(people));

function main()
{
    var n = Number( readline() );
    var a = readline(' ').split(' ').map( Number );

    var sum = a.reduce( (p,n) => p+n , 0 );
    var mx = 0;
    a.forEach( (v) => mx = Math.max( mx , v ) );

    var ans = mx*n - sum;
    print(ans);
} main();

function main()
{
    var n = Number( readline() );
    var a = readline(' ').split(' ').map( Number );

    var sum = a.reduce( (p,n) => p+n , 0 );
    var max = a.reduce( (p,n) => Math.max(p,n) , 0 );

    var ans = max*n - sum;
    print(ans);
} main();

var n = parseInt(readline());
	var welfare = readline().split(" ").map(x=>+x);
	var totalSpend=0;
	if(welfare.length === 1){
		totalSpend = 0;
	}
	else{
		var sum = 0;
		var maximumBurle = 0;
		for(var i = 0; i < n; i++){
			sum += welfare[i];
			maximumBurle = Math.max(maximumBurle, welfare[i]);
		}
		totalSpend = n*maximumBurle-sum;
	}
    print(totalSpend);
    // console.log(spend);

var n =readline();
var str = readline().split(" ");
var res=0;
var max = Math.max.apply(this, str);
for (var i=0; i<n; i++){
	res += max-Number(str[i]);

}
print(res);

var q = readline();
if (+q < 2) {
	print("0");
}
else {
	var netWorth = readline().split(" ").map(Number);
	var max = Math.max.apply(Math, netWorth);
	print(netWorth.reduce(function (sum, next) { return sum + max - next; }, 0));
}

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

var m = 0;
for(var i=0; i<n; i++){
    m = Math.max(m, a[i]);
}
var s = 0;
for(var i=0; i<n;i++){
    s += m-a[i];
}
print(s);

"use strict";

var main = function() {
    var n = +rd();
    var A = rdAr();
    var max = Math.max(...A);
    pr(A.reduce((a, v) => a + (max - v), 0));
};

var rd = readline;
var pr = print;
var rdAr = () => { return rd().split(' ').map( v => +v); };
var cmpLt = (a, b) => a - b;
var cmpGt = (a, b) => b - a;

main();

readline()
a=readline().split(' ').map(Number)
m=Math.max.apply(null,a)
s=0
a.forEach(q => s += (m-q))
print(s)

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

var mx = 0;
for(var i = 0; i < n; i++)
    mx = Math.max(mx, a[i]);

var res = 0;
for(var i = 0; i < n; i++)
    res += mx - a[i];

print(res);

var n = readline();
var arr = readline().split(" ").map(Number).sort((a,b)=>a-b)
var count = 0
arr.forEach(i => count+=arr[n-1]-i)
print(count)

var n = readline();
var arr = readline().split(" ").map(Number).sort((a,b)=>a-b)
var count = 0
for(i=0;i<n;i++){count+=arr[n-1]-arr[i]};
print(count)

var n = readline();
var a = readline();

var m = 0;
for(var i=0; i<n; i++){
    m = Math.max(m, a[i]);
}
var s = 0;
for(var i=0; i<n;i++){
    s += m-a[i];
}
print(s);

var n = Number(readline());
var a = readline();

var m = 0;
for(var i=0; i<n; i++){
    m = Math.max(m, a[i]);
}
var s = 0;
for(var i=0; i<n;i++){
    s += m-a[i];
}
print(s);

function main(){
  var citizens = readline();
  var welfares = readline().split(" ").map(Number);

  var i = 0;
  var max = -1;
  var suma = 0;
  while (i>citizens) {
    if (max<welfares[i]) {
      max = welfares[i];
    }
    suma += welfares[i];
    i++;
  }
    print((citizens*max) - suma);
}

main();


let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        const sum = array.reduce((acc, v) => acc + v, 0);
        const xorSum = array.reduce((acc, v) => acc ^ v, 0);
        // console.log(array, 'sum, xorSum', sum, xorSum);
        if (sum === 2 * xorSum) {
            console.log(0);
            console.log();
        } else {
            let first = xorSum;
            let second = (sum + first);
            console.log(2);
            console.log(first, second);
            // assert(BigInt(sum) + BigInt(first) + BigInt(second) === BigInt(n) * (BigInt(xorSum) ^ BigInt(first) ^ BigInt(second)), 'Wrong answer 1');
        }
    }
});

function assert(condition, message) {
    if (!condition) {
        throw new Error(message);
    }
}

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        const sum = array.reduce((acc, v) => acc + v, 0);
        const xorSum = array.reduce((acc, v) => acc ^ v, 0);
        // console.log(array, 'sum, xorSum', sum, xorSum);
        if (sum === 2 * xorSum) {
            console.log(0);
            console.log();
        } else {
            let first = xorSum;
            if ((sum + first) % 2 === 0) {
                let second = (sum + first);
                console.log(2);
                console.log(first, second);
                // console.log('check sum + first, xorSum ^ first', sum + first, xorSum ^ first);
                // console.log('check first, second, xorSum ^ first ^ second', first, second, xorSum ^ first ^ second, (xorSum ^ first) ^ second);
                // console.log('check first, second, xorSum ^ first ^ second', first, second, xorSum ^ first ^ second, (xorSum ^ first) ^ second);
                // console.log(0 ^ 5952667316);
                // console.log('0 ^ 134523487', 0 ^ 134523487);
                // assert(sum + first + second === 2 * (xorSum ^ first ^ second), 'Wrong answer 1');
            } else {
                let second = 1;
                let third = (sum + first + second);
                console.log(3);
                console.log(first, second, third);
                // assert(sum + first + second + third === 2 * (xorSum ^ first ^ second ^ third), 'Wrong answer 2');
            }
        }
    }
});

function assert(condition, message) {
    if (!condition) {
        throw new Error(message);
    }
}

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let lines = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0);
    for (let i = 0; i < lines.length; i += 2) {
        const array = lines[i + 1].split(' ').map(Number);
        const sum = array.reduce((acc, v) => acc + v, 0);
        const xorSum = array.reduce((acc, v) => acc ^ v, 0);
        // console.log(array, 'sum, xorSum', sum, xorSum);
        if (sum === 2 * xorSum) {
            console.log(0);
        } else {
            let first = xorSum;
            if ((sum + first) % 2 === 0) {
                let second = (sum + first);
                console.log(first, second);
                // console.log('check', sum + first + second, 2 * (xorSum ^ first ^ second));
                assert(sum + first + second === 2 * (xorSum ^ first ^ second), 'Wrong answer');
            } else {
                let second = 1;
                let third = (sum + first + second);
                console.log(first, second, third);
                assert(sum + first + second + third === 2 * (xorSum ^ first ^ second ^ third), 'Wrong answer');
            }
        }
    }
});

function assert(condition, message) {
    if (!condition) {
        throw new Error(message);
    }
}


var count = 0;
var com;
var m = '-'.charCodeAt(0);
var p = '+'.charCodeAt(0);
var pattern = /:(\w| )*/;
var res = 0;
while((com = readline())) {
  if(com.charCodeAt(0) === m) {
    count--;
  }
  if(com.charCodeAt(0) === p) {
    count++;
  }
  if((com = com.match(pattern))) {
    res += (com[0].length - 1) * count;
  }
}
print(res);

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

const input = [];
let members = 0;
let traffic = 0;
rl.on('line', function (line) {
	if (line[0] === '+') {
		members++;
	} else if (line[0] === '-') {
		members--;
	} else {
		traffic += (line.length - line.indexOf(':') - 1) * members;
	}
});

rl.on('close', function (cmd) {
	console.log(traffic);
	process.exit(0);
});

const readline = require('readline');

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

var users = [], ans = 0;

rl.on('line', (input) => {
    switch(input[0]){
        case "+":
            users.push(input.substring(1));
            break;
        case "-":
            let n = users.indexOf(input.substring(1));
            users.splice(n, 1);
            break;
        default:
            //code... input = "mike:hello"
            let colonIndex = input.indexOf(":");
            let message = input.substring(colonIndex+1);
            ans += users.length * message.length;
            break;
    }
  }).on('close',()=>{
      //
      console.log(ans);
  });

const readline = require('readline');

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

var users = [];
var ans = 0;
rl.on('line', (input) => {

    //var cmd=input[0];
    var cmd = input.charAt(0);

    switch (cmd) {
        case '+': {
            users.push(input.substring(1));
            break;
        }
        case '-': {
            let index = users.indexOf(input.substring(1));
            users.splice(index, 1);
            break;
        }
        default: {
            let index = input.indexOf(':');
            let msg = input.substring(index + 1);
            ans += msg.length * users.length;

            break;
        }
    }

});

rl.on('close', function () {
    console.log(ans);
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
/**
 * while(true){
 *  string input = Console.ReadLine();
 * }
 */
/**
 *        01234
 * input="+Mike"
 *
 * .substr(fromIndex, countLen)     c++
 * .substring(fromIndex, endIndex)  python
 *        0123456789
 * var s="ABCDEFGHIJ"     => "FGH"
 *
 * s.substr(5,3)
 * s.substring(5,8)
 *
 */
/**
 *
 * default=>
 *         0123456789
 *  input="Mike:hello"
 *           01234
 *  message="hello"
 */
var users = [], ans = 0;
rl.on('line', (input) => {
    // console.log("input= %s  len= %d", input, input.length);
    switch (input[0]) {
        case '+':
            users.push(input.substr(1));
            break;
        case '-':
            let elemInd = users.indexOf(input.substr(1));
            users.splice(elemInd, 1);
            break;
        default:
            let colonInd = input.indexOf(':');
            let message = input.substr(colonInd + 1);
            ans += message.length * users.length;
            break;

    }
}).on('close', function () {
    // console.log('inside close  function');
    console.log(ans);
});

const readline = require('readline');

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

var users=[],ans=0;

rl.on('line', (input) => {

   switch (input[0]){
        case '+':
            users.push(input.substring(1));
            break;
        case '-':
            users.splice(users.indexOf(input.substring(1)),1);
            break;
        default:
            var message = input.substring(input.indexOf(':') + 1);
            ans += message.length * users.length;
            break;
   }
  }).on('close',()=>{
      console.log(ans);
  });

function solve(lns) {
  const s = new Set();
  let result = 0;
  for (const ln of lns) {
    const f = ln[0];
    const r = ln.substring(1);
    if (f === '+') {
      s.add(r);
    } else if (f === '-') {
      s.delete(r);
    } else {
      const [_, m] = ln.split(/:/);
      result = result + (m.length * s.size);
    }
  }
  return result;
}

function main(lines) {
  const trim_lines = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      trim_lines.push(t);
    }
  }
  const result = solve(trim_lines);
  console.log(result);
}

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

const readline = require('readline');

const INPUT = 'test.in';
const LOCAL = process.env.ENABLE_LOCAL_ENV === 'true';
const log = (...args) => {
    LOCAL && console.log(...args)
};
let rl;
let lineNr = 0;

/**
 * MAIN
 */
(async () => {
    const promises = await setup(INPUT);
    await Promise.all(promises);
    process.stdout.write(res.toString());
})();

function setup() {
    const promises = []
    rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
        terminal: false,
    });

    rl.on('line', (line) => {
        promises.push(work(line, lineNr));
        lineNr++;
    });

    rl.on('error', (err) => {
        log('Error:', err);
    });

    return new Promise(res => {
        rl.on('close', () => {
            res(promises)
            log('Done!');
        });
    });
}

let people = 0;
let res = 0;
async function work(line, lineNr) {
    if (line.startsWith('+')) {
        people++;
    } else if (line.startsWith('-')) {
        people--;
    } else {
        // console.log(line, line.trim().split(':')[1].length);
        res += (people * (line.trim().split(':')[1].length));
    }
}

/**
 *
 * Solution goes below
 *
 */
function solve(line) {

}

var line;
var c=0;
var ret=0;
while(line = readline()){
	if(line[0] == '+'){
		c++;
	}else if(line[0] == '-'){
		c--;
	}else{
		ret += line.split(':')[1].length * c;
	}
}
print(ret);

var counter = 0;
var users = [];
var cmd = "";
while (cmd != undefined) {
    cmd = readline();

    if (!cmd) { break; }

    switch (cmd.charAt(0)) {
        case "+":
            var commer = cmd.slice(1);
            users.push(commer);
            break
        case "-":
            var leaver = cmd.slice(1);
            users = users.filter(function (e) { return e != leaver });
            break
        default:
            var msg = cmd.slice(cmd.indexOf(":") + 1);
            counter += users.length * msg.length;
    }
}
print(counter);

const readline = require('readline');

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

var users=[], ans=0;
rl.on('line', (input) => {
    switch(input[0]){
      case '+':
          // here we want to add user in our users array/list
          // for example when input ="+mike" we add only mike without + sign
          users.push(input.substr(1));
          break;
      case '-':
          //here we want to remove this user from our users array/list
          // for examle if input = "-mike" we remove "mike"
          // to remove an element from array we should use splice built in method in javascript
          //so goole that and find out by yourself
          let ind = users.indexOf(input.substr(1));
          users.splice(ind, 1);
          break;
       default:
          // here you decide what you do...
          //good luck......
          let colonInd = input.indexOf(':');
          let msg = input.substr(colonInd+1);
          ans+=msg.length*users.length;

          break;
    }//end of switch loop
}).on('close',()=>{
    //output your answer here when you push ctrl + c
    console.log(ans);
});

var line
var inch = 0
var s = 0
while (line = readline()) {
	if (line[0] == '-') {inch--; continue}
	if (line[0] == '+') {inch++; continue}
	var m = line.split(':')[1]
	s += m.length * inch
}
print(s)

const readline = require('readline');

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

var Users = [],ans = 0;

rl.on('line', (input) => {
       switch(input[0]){
           case '+':
               Users.push(input.substring(1));
               break;
           case '-':
               let ind = Users.indexOf(input.substring(1));
               Users.splice(ind,1);
               break;
            default :
               let indx = input.indexOf(':') + 1;
               let message = input.substring(indx);
               ans += message.length * Users.length;
               break;
       }

}).on('close',()=>{
    console.log(ans);
});

// Generated by CoffeeScript 1.4.0
(function() {
  var line, n, t;

  n = 0;

  t = 0;

  while (line = readline()) {
    switch (line[0]) {
      case '+':
        n++;
        break;
      case '-':
        n--;
        break;
      default:
        t += n * (line.length - line.indexOf(':') - 1);
    }
  }

  print(t);

}).call(this);

var count = 0
var attendees = 0
while (line = readline()) {
    if (line[0] == "+") {
        attendees++
    }
    if (line[0] == "-") {
        attendees--
    }
    if (line[0] != "+" && line[0] != "-") {
        message = line.substr(line.indexOf(":") + 1)
        count += message.length*attendees
    }
}

print(count)

function userAdd(user){
    if (userList.indexOf(user) === -1) userList.push(user);
}

function userRemove(user){
    var id = userList.indexOf(user);
    if (id !== -1) userList.splice(id, 1);
}

function send(msg){
    traffic += msg.length * userList.length;
}

var i, input, cmd, temp, userList = [], traffic = 0;

while (true){
    input = readline();
    if (typeof input === 'undefined') break;

    cmd = input.substr(0,1);
    if (cmd === '+') {
        userAdd(input.substr(1));
    } else if (cmd === '-') {
        userRemove(input.substr(1));
    } else {
        send(input.split(':')[1]);
    }
}

print(traffic);

const readline = require("readline");

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

var cont = [];
var ans = 0;

rl.on("line", input => {

  switch (input[0]) {
    case "+":
      cont.push(input.substr(1));
      break;
    case "-":
      var ind = cont.indexOf(input.substr(1));
      cont.splice(ind, 1);
      break;
    default:
      var ind = input.indexOf(":");
      var msg = input.substr(ind + 1);
      ans += cont.length * msg.length;
      break;
  }
}).on("close", () => {
  console.log(ans);
});

/* rl.on('close' ,()=>{

    console.log("test")

});*/

var users = 0;
var mes = 0;
var result = 0;
var mass = [];
while (line = readline()) {
    line = line.split(":")
    if (line[0][0]=="+") {
        users++;
    }
    if (line[0][0]=="-") {
        users--;
    }
    if (line[1]!=undefined) {
        mes = line[1].length;
        result += mes*users;
    }
}

write(result);

const readline = require('readline');

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

var users = [];
var ans = 0;
rl.on('line', (input) => {
    // console.log("input = %s",input);
    switch (input[0]) {
        case '+':
            users.push(input.substring(1));
            break;
        case '-':
            users.splice(users.indexOf(input.substring(1)), 1);
            break;
        default:
            var colonIndex = input.indexOf(':');
            var msg = input.substring(colonIndex + 1);
            ans += msg.length * users.length;
            break;
    };

}).on('close', () => {
    console.log(ans);
});

/*
rl.on('close', () => {
    console.log(ans);
});
*/

const readline = require('readline');

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

var users = [];
 var ans=0;
rl.on('line', (input) => {
    if (input != "" && input != null) {

        //var cmd=input[0];
        var cmd = input.charAt(0);

        switch(cmd){
            case '+':{
                users.push(input.substring(1));
                 break;
            }
            case '-':{
                let index = users.indexOf(input.substring(1));
                users.splice(index,1);
                break;
            }
            default:{
                  let index=input.indexOf(':');
                  let msg=input.substring(index+1);
                  ans+=msg.length*users.length;

                break;
            }
        }
    }
    else{
        console.log(ans);
         rl.close();
    }

});

const readline = require("readline");

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

var cont = [];
var ans = 0;

rl.on("line", input => {
  console.log(`Received: ${input}`);

  switch (input[0]) {
    case "+":
      cont.push(input.substr(1));
      break;
    case "-":
      var ind = cont.indexOf(input.substr(1));
      cont.splice(ind, 1);
      break;
    default:
      var ind = input.indexOf(":");
      var msg = input.substr(ind + 1);
      ans += cont.length * msg.length;
      break;
  }
}).on("close", () => {
  console.log(ans);
});

/* rl.on('close' ,()=>{

    console.log("test")

});*/

t=0;
n=0;
while (c=readline(),c!=null) {
	if (c[0]==="+") n++;
	else if (c[0]==="-") n--;
	else {
		print(c.length,c.search(":"),n);
		t+=(c.length-c.search(":")-1)*n;
	}
}
print(t);


var n=+readline(),
a=readline().split(' ').map(Number),
n1=a.filter(function(v){return v<0;}),
n2=a.filter(function(v){return v>0;}),
n3=a.filter(function(v){return v===0;});
if(n2.length===0){
	n2.push(n1.pop());
	n2.push(n1.pop());
}
if(n1.length%2===0){
	n3.push(n1.pop());
}
print(n1.length+' '+n1.join(' '));
print(n2.length+' '+n2.join(' '));
print(n3.length+' '+n3.join(' '));

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

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

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

  const [plusArr, minusArr, zeroArr] = [[], [], []];
  for (let i = 0; i < len; i++) {
    if (arr[i] > 0) plusArr.push(arr[i]);
    else if (arr[i] < 0) minusArr.push(arr[i]);
    else zeroArr.push(arr[i]);
  }

  if (plusArr.length === 0) {
    plusArr.push(minusArr.pop());
    plusArr.push(minusArr.pop());
  }
  if (minusArr.length % 2 === 0) {
    zeroArr.push(minusArr.pop());
  }

  console.log(`${minusArr.length} ${minusArr.join(" ")}`);
  console.log(`${plusArr.length} ${plusArr.join(" ")}`);
  console.log(`${zeroArr.length} ${zeroArr.join(" ")}`);
}

let input = ''

// Input
process.stdin.on('data', line => {
	input += line
})

// Process
process.stdin.on('end', () => {
	const { EOL } = require('os')
	const lines = input.split(EOL).filter(data => data)

	const n = +lines[0]
	const numList = lines[1].split(' ').map(num => +num).sort((prev, cur) => prev - cur)
	console.log(`1 ${numList[0]}`)
	if (numList[n - 1] === 0) {
		console.log(`2 ${numList[1]} ${numList[2]}`)
		console.log(`${n - 3} ${numList.slice(3).join(' ')}`)
	}
	else {
		console.log(`1 ${numList[n - 1]}`)
		console.log(`${n - 2} ${numList.slice(1).slice(0, -1).join(' ')}`)
	}
})

;(function () {
	var n = +readline();
	var c = readline().split(' ').map(Number);

	print(1, c.splice(c.indexOf(Math.min.apply(null, c)), 1));
	var m = c.splice(c.indexOf(Math.max.apply(null, c)), 1);
	if ( m > 0 ) {
		print(1, m);
		print(n - 2, c.join(' '));
	} else if ( m == 0 ) {
		print(2, c.splice(c.indexOf(Math.min.apply(null, c)), 1), c.splice(c.indexOf(Math.min.apply(null, c)), 1));
		print(n - 3, c.join(' '), m);
	} else {
		print(2, m, c.splice(c.indexOf(Math.max.apply(null, c)), 1));
		print(n - 3, c.join(' '));
	}
}).call(this);

var a = [], b = [], c = [], r = [];
readline();
readline().split( ' ' ).forEach( function(item) {
    item = item - '';
    if (item < 0 && r.length < 2) {
        r.push( item );
    } else if (item < 0 && !a.length) {
        a.push( item );
    } else if (item < 0) {
        c.push( item );
    } else if (item > 0) {
        b.push( item );
    } else {
        c.push( item );
    }
} );

if (!b.length) {
    b.push( r.shift() );
    b.push( r.shift() );
}

if (!a.length) {
    a.push( r.shift() );
}

c.push.apply( c, r );

printArr( a );
printArr( b );
printArr( c );

function printArr(arr) {
    print( arr.length + ' ' + arr.join( ' ' ) );
}

let input = ''

// Input
process.stdin.on('data', line => {
	input += line
})

// Process
process.stdin.on('end', () => {
	const { EOL } = require('os')
	const lines = input.split(EOL).filter(data => data)
	console.log(lines)
})

let input = ''

// Input
process.stdin.on('data', line => {
	input += line
})

// Process
process.stdin.on('end', () => {
	const lines = input.split('\n')
	console.log(lines)
})

let input = ''

// Input
process.stdin.on('data', line => {
	input += line
})

// Process
process.stdin.on('end', () => {
	const { EOL } = require('os')
	const lines = input.split(EOL)
	console.log(lines)
})

var a = [], b = [], c = [], r = [];
readline();
readline().split( ' ' ).forEach( function(item) {
    item = item - '';
    if (item < 0 && r.length < 2) {
        r.push( item );
    } if (item < 0 && !a.length) {
        a.push( item );
    } else if (item < 0) {
        c.push( item );
    } else if (item > 0) {
        b.push( item );
    } else {
        c.push( item );
    }
} );

if (!b.length) {
    b.push( r.shift() );
    b.push( r.shift() );
}

if (!a.length) {
    a.push( r.shift() );
}

c.push.apply( c, r );

printArr( a );
printArr( b );
printArr( c );

function printArr(arr) {
    print( arr.length + ' ' + arr.join( ' ' ) );
}

var a = [], b = [], c = [], r = [];
readline();
readline().split( ' ' ).forEach( function(item) {
    item = item - '';
    if (item < 0 && r.length < 2) {
        r.push( item );
    } if (item < 0 && !a.length) {
        a.push( item );
    } else if (item < 0) {
        c.push( item );
    } else if (item > 0) {
        b.push( item );
    } else {
        c.push( item );
    }
} );

if (!b.length) {
    b.push.apply( b, r ); r = [];
} else if (!a.length) {
    a.push( r.shift() );
}

c.push.apply( c, r );

printArr( a );
printArr( b );
printArr( c );

function printArr(arr) {
    print( arr.length + ' ' + arr.join( ' ' ) );
}


;(function () {

	print((function (n) {
		var p = -1, h = 0;
		while (n--) {
			var s = +readline();
			p += 2 + Math.abs(s-h);
			h = s;
		}
		return p;
	})(+readline()));

}).call(this);

var n=+readline();
var ans=0;
var prev=0;
while(n--){
  h=+readline();
  ans+=Math.abs(h-prev)+2;
  prev=h;
}
print(ans-1);


const readline = require('readline')

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

function solve(n) {
    if (n === 3) return -1
    if (n === 5) return '5 4 1 2 3'
    const arr = Array(n)
    if (n & 1) {
        for (let i = 0; i < n; i++) {
            arr[i] = (i & 1) ? i : i + 2
            arr[i] += 3
        }
        arr[n - 3] = 3
        arr[n - 2] = 2
        arr[n - 1] = 1
    } else {
        for (let i = 0; i < n; i++) {
            arr[i] = (i & 1) ? i : i + 2
        }
    }
    return arr.join(' ')
}

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var p = parseInt(readline().trim());
    var o = [], popped = [];
    if (p == 3) {
      process.stdout.write('-1\n');
      continue;
    }
    if (p % 2 === 0) {
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o = o.join(' ')
          process.stdout.write(o + '\n');
        }
      }
    } else {
      o = [];
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o.reverse()
          popped.push(o.pop())
          popped.push(o.pop())
          o.unshift(popped[1].toString(), popped[0].toString())
          process.stdout.write(o.join(' ') + '\n')
        }
      }
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const testCases = Number(readline());
    for (let i = 0; i < testCases; i++) {
        let n = Number(readline());
        let ans = generateFunnyPermutation(n);
        console.log(ans === -1 ? -1 : ans.join(" "))
    }
}

function generateFunnyPermutation(n) {
    if (n === 2) return [2,1];
    if (n === 3) return -1;
    let arr = Array(n);
    for (let i = 0; i < n; i++) {
        arr[i] = i+1;
    }
    let mid = Math.floor((n-1)/2);
    rotateArr(arr, 0, n-1);
    rotateArr(arr, 0, mid);
    rotateArr(arr, mid+1, n-1);

    return arr;
}

function rotateArr(arr, s, e) {
    let start = s, end = e;

    while (start < end) {
        let tmp = arr[start];
        arr[start] = arr[end];
        arr[end] = tmp;
        start++;
        end--;
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    if (n === 3) console.log(-1);
    else if (n % 2 === 0)
      console.log(
        new Array(n)
          .fill(0)
          .map((a, i) => n - i)
          .join(" ")
      );
    else {
      let k = Math.ceil(n / 2);
      let arr = new Array(k).fill(0).map((a, i) => k + i);
      for (let i = k - 1; i >= 1; i--) arr.push(i);
      console.log(arr.join(" "));
    }
  }
};
solve();

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

let inputString = '';
let currentLine = 0;

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

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

    mufin();
});

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

}
*/
const y = [];
const z = [];
let ptr;
var gcd = function(a, b) {
    if (!b) {
    return a;
    }
    return gcd(b, a % b);
}

function add(x1, y1, z1)
{
    y1 = y1 / x1; z1 = z1 / x1;
    for(let i = 0; i < ptr; i++)
        if ((Math.abs(y1 - y[i]) < 0.000001) && (Math.abs(z1 - z[i]) < 0.000001))
        return 0;
    y[ptr] = y1; z[ptr] = z1;
    return ++ptr;
    }
    function sort(a, b) {
        if (a < b) {
        return -1;
        }
        if (a > b) {
        return 1;
        }
        return 0;
    }
function triangle(a, b, c)
{
    let temp = [a,b,c];
    sort(temp,temp+3);
    if(!add(temp[0],temp[1],temp[2])) return;
    let m = Math.sqrt(2*temp[0]*temp[0] + 2*temp[1]*temp[1] - temp[2]*temp[2]) / 2;
    triangle(temp[0],m,temp[2]/2);
    triangle(temp[1],m,temp[2]/2);
}
function f(n,a,b){
    let i;
    a[1] = 0; a[2] = 3;
    b[1] = 3; b[2] = 6;
    for(i = 3; i <= n; i++){
        a[i] = a[i-1] + b[i-1];
        b[i] = 2 * a[i-1] + b[i-1];
    }
    return a[n] + b[n];

}

function ff(n, k) {
    if (!n){
        return 0;
    }
    let tmp = 1 << (n - 1);
    if (k < tmp) return ff(n - 1, k);
    return tmp + ff(n - 1, (1 << n) - 1 - k);
}

function div(val, by){
    return (val - val % by) / by;
}
function PowMod(x, y, n)
{
    console.log(x * x % n)
	if (y === 0) {
        return 1;
    }
	if (y&1){
        return x * PowMod(x * x % n, div(y,2), n) % n;
    }
	return PowMod(x * x % n, div(y,2), n);
}
function binomial(n, k) {
    if ((typeof n !== 'number') || (typeof k !== 'number'))
    return false;
    var coeff = 1;
   for (var x = n-k+1; x <= n; x++) coeff *= x;
    for (x = 1; x <= k; x++) coeff /= x;
    return coeff;
}
function factorial(x) {

    if (x == 0) {
        return 1;
    }
    else {
        return x * factorial(x - 1);
    }
}
const fact = (a, b, c, x, y, z) => {
    return Math.sqrt(( x - a )*( x - a ) + ( y - b )*( y - b ) + ( z - c )*( z - c ));
}
function app(a,n1,n2,n3)
{
    if (a == 0){
        return 0;
    }
    app(a - 1, n1, n3, n2);
    if ((n1 + ' ' + n2) === undefined) {
        return 0;
    }
    console.log(n1 + ' ' + n2);
    app(a - 1, n3,n2,n1);
}

const diffDays = (day1, day2) => {
        if ((day1[6] !== day2[6] || day1[5] !== day2[5]) || (day1[8] !== day2[8] || day1[9] !== day2[9])) {
            return 1;
        }
        else{
            return 0;
        }
}

// 2022-03-19T06:06:00.000Z
// 2022-03-19T04:04:00.000Z
let pi = 3.14159265359;

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }
}
//Set.prototype.getByIndex = function(index) { return [...this][index]; }
//let mySet = new Set();
function mufin() {
    let k = readLine();
    while(k--){
        let n = readLine();
        if(n == 3)
            console.log(-1);
        else
        {
            if(n % 2 == 0){
                for(let i = 1; i <= n; i+=2)
                {
                    process.stdout.write(`${i+1} ${i} `);
                }
                process.stdout.write(`\n`);
            } else
            {
                process.stdout.write(`${n} ${n-1} `);
                for(let i = 1; i <= n-2; i++)
                    process.stdout.write(`${i} `);
                process.stdout.write(`\n`);
            }

        }

    }
}
function Fibonacci(n){
    if (n == 1) {
        return 1;
      }
      if (n == 2) {
        return 1;
      }
      if (n == 3) {
        return 1;
      }
      if (a[n] != -1) {
        return a[n];
      }
      if (n % 2 == 1) {
        return a[n] = Fibonacci(n - 1) + Fibonacci(n - 3);
      }
      return a[n] = Fibonacci(n - 1);

}
function io(x, y){
    if (x <= 0 || y <= 0) {
        return 0;
    }
    if (x < y) {
        return io(x-1, y-2) +  io(x-2, y-1);
    }
    if (x > y) {
        return io(x-2, y-2) + 1;
    }
}
function ctl(a)
{
    if(a==1){
        return 2;
    }
    if(a==2){
        return 4;
    }
    return ctl(a-1)+ctl(a-2);
}

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    while (t--) {
        let n = parseInt(readline())
        console.log(solve(n))
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n) => {

    if (n == 1) return "1"
    else if (n == 2) return "2 1"
    else if (n == 3) return "-1"
    else if (n == 4) return "4 3 1 2"
    else {
        let lim = Math.floor(n / 2) + 1
        let res = ''
        for (let i = n; i > lim; i--) res += i + ' '
        for (let i = 1; i <= lim; i++) res += i + ' '
        return res
    }
}

const isOdd = (num) => num & 1
const isEven = (num) => !(num & 1)
const minOfArray = (arr) => Math.min.apply(null, arr)
const maxOfArray = (arr) => Math.max.apply(null, arr)
const uniqueArray = (arr) => [...new Set(arr)]
const sortArray = (arr) => arr.sort((a, b) => a - b)
const sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)

'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, rb, rns, re, rbs] = convertInput(read);
  const n = rn();
  if (n === 1 || n === 3) return -1;
  const res = [n, n - 1];
  for (let i = 0; i < n - 2; i++) {
    res.push(i + 1);
  }
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

//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();
		if(N == 3){
			myout(-1);
			continue;
		}else if(N == 2){
			myout("2 1");
			continue;
		}
		var output = new Array(N);
		output[0] = N - 1;
		output[1] = N;
		for(var i = 2; i < N; i++){
			output[i] = i - 1;
		}
		myout(myconv(output, 8));
	}
}

var tcn = readline()

for(var tc = 0; tc < tcn; tc++) {
    var n = readline()
    var result = []

    if (n == 3 || n == 1) {
        print('-1')
    }
    else if (n % 2 == 0) {
        for(var j = 0; j < n/2; j++) {
            result.push(2*j + 2)
            result.push(2*j + 1)
        }
    }
    else {
        for(var j = (n - 1) / 2; j > 1; j--) {
            result.push(2*j)
            result.push(2*j + 1)
        }
        result.push(1)
        result.push(2)
        result.push(3)
    }

    result.forEach(x => write(`${x} `))
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var value = parseInt(readline());
    var result = "";
    if (value === 3)
    {
        result = -1;
    }
    else
    {
        result += `${value} ${value-1} `;
        for (var j = 1; j < value-1; j++)
        {
            result += `${j} `;
        }
    }
    print(result);
}

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var p = parseInt(readline().trim());
    var o = [], popped = [];
    if (p == 3) {
      process.stdout.write('-1\n');
      continue;
    }
    if (p % 2 === 0) {
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o = o.reverse().join(' ')
          process.stdout.write(o + '\n');
        }
      }
    } else {
      o = [];
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o.reverse()
          popped.push(o.pop())
          popped.push(o.pop())
          o.unshift(popped[1].toString(), popped[0].toString())
          process.stdout.write(o.join(' ') + '\n')
        }
      }
    }
  }
}

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var p = parseInt(readline().trim());
    if (p == 3) {
      process.stdout.write('-1\n');
      continue;
    }
    if (p % 2 === 0) {
      var o = [];
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o = o.reverse().join(' ')
          process.stdout.write(o + '\n');
        }
      }
    } else {
      var o = [], popped = [];
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          popped.push(o.pop())
          popped.push(o.pop())
          popped = popped.reverse();
          o.unshift(popped[0], popped[1])
          process.stdout.write(o + '\n')
        }
      }
    }
  }
}

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();
  });
  solve();
});
function readline() {
  return inputString[currentLine++];
}

function solve() {
  var t = readline();
  for (var k = 0; k < t; k++) {
    var p = parseInt(readline().trim());
     var o = [], popped = [];
    if (p % 2 === 0) {
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o = o.join(' ')
          process.stdout.write(o + '\n');
        }
      }
    } else {
      o = [];
      for (var i = p; i > 0; i--) {
        o.push(i);
        if (i - 0 == 1) {
          o.reverse()
          popped.push(o.pop())
          popped.push(o.pop())
          o.unshift(popped[1].toString(), popped[0].toString())
          process.stdout.write(o.join(' ') + '\n')
        }
      }
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const testCases = Number(readline());
    for (let i = 0; i < testCases; i++) {
        let n = Number(readline());
        let ans = generateFunnyPermutation(n);
        console.log(ans === -1 ? -1 : ans.join(" "))
    }
}

function generateFunnyPermutation(n) {
    if (n === 2) return [2,1];
    if (n === 3) return -1;
    let arr = Array(n);
    for (let i = 0; i < n; i++) {
        arr[i] = i+1;
    }
    let mid = Math.floor(n/2);
    rotateArr(arr, 0, n-1);
    rotateArr(arr, 0, mid);
    rotateArr(arr, mid+1, n-1);

    return arr;
}

function rotateArr(arr, s, e) {
    let start = s, end = e;

    while (start < end) {
        let tmp = arr[start];
        arr[start] = arr[end];
        arr[end] = tmp;
        start++;
        end--;
    }
}

const readline = require('readline')

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

function solve(n) {
    if (n === 3) return -1
    const arr = Array(n)
    if (n & 1) {
        for (let i = 0; i < n; i++) {
            arr[i] = (i & 1) ? i : i + 2
            arr[i] += 3
        }
        arr[n - 3] = 3
        arr[n - 2] = 2
        arr[n - 1] = 1
    } else {
        for (let i = 0; i < n; i++) {
            arr[i] = (i & 1) ? i : i + 2
        }
    }
    return arr.join(' ')
}

var tcn = readline()

for(var tc = 0; tc < tcn; tc++) {
    var n = readline()
    var result = []

    if (n == 3 || n == 1) {
        print('-1')
    }
    else if (n % 2 == 0) {
        for(var j = 0; j < n/2; j++) {
            result.push(2*j + 2)
            result.push(2*j + 1)
        }
    }
    else {
        for(var j = (n - 1) / 2; j > 1; j--) {
            result.push(2*j)
            result.push(2*j + 1)
        }
        result.push(1)
        result.push(2)
        result.push(3)
    }
}

result.forEach(x => write(`${x} `))

var tcn = readline()

for(var tc = 0; tc < tcn; tc++) {
    var n = readline()
    var result = []

    if (n == 3 || n == 1) {
        print('-1')
    }
    else if (n % 2 == 0) {
        for(var j = 0; j < n/2; j++) {
            result.push(2*j + 2)
            result.push(2*j + 1)
        }
    }
    else {
        for(var j = (n - 1) / 2; j > 1; j--) {
            result.push(2*j)
            result.push(2*j + 1)
        }
        result.push(1)
        result.push(2)
        result.push(3)
    }
}

result.forEach(x => print(`${x} `))