You are given an array of integers $$$a_1,a_2,\ldots,a_n$$$. Find the maximum possible value of $$$a_ia_ja_ka_la_t$$$ among all five indices $$$(i, j, k, l, t)$$$ ($$$i<j<k<l<t$$$).

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t\le 2 \cdot 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$5\le n\le 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-3\times 10^3\le a_i\le 3\times 10^3$$$) — given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print one integer — the answer to the problem.

NoteIn the first test case, choosing $$$a_1,a_2,a_3,a_4,a_5$$$ is a best choice: $$$(-1)\cdot (-2) \cdot (-3)\cdot (-4)\cdot (-5)=-120$$$.In the second test case, choosing $$$a_1,a_2,a_3,a_5,a_6$$$ is a best choice: $$$(-1)\cdot (-2) \cdot (-3)\cdot 2\cdot (-1)=12$$$.In the third test case, choosing $$$a_1,a_2,a_3,a_4,a_5$$$ is a best choice: $$$(-1)\cdot 0\cdot 0\cdot 0\cdot (-1)=0$$$.In the fourth test case, choosing $$$a_1,a_2,a_3,a_4,a_6$$$ is a best choice: $$$(-9)\cdot (-7) \cdot (-5)\cdot (-3)\cdot 1=945$$$.

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => n);
    let output = "";
    let max = -Infinity;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1n;
      for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);

      if (max < mul) max = mul;
    }
    max = max === -0n ? 0n : max;
    output += max;

    console.log(output);
  }
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}
function min(a, b) {
  if (a > b) return b;
  return a;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(1, t, i => {
    let n = inp[r++];
    let a = inp.slice(r, r = r + n);
    // console.log(a);
    a=a.map(v => BigInt(v));
    let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);
    let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);
    let min2 = Arr(0, n - 2, (i, p) => min(p, min(a[i+1] * min1[i], a[i+1] * max1[i])), 1e100);
    let max2 = Arr(0, n - 2, (i, p) => max(p, max(a[i+1] * min1[i], a[i+1] * max1[i])), -1e100);
    let min3 = Arr(0, n - 3, (i, p) => min(p, min(a[i+2] * min2[i], a[i+2] * max2[i])), 1e100);
    let max3 = Arr(0, n - 3, (i, p) => max(p, max(a[i+2] * min2[i], a[i+2] * max2[i])), -1e100);
    let min4 = Arr(0, n - 4, (i, p) => min(p, min(a[i+3] * min3[i], a[i+3] * max3[i])), 1e100);
    let max4 = Arr(0, n - 4, (i, p) => max(p, max(a[i+3] * min3[i], a[i+3] * max3[i])), -1e100);
    let min5 = Arr(0, n - 5, (i, p) => min(p, min(a[i+4] * min4[i], a[i+4] * max4[i])), 1e100);
    let max5 = Arr(0, n - 5, (i, p) => max(p, max(a[i+4] * min4[i], a[i+4] * max4[i])), -1e100);
    console.log(max5[n-5]+'')
  })
})();

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)

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)

  const descComp = (a, b) => b - a
let i = 0
  while (T--) {

    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 1n

    if (a.length === 5) {
      out += multToBigInt(...a) + '\n'
      continue
    }

    const neg = []
    const pos = []

    for (let i = 0, l = a.length; i < l; i++) {
      const x = a[i]
      if (x < 0) neg.push(x)
      else pos.push(x)
    }

    pos.sort(descComp)
    neg.sort(cmpi)

    const nl = neg.length
    const pl = pos.length

    if (pl === 0) {
      for (let i = 5; i > 0; i--) {
        result *= BigInt(neg[nl - i])
      }
    } else if (nl === 0) {
      for (let i = 0; i < 5; i++) {
        result *= BigInt(pos[i])
      }
    } else {
      let lastNeg = null
      let lastPos = null
      let ni = 0
      let pi = 0

      for (let i = 0; i < 5; i++) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (ni === nl) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn > -nn) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn < -nn) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (result < 0n) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        }
      }

      if (result < 0n) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl || lastNeg === null) {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        } else if (ni === nl || lastPos === null) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else if (pn * lastPos > nn * lastNeg) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else  {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        }
      }
    }

    out += result + '\n'
  }

  console.log(out)
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    let max = Number.MIN_SAFE_INTEGER;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1;
      for (let j = 0; j < i; j++) mul *= arr[j];
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];
      max = Math.max(max, mul);
    }
    max = max === -0 ? 0 : max;
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (plusArr.length >= 3) {
      let [_plusAll, _plusThree] = [1, 1];
      for (let i = 0; i < plusArr.length; i++) {
        _plusAll *= plusArr[i];
        if (i < 3) _plusThree *= plusArr[i];
      }
      max = Math.max(max, _plusAll, _plusThree * minusArr[0] * minusArr[1]);
    }
    if (minusArr.length >= 4) {
      let [_minusAll, _minusThree] = [1, 1];
      for (let i = 0; i < minusArr.length; i++) {
        _minusAll *= minusArr[i];
        if (i < 4) _minusThree *= minusArr[i];
      }
      if (plusArr.length !== 0) {
        max = Math.max(max, _minusAll, _minusThree * plusArr[0]);
      } else {
        max = Math.max(max, _minusAll);
      }
    }
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    let max = Number.MIN_SAFE_INTEGER;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1;
      for (let j = 0; j < i; j++) mul *= arr[j];
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];
      max = Math.max(max, mul);
    }
    max === -0 ? 0 : max;
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (arr.length === 5) {
      const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];
      max = Math.max(max, mul);
    }

    if (plusArr.length >= 5) {
      let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];

      max = Math.max(max, _plusAll);
    }

    if (plusArr.length >= 3 && minusArr.length >= 2) {
      let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];

      max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);
    }

    if (plusArr.length >= 1 && minusArr.length >= 4) {
      let _plusTwo = plusArr[0];

      max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    max = max === -0 ? 0 : max;
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => n);
    let output = "";
    let max = Number.MIN_SAFE_INTEGER;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1n;
      for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);

      if (max < mul) max = mul;
    }
    max = max === -0n ? 0n : max;
    output += max;

    console.log(output);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (plusArr.length >= 5) {
      let _plusAll = 1;
      for (let i = 0; i < plusArr.length; i++) {
        _plusAll *= plusArr[i];

        max = Math.max(max, _plusAll);
      }
    }

    if (plusArr.length >= 3 && minusArr.length >= 2) {
      let _plusThree = 1;
      for (let i = 0; i < plusArr.length; i++) {
        if (i < 3) _plusThree *= plusArr[i];
      }
      max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);
    }

    if (plusArr.length >= 1 && minusArr.length >= 4) {
      let _plusTwo = plusArr[0];

      max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (plusArr.length >= 5) {
      let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];

      max = Math.max(max, _plusAll);
    }

    if (plusArr.length >= 3 && minusArr.length >= 2) {
      let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];

      max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);
    }

    if (plusArr.length >= 1 && minusArr.length >= 4) {
      let _plusTwo = plusArr[0];

      max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    let max = Number.MIN_SAFE_INTEGER;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1;
      for (let j = 0; j < i; j++) mul *= arr[j];
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= arr[k];
      max = Math.max(max, mul);
    }
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (arr.length === 5) {
      const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];
      max = Math.max(max, mul);
    }

    if (plusArr.length >= 5) {
      let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];

      max = Math.max(max, _plusAll);
    }

    if (plusArr.length === 3) {
      max = Math.max(
        max,
        plusArr[0] * plusArr[1] * plusArr[2] * minusArr[0] * minusArr[1],
        plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]
      );
    }

    if (plusArr.length === 1 || plusArr.length === 2) {
      max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    max = max === -0 ? 0 : max;
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => n);
    let output = "";
    let max = Number.MIN_SAFE_INTEGER;
    arr.sort((a, b) => b - a);

    for (let i = 0; i <= 5; i++) {
      let mul = 1n;
      for (let j = 0; j < i; j++) mul *= BigInt(arr[j]);
      for (let k = len - 1; k >= len - 5 + i; k--) mul *= BigInt(arr[k]);
      mul = mul + "";
      max = Math.max(max, mul);
    }
    max = max === -0n ? 0n : max;
    output += max;

    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (arr.length === 5) {
      const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];
      max = Math.max(max, mul);
    }

    if (plusArr.length >= 5) {
      let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];

      max = Math.max(max, _plusAll);
    }

    if (plusArr.length === 3 || plusArr.length === 4) {
      max = Math.max(max, plusArr[0] * plusArr[1] * plusArr[2] * minusArr[0] * minusArr[1]);

      if (minusArr.length >= 4) {
        max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
      }
    }

    if (plusArr.length === 1 || plusArr.length === 2) {
      max = Math.max(max, plusArr[0] * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    max = max === -0 ? 0 : max;
    console.log(max);
  }
}

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() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [plusArr, minusArr] = [[], []];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (n >= 0) plusArr.push(n);
        else minusArr.push(n);
        return n;
      });

    plusArr.sort((a, b) => b - a);
    minusArr.sort((a, b) => a - b);

    let max = Number.MIN_SAFE_INTEGER;

    if (arr.length === 5) {
      const mul = arr[0] * arr[1] * arr[2] * arr[3] * arr[4];
      max = Math.max(max, mul);
    }

    if (plusArr.length >= 5) {
      let _plusAll = plusArr[0] * plusArr[1] * plusArr[2] * plusArr[3] * plusArr[4];

      max = Math.max(max, _plusAll);
    }

    if (plusArr.length >= 3 && minusArr.length >= 2) {
      let _plusThree = plusArr[0] * plusArr[1] * plusArr[2];

      max = Math.max(max, _plusThree * minusArr[0] * minusArr[1]);
    }

    if (plusArr.length >= 1 && minusArr.length >= 4) {
      let _plusTwo = plusArr[0];

      max = Math.max(max, _plusTwo * minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3]);
    }

    if (minusArr.length >= 5 && plusArr.length === 0) {
      let _minusAll = minusArr[0] * minusArr[1] * minusArr[2] * minusArr[3] * minusArr[4];

      max = Math.max(max, _minusAll);
    }
    console.log(max);
  }
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}
function min(a, b) {
  if (a > b) return b;
  return a;
}
var min = Math.min;
var max = Math.max;

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(1, t, i => {
    let n = inp[r++];
    let a = inp.slice(r, r = r + n);
    let amin = [], amax = [];
    let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);
    let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);
    let min2 = Arr(0, n - 2, (i, p) => min(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), 1e100);
    let max2 = Arr(0, n - 2, (i, p) => max(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), -1e100);
    let min3 = Arr(0, n - 3, (i, p) => min(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), 1e100);
    let max3 = Arr(0, n - 3, (i, p) => max(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), -1e100);
    let min4 = Arr(0, n - 4, (i, p) => min(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), 1e100);
    let max4 = Arr(0, n - 4, (i, p) => max(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), -1e100);
    let min5 = Arr(0, n - 5, (i, p) => min(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), 1e100);
    let max5 = Arr(0, n - 5, (i, p) => max(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), -1e100);
    console.log(max5[n - 5]+'')
  })
})();

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}
function min(a, b) {
  if (a > b) return b;
  return a;
}
var min = Math.min;
var max = Math.max;

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(1, t, i => {
    let n = inp[r++];
    let a = inp.slice(r, r = r + n);
    let amin = [], amax = [];
    let min1 = Arr(0, n - 1, (i, p) => min(p, a[i]), 1e100);
    let max1 = Arr(0, n - 1, (i, p) => max(p, a[i]), -1e100);
    let min2 = Arr(0, n - 2, (i, p) => min(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), 1e100);
    let max2 = Arr(0, n - 2, (i, p) => max(p, a[i + 1] * min1[i], a[i + 1] * max1[i]), -1e100);
    let min3 = Arr(0, n - 3, (i, p) => min(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), 1e100);
    let max3 = Arr(0, n - 3, (i, p) => max(p, a[i + 2] * min2[i], a[i + 2] * max2[i]), -1e100);
    let min4 = Arr(0, n - 4, (i, p) => min(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), 1e100);
    let max4 = Arr(0, n - 4, (i, p) => max(p, a[i + 3] * min3[i], a[i + 3] * max3[i]), -1e100);
    let min5 = Arr(0, n - 5, (i, p) => min(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), 1e100);
    let max5 = Arr(0, n - 5, (i, p) => max(p, a[i + 4] * min4[i], a[i + 4] * max4[i]), -1e100);
    console.log(max5[n - 5])
  })
})();

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)

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)

  const descComp = (a, b) => b - a

  while (T--) {
    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 1n

    if (a.length === 5) {
      out += multToBigInt(...a) + '\n'
      continue
    }

    const neg = []
    const pos = []

    for (let i = 0, l = a.length; i < l; i++) {
      const x = a[i]
      if (x < 0) neg.push(x)
      else pos.push(x)
    }

    pos.sort(descComp)
    neg.sort(cmpi)

    const nl = neg.length
    const pl = pos.length

    if (pl === 0) {
      for (let i = 5; i > 0; i--) {
        result *= BigInt(neg[nl - i])
      }
    } else if (nl === 0) {
      for (let i = 0; i < 5; i++) {
        result *= BigInt(pos[i])
      }
    } else {
      let lastNeg = null
      let lastPos = null
      let ni = 0
      let pi = 0

      for (let i = 0; i < 5; i++) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (ni === nl) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn > nn) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn < nn) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (result < 0n) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        }
      }

      if (result < 0n) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        } else if (ni === nl) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else if (pn > -nn) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else  {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        }
      }
    }

    out += result + '\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')

    main()
})

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

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

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)

  const descComp = (a, b) => b - a

  while (T--) {

    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 1n
try {
    if (a.length === 5) {
      out += multToBigInt(...a) + '\n'
      continue
    }

    const neg = []
    const pos = []

    for (let i = 0, l = a.length; i < l; i++) {
      const x = a[i]
      if (x < 0) neg.push(x)
      else pos.push(x)
    }

    pos.sort(descComp)
    neg.sort(cmpi)

    const nl = neg.length
    const pl = pos.length

    if (pl === 0) {
      for (let i = 5; i > 0; i--) {
        result *= BigInt(neg[nl - i])
      }
    } else if (nl === 0) {
      for (let i = 0; i < 5; i++) {
        result *= BigInt(pos[i])
      }
    } else {
      let lastNeg = null
      let lastPos = null
      let ni = 0
      let pi = 0

      for (let i = 0; i < 5; i++) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (ni === nl) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn > -nn) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn < -nn) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (result < 0n) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        }
      }

      if (result < 0n) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl || lastNeg === null) {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        } else if (ni === nl || lastPos === null) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else if (pn > -nn) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else  {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        }
      }
    }

    out += result + '\n'
  } catch (e) {
    console.log(e)
    console.log('n = ', n, 'a = ', a)
  }
  }

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

    main()
})

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

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

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)

  const descComp = (a, b) => b - a

  while (T--) {

    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 1n
try {
    if (a.length === 5) {
      out += multToBigInt(...a) + '\n'
      continue
    }

    const neg = []
    const pos = []

    for (let i = 0, l = a.length; i < l; i++) {
      const x = a[i]
      if (x < 0) neg.push(x)
      else pos.push(x)
    }

    pos.sort(descComp)
    neg.sort(cmpi)

    const nl = neg.length
    const pl = pos.length

    if (pl === 0) {
      for (let i = 5; i > 0; i--) {
        result *= BigInt(neg[nl - i])
      }
    } else if (nl === 0) {
      for (let i = 0; i < 5; i++) {
        result *= BigInt(pos[i])
      }
    } else {
      let lastNeg = null
      let lastPos = null
      let ni = 0
      let pi = 0

      for (let i = 0; i < 5; i++) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (ni === nl) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn > -nn) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn < -nn) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (result < 0n) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        }
      }

      if (result < 0n) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        } else if (ni === nl) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else if (pn > -nn) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else  {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        }
      }
    }

    out += result + '\n'
  } catch (e) {
    console.log(e)
    console.log('n = ', n, 'a = ', a)
  }
  }

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

    main()
})

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

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

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  const multToBigInt = (a1, a2, a3, a4, a5) => BigInt(a1 * a2 * a3) * BigInt(a4 * a5)

  const descComp = (a, b) => b - a
let i = 0
  while (T--) {
i++
    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 1n
try {
    if (a.length === 5) {
      out += multToBigInt(...a) + '\n'
      continue
    }

    const neg = []
    const pos = []

    for (let i = 0, l = a.length; i < l; i++) {
      const x = a[i]
      if (x < 0) neg.push(x)
      else pos.push(x)
    }

    pos.sort(descComp)
    neg.sort(cmpi)

    const nl = neg.length
    const pl = pos.length

    if (pl === 0) {
      for (let i = 5; i > 0; i--) {
        result *= BigInt(neg[nl - i])
      }
    } else if (nl === 0) {
      for (let i = 0; i < 5; i++) {
        result *= BigInt(pos[i])
      }
    } else {
      let lastNeg = null
      let lastPos = null
      let ni = 0
      let pi = 0

      for (let i = 0; i < 5; i++) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (ni === nl) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn > -nn) {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        } else if (pn < -nn) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else if (result < 0n) {
          lastNeg = nn
          result *= BigInt(lastNeg)
          ni++
        } else {
          lastPos = pn
          result *= BigInt(lastPos)
          pi++
        }
      }

      if (result < 0n) {
        const pn = pos[pi]
        const nn = neg[ni]
        if (pi === pl || lastNeg === null) {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        } else if (ni === nl || lastPos === null) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else if (pn > -nn) {
          result /= BigInt(lastNeg)
          result *= BigInt(pn)
        } else  {
          result /= BigInt(lastPos)
          result *= BigInt(nn)
        }
      }
    }

    out += result + '\n'
    if (i === 39) {
      console.log('n=', n, 'a=', a)
    }
  } catch (e) {
    console.log(e)
    console.log('n = ', n, 'a = ', a)
  }
  }

  console.log(out)
}


There are $$$n$$$ children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right.Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other. You are given the number $$$n$$$, the initial arrangement of children and the number $$$k$$$. You have to find a way for the children to act if they want to finish the process in exactly $$$k$$$ seconds. More formally, for each of the $$$k$$$ moves, you need to output the numbers of the children who turn left during this move.For instance, for the configuration shown below and $$$k = 2$$$ children can do the following steps:    At the beginning, two pairs make move: $$$(1, 2)$$$ and $$$(3, 4)$$$. After that, we receive the following configuration:    At the second move pair $$$(2, 3)$$$ makes the move. The final configuration is reached. Good job.   It is guaranteed that if the solution exists, it takes not more than $$$n^2$$$ "headturns".

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 3000$$$, $$$1 \le k \le 3000000$$$)  — the number of children and required number of moves. The next line contains a string of length $$$n$$$ and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right.

If there is no solution, print a single line with number $$$-1$$$. Otherwise, output $$$k$$$ lines. Each line has to start with a number $$$n_i$$$ ($$$1\le n_i \le \frac{n}{2}$$$)  — the number of pairs of children, who turn at this move. After that print $$$n_i$$$ distinct integers  — the numbers of the children who will turn left during this move.  After performing all "headturns", there can't be a pair of two neighboring children looking at each other. If there are many solutions, print any of them.

NoteThe first sample contains a pair of children who look at each other. After one move, they can finish the process.In the second sample, children can't make any move. As a result, they can't end in $$$k>0$$$ moves.The third configuration is described in the statement.

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

function solve(n, k, a) {
  let count = 0;
  let steps = [];
  while (1) {
    let step = [];
    for (let i = 0; i < a.length - 1; ++i) {
      if (a[i] === 'R' && a[i + 1] === 'L') {
        a[i] = 'L'; a[i + 1] = 'R';
        step.push(i + 1);
        ++i;
        ++count;
      }
    }
    if (step.length === 0) break;
    steps.push(step);
  }
  if (k < steps.length || k > count) {
    console.log(-1);
    return;
  }
  let result = [];
  for (let i in steps) {
    while (steps[i].length > 1 && k > steps.length - i) {
      result.push('1 ' + steps[i].pop());
      --k;
    }
    result.push(steps[i].length + ' ' + steps[i].join(' '));
    --k;
  }
  console.log(result.join('\n'));
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const [n, k] = readLine();
  const a = lines[currentLine++].split('');
  solve(n, k, a);
}

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

function solve(n, k, a) {
  let count = 0;
  let steps = [];
  while (1) {
    let step = [];
    for (let i = 0; i < a.length - 1; ++i) {
      if (a[i] === 'R' && a[i + 1] === 'L') {
        a[i] = 'L'; a[i + 1] = 'R';
        step.push(i + 1);
        ++i;
        ++count;
      }
    }
    if (step.length === 0) break;
    steps.push(step);
  }
  if (k < steps.length || k > count) {
    console.log(-1);
    return;
  }
  for (let i in steps) {
    while (steps[i].length > 1 && k > steps.length - i) {
      console.log('1 ' + steps[i].pop());
      --k;
    }
    process.stdout.write(steps[i].length.toString());
    while(steps[i].length > 0) {
      process.stdout.write(' ' +steps[i].pop());
    }
    console.log('');
  }
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const [n, k] = readLine();
  const a = lines[currentLine++].split('');
  solve(n, k, a);
}

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

function solve(n, k, a) {
  let count = 0;
  let steps = [];
  while (1) {
    let step = [];
    for (let i = 0; i < a.length - 1; ++i) {
      if (a[i] === 'R' && a[i + 1] === 'L') {
        a[i] = 'L'; a[i + 1] = 'R';
        step.push(i + 1);
        ++i;
        ++count;
      }
    }
    if (step.length === 0) break;
    steps.push(step);
  }
  if (k < steps.length || k > count) {
    console.log(-1);
    return;
  }
  for (let i in steps) {
    while (steps[i].length > 1 && k < steps.length - i) {
      console.log('1 ' + steps[i].pop());
      --k;
    }
    console.log(steps[i].length + ' ' + steps[i].join(' '));
  }
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const [n, k] = readLine();
  const a = lines[currentLine++].split('');
  solve(n, k, a);
}

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

function solve(n, k, a) {
  let count = 0;
  let steps = [];
  while (1) {
    let step = [];
    for (let i = 0; i < a.length - 1; ++i) {
      if (a[i] === 'R' && a[i + 1] === 'L') {
        a[i] = 'L'; a[i + 1] = 'R';
        step.push(i + 1);
        ++i;
        ++count;
      }
    }
    if (step.length === 0) break;
    steps.push(step);
  }
  if (k < steps.length || k > count) {
    console.log(-1);
    return;
  }
  for (let i in steps) {
    while (steps[i].length > 1 && k < steps.length - i) {
      console.log('1 ' + steps[i].pop());
      --k;
    }
    process.stdout.write(steps[i].length.toString());
    while(steps[i].length > 0) {
      process.stdout.write(' ' +steps[i].pop());
    }
    console.log('');
  }
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const [n, k] = readLine();
  const a = lines[currentLine++].split('');
  solve(n, k, a);
}


To improve the boomerang throwing skills of the animals, Zookeeper has set up an $$$n \times n$$$ grid with some targets, where each row and each column has at most $$$2$$$ targets each. The rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and the columns are numbered from $$$1$$$ to $$$n$$$ from left to right.  For each column, Zookeeper will throw a boomerang from the bottom of the column (below the grid) upwards. When the boomerang hits any target, it will bounce off, make a $$$90$$$ degree turn to the right and fly off in a straight line in its new direction. The boomerang can hit multiple targets and does not stop until it leaves the grid.   In the above example, $$$n=6$$$ and the black crosses are the targets. The boomerang in column $$$1$$$ (blue arrows) bounces $$$2$$$ times while the boomerang in column $$$3$$$ (red arrows) bounces $$$3$$$ times. The boomerang in column $$$i$$$ hits exactly $$$a_i$$$ targets before flying out of the grid. It is known that $$$a_i \leq 3$$$.However, Zookeeper has lost the original positions of the targets. Thus, he asks you to construct a valid configuration of targets that matches the number of hits for each column, or tell him that no such configuration exists. If multiple valid configurations exist, you may print any of them.

The first line contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$.  The next line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ $$$(0 \leq a_i \leq 3)$$$.

If no configuration of targets exist, print $$$-1$$$.  Otherwise, on the first line print a single integer $$$t$$$ $$$(0 \leq t \leq 2n)$$$: the number of targets in your configuration.   Then print $$$t$$$ lines with two spaced integers each per line. Each line should contain two integers $$$r$$$ and $$$c$$$ $$$(1 \leq r,c \leq n)$$$, where $$$r$$$ is the target's row and $$$c$$$ is the target's column. All targets should be different.   Every row and every column in your configuration should have at most two targets each.

NoteFor the first test, the answer configuration is the same as in the picture from the statement. For the second test, the boomerang is not supposed to hit anything, so we can place $$$0$$$ targets. For the third test, the following configuration of targets matches the number of hits, but is not allowed as row $$$3$$$ has $$$4$$$ targets.   It can be shown for this test case that no valid configuration of targets will result in the given number of target hits.

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let n = $(), a = $(n)
  let r = n;
  let rc = Arr(n, i => 0)
  let fr = n - 1;
  ForR(n, i => {
    if (a[i] == 0) return;
    if (a[i] == 1) {
      r--;
      rc[r] = 1;
      out.push([r + 1, i + 1])
    } else if (a[i] == 2) {
      while (fr >= 0 && rc[fr] != 1) fr--;
      if (fr < 0) {
        log(-1);
        process.exit()
      }
      rc[fr] = 2;
      out.push([fr + 1, i + 1])
    } else {
      if (!out.length) {
        log(-1);
        process.exit();
      }
      r--;
      rc[r] = 2;
      let x = out[out.length - 1];
      rc[x[0] - 1] = 2;
      out.push([r + 1, x[1]])
      out.push([r + 1, i + 1])
    }
  })
  log(out.length);
  log(out.map(v => v.join(' ')).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 => string.trim());

    main();
});

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

function main() {
    const n = Number.parseInt(readLine());
    const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));
    let targets = 0;
    let nextRow = 0;
    let answer = '';
    try {
        for (let i = 0; i < expectedColHits.length; i++) {
            if (expectedColHits[i] === 1) {
                targets++;
                answer += (nextRow++ + 1) + ' ' + (i + 1) + '\n';
            } else if (expectedColHits[i] === 2) {
                targets += 2;
                answer += (nextRow + 1) + ' ' + (i + 1) + '\n';
                answer += (nextRow++ + 1) + ' ' + (1 + nextCol1(expectedColHits, i)) + '\n';
            } else if (expectedColHits[i] === 3) {
                targets += 2;
                answer += (nextRow + 1) + ' ' + (i + 1) + '\n';
                answer += (nextRow++ + 1) + ' ' + (1 + nextColGreater0(expectedColHits, i)) + '\n';
            }
        }
    } catch (e) {
        console.log(-1);
        return;
    }
    if (nextRow > n) {
        console.log(-1);
        return;
    }
    console.log(targets);
    console.log(answer);
}

function nextCol1(expectedColHits, i) {
    for (let k = i+1; k < expectedColHits.length; k++) {
        if (expectedColHits[k] === 1) {
            expectedColHits[k] = 0;
            return k;
        }
    }
    throw new Error();
}
function nextColGreater0(expectedColHits, i) {
    for (let k = i+1; k < expectedColHits.length; k++) {
        if (expectedColHits[k] > 0) {
            return k;
        }
    }
    throw new Error();
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let n = $(), a = $(n)
  let r = n;
  let rc = Arr(n, i => 0)
  let fr = n - 1;
  ForR(n, i => {
    if (a[i] == 0) return;
    if (a[i] == 1) {
      r--;
      rc[r] = 1;
      out.push([r + 1, i + 1])
    } else if (a[i] == 2) {
      while (fr >= 0 && rc[fr] != 1) fr--;
      if (fr < 0) {
        log(-1);
        process.exit()
      }
      rc[fr] = 2;
      out.push([fr + 1, i + 1])
    } else {
      if (!out.length) {
        log(-1);
        process.exit();
      }
      r--;
      rc[r] = 2;
      out.push([r + 1, out[out.length - 1][1]])
      out.push([r + 1, i + 1])
    }
  })
  log(out.length);
  log(out.map(v => v.join(' ')).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 => string.trim());

    main();
});

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

function main() {
    const n = Number.parseInt(readLine());
    const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));
    let targets = [];
    let nextRow = 0;
    try {
        for (let i = 0; i < expectedColHits.length; i++) {
            if (expectedColHits[i] === 1) {
                targets.push([nextRow++, i]);
            } else if (expectedColHits[i] === 2) {
                targets.push([nextRow, i]);
                targets.push([nextRow++, nextCol(expectedColHits, i)])
            } else if (expectedColHits[i] === 3) {
                const col = nextCol(expectedColHits, i);
                targets.push([nextRow, i]);
                targets.push([nextRow++, col])
                targets.push([nextRow++, col])
            }
        }
    } catch (e) {
        console.log(-1);
        return;
    }
    if (nextRow > n) {
        console.log(-1);
        return;
    }
    console.log(targets.length);
    for (let i = 0; i < targets.length; i++) {
        console.log(targets[i][0] + 1, targets[i][1] + 1);
    }
}

function nextCol(expectedColHits, i) {
    for (let k = i; k < expectedColHits.length; k++) {
        if (expectedColHits[k] === 1) {
            expectedColHits[k] = 0;
            return k;
        }
    }
    throw new Error();
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const n = Number.parseInt(readLine());
    const expectedColHits = readLine().split(' ').map(h => Number.parseInt(h));
    let targets = 0;
    let nextRow = 0;
    let answer = '';
    try {
        for (let i = 0; i < expectedColHits.length; i++) {
            if (expectedColHits[i] === 1) {
                targets++;
                answer += nextRow++ + ' ' + i + '\n';
            } else if (expectedColHits[i] === 2) {
                targets += 2;
                answer += nextRow++ + ' ' + i + '\n';
                answer += nextRow++ + ' ' + nextCol1(expectedColHits, i) + '\n';
            } else if (expectedColHits[i] === 3) {
                targets += 2;
                answer += nextRow++ + ' ' + i + '\n';
                answer += nextRow++ + ' ' + nextColGreater0(expectedColHits, i) + '\n';
            }
        }
    } catch (e) {
        console.log(-1);
        return;
    }
    if (nextRow > n) {
        console.log(-1);
        return;
    }
    console.log(targets);
    console.log(answer);
}

function nextCol1(expectedColHits, i) {
    for (let k = i+1; k < expectedColHits.length; k++) {
        if (expectedColHits[k] === 1) {
            expectedColHits[k] = 0;
            return k;
        }
    }
    throw new Error();
}
function nextColGreater0(expectedColHits, i) {
    for (let k = i+1; k < expectedColHits.length; k++) {
        if (expectedColHits[k] > 0) {
            return k;
        }
    }
    throw new Error();
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers. You want to distribute these $$$n$$$ integers into two groups $$$s_1$$$ and $$$s_2$$$ (groups can be empty) so that the following conditions are satisfied:  For each $$$i$$$ $$$(1 \leq i \leq n)$$$, $$$a_i$$$ goes into exactly one group. The value $$$|sum(s_1)| - |sum(s_2)|$$$ is the maximum possible among all such ways to distribute the integers.Here $$$sum(s_1)$$$ denotes the sum of the numbers in the group $$$s_1$$$, and $$$sum(s_2)$$$ denotes the sum of the numbers in the group $$$s_2$$$.Determine the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 2 \cdot 10^4)$$$  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 10^5)$$$  — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2 \ldots a_n$$$ $$$(-10^9 \leq a_i \leq 10^9)$$$  — elements of the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, output a single integer  — the maximum possible value of $$$|sum(s_1)| - |sum(s_2)|$$$.

const x = readline(); // first line

for(var i = 0 ; i < x ; i++) {
  readline(); // skip line
  var inp = readline().split(' ').map(x => parseInt(x));
  var func = arr => Math.abs(arr.reduce((prev, curr) => prev + curr, 0));
  print(func(inp));
}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var caseLength = parseInt(readline());
    var caseArray = readline().split(" ");
    var total = 0;
    for (var j = 0; j < caseLength; j++)
    {
        total += parseInt(caseArray[j]);
    }
    if (total < 0) total *= -1;
    print(total);
}

t=readline()
while(t--){
  readline()
  r=0
  a=readline().split(" ").map(Number)
  for(i=0;i<a.length;i++)r+=a[i]
  print(Math.abs(r))
}

const cntInput = readline();
for (var i=0; i<cntInput; i++) {
    var arrLen = readline();
    var arrStr = readline();

    var s1 = 0;
    var s2 = 0;

    var inputArr = arrStr.split(' ');

    for (var k=0; k<arrLen; k++) {
        if (inputArr[k] < 0) {
            s1 = s1 + parseInt(inputArr[k]);
        }
        else {
            s2 = s2 + parseInt(inputArr[k]);
        }
    }

    var absS1 = Math.abs(s1);
    var absS2 = Math.abs(s2);

    var ret = (absS1 > absS2) ? (absS1 - absS2) : (absS2 - absS1);

    print(ret);
}

"use strict";

const rl = require('readline').createInterface(process.stdin, process.stdout);
let all_input = [];

rl.on('line', function(input){
  all_input.push(input);
});

rl.on('close', function(line){
  let index = 0;
  let t = parseInt(all_input[index]);
  index++;

  //for(int i = 0; i < t; i++)
  while(t--)
  {
    let n = parseInt(all_input[index]);
    index++;

    let arr = all_input[index].trim().split(' ').map(Number);
    index++;
    solve(arr, n);
  }
});

function solve(arr, n)
{
  let negative_sum = 0, positive_sum = 0;

  for(let i = 0; i < n; i++)
  {
    if(arr[i] <= 0)
      negative_sum += Math.abs(arr[i]);
    else
      positive_sum += arr[i];
  }

  console.log(Math.abs(negative_sum - positive_sum));
}

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin2(n, nums) {
    // print(n, nums);
    let s1 = 0, s2 = 0;
    for(let i = 0; i < n; i++) {
        if(nums[i] >= 0) {
            s1 += nums[i];
        } else {
            s2 += nums[i];
        }
    }
    let res = Math.abs(Math.abs(s1) -Math.abs(s2));
    print(res);
}

function begin(n, nums) {
    // print(n, nums);
    let sum = 0;
    for(let i = 0; i < n; i++) {
        sum += nums[i]
    }
    let res = Math.abs(sum);
    print(res);
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var x = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, x);
    }
}

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, nums) {
    // print(n, nums);
    let s1 = 0, s2 = 0;
    for(let i = 0; i < n; i++) {
        if(nums[i] >= 0) {
            s1 += nums[i];
        } else {
            s2 += nums[i];
        }
    }
    let res = Math.abs(Math.abs(s1) -Math.abs(s2));
    print(res);

}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        var x = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(n, x);
    }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 0; j < n; j++){
                ans += a[j];
            }
            console.log(Math.abs(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) {
    return Math.abs(arr.reduce((s, x) => s + x, 0))
}

'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++) {
        const n = Number(readline());
        let arr = readline().split(" ").map(x => Number(x))
        console.log(findMaximumSum(arr))
    }
}

function findMaximumSum(arr) {
    arr.sort((a, b) => a - b)
    let sum1 = 0, sum2 = 0, i = 0;
    while (i < arr.length) {
        if (arr[i] < 0) sum1 += arr[i]
        else sum2 += arr[i]
        i++
    }

    return Math.abs(Math.abs(sum2) - Math.abs(sum1))
}

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;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var a = readline().split(" ").map(w => parseInt(w));
	a.sort((x, y) => x-y);
	var cur = 0, sum = 0;
	for(var i=0;i<n;i++) sum += a[i];
	var ans = sum;
	for(var i=0;i<n;i++) {
		cur += a[i];
		ans = max(ans, abs(sum - cur) - abs(cur));
		ans = max(ans, abs(cur) - abs(sum-cur));
	}
	console.log(ans)
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        let s1 = 0, s2 = 0
        lines[line++].split(' ').map(x => {
            const a = parseInt(x, 10)
            if (a > 0) s1 += a;
            else s2 += a
        })
        console.log(Math.abs(s1+s2))
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function powerOfTwo(x) {
    return Math.log2(x) % 1 === 0;
}

function mode(arr){
    return arr.sort((a,b) =>
          arr.filter(v => v===a).length
        - arr.filter(v => v===b).length
    ).pop();
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine())

        let arr = readLine().split(" ").map(x=>parseInt(x))

        let sumpos=0
        let sumneg=0
        //console.log("arr" + arr)
        for(let i=0;i<n;i++)
        {
            if(arr[i]>0)
                sumpos+=arr[i]
            else
                sumneg+=-arr[i]
        }
        //console.log("sumpos" + sumpos)
        //console.log("sumneg" + sumneg)
        if(sumpos>sumneg)
            console.log(sumpos - sumneg)
        else
            console.log(sumneg - sumpos)

   }
}

'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);
  rn();
        const a = rns();
  let x = 0,
      y = 0;
  for (let num of a) {
    if (num > 0) {
      x += num;
    } else if (num < 0) {
      y -= num;
    }
  }
  return Math.abs(x - y);
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      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(/\r?\n/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

"use strict";

function solve(array)
{
  let len = array.length;
  let negative_sum, positive_sum;

  negative_sum = positive_sum = 0;

  for(let i = 0; i < len; i++)
  {
    if(parseInt(array[i]) <= 0)
      negative_sum += Math.abs(parseInt(array[i]));
    else
      positive_sum += parseInt(array[i]);
  }

  console.log(Math.abs(negative_sum - positive_sum));
}

let test_count = 0, n = 0;

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

readline.on('line', function(line){
  let arr = line.split(' ');

  if(test_count === 0)
    n = arr[0];
  else if( (test_count != 0) && (test_count % 2 === 0) )
  {
    solve(arr);
  }

  if(test_count == (2 * n) )
    readline.close();

  test_count++;
});


You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose k numbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array.

The first line contains two integers nA, nB (1 ≤ nA, nB ≤ 105), separated by a space — the sizes of arrays A and B, correspondingly. The second line contains two integers k and m (1 ≤ k ≤ nA, 1 ≤ m ≤ nB), separated by a space. The third line contains nA numbers a1, a2, ... anA ( - 109 ≤ a1 ≤ a2 ≤ ... ≤ anA ≤ 109), separated by spaces — elements of array A. The fourth line contains nB integers b1, b2, ... bnB ( - 109 ≤ b1 ≤ b2 ≤ ... ≤ bnB ≤ 109), separated by spaces — elements of array B.

Print "YES" (without the quotes), if you can choose k numbers in array A and m numbers in array B so that any number chosen in array A was strictly less than any number chosen in array B. Otherwise, print "NO" (without the quotes).

NoteIn the first sample test you can, for example, choose numbers 1 and 2 from array A and number 3 from array B (1 < 3 and 2 < 3).In the second sample test the only way to choose k elements in the first array and m elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in A will be less than all the numbers chosen in B: .

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const lengths = readline().split(' ');
  const choosenNumbers = readline().split(' ');
  const arrayA = readline().split(' ');
  const arrayB = readline().split(' ');
  const choosenNumbersFromA = parseInt(choosenNumbers[0])
  const choosenNumbersFromB = parseInt(choosenNumbers[1])

  console.log(helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) ? 'YES' : 'NO')
}

function helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {
  return parseInt(arrayA[choosenNumbersFromA - 1]) < parseInt(arrayB[arrayB.length - choosenNumbersFromB])
}

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

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

  if (c === 1) {
    [k, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  if (c === 2) {
    arr1 = d.split(' ').map(Number);
    c++;
    return;
  }

  arr2 = d.split(' ').map(Number).reverse();

  if (arr1[k - 1] < arr2[m - 1]) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

var input = readline().split(" "), na = +input[0], nb = +input[1],
	input = readline().split(" "), k = +input[0], m = +input[1],
	a = readline().split(" ").map(Number), b = readline().split(" ").map(Number),
	arrA = [], arrB = [], maxA, minB;

if(a[na-1] < a[nb-1]){
	write("YES");
}
else{
	arrA = a.slice(0,k);
	arrB = b.reverse().slice(0,m).reverse();

	maxA = Math.max.apply(null,arrA);
	minB = Math.min.apply(null,arrB);

	if(maxA < minB){
		write("YES");
	}
	else{
		write("NO");
	}
}

function main(a,b,k,m,ar,br){

  var ans = 0;
  for(var i = b ; i > b-m-1 ; i--){

  if(ar[k-1] < br[i])ans++;
  }
  if(ans == m){
    print("YES");
    return;
  }
    print("NO");
}

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

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

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

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

main(ab[0],ab[1],km[0],km[1],ar,br);

var data = readline().split(' ');
var Na = parseInt(data[0]);
var MasA=[];
var MasB=[];
var Nb = parseInt(data[1]);
var data = readline().split(' ');
var k = parseInt(data[0]);
var m = parseInt(data[1]);
var data = readline().split(' ');
for (i=0;i<Na;i++){
	MasA[i]=parseInt(data[i]);
}
var data = readline().split(' ');
for (i=0;i<Nb;i++){
	MasB[i]=parseInt(data[i]);
}
var result = "YES"
if (MasA[k-1]>=MasB[MasB.length-m]){
	result = "NO";
}
//write(MasA[k-1]+" ");
//write(MasB[MasB.length-m]+ " ");
write(result);

var n1n2 = readline().split(' ');

var n1 = Number(n1n2[0]),
	n2 = Number(n1n2[1]);

var km = readline().split(' ');

var k = Number(km[0]);
var m = Number(km[1]);

var a = readline().split(' ').map(Number);
var b = readline().split(' ').map(Number);

var maxOfArr1 = a.slice(0, k)[k - 1];
var largerNumsInB = 0;

for (var i = b.length - 1; i >= 0; i--) {
	if (b[i] > maxOfArr1) {
		largerNumsInB++;
	}
}

if (largerNumsInB >= m) {
	print('YES');
} else {
	print('NO');
}

function getInputs() {
    return readline().split(' ').map(function(x) { return parseInt(x) });
}

var inputs = getInputs();

var sizeA = inputs[0];
var sizeB = inputs[1];

var limits = getInputs();

var k = limits[0];
var m = limits[1];

var A = getInputs();
var B = getInputs();

var first = A.slice(0, k);
var second = B.slice(-m);

var answer = 'YES';

for (var i = 0; i < k; i++) {
    var item = first[i];

    var isLess = false;

    for (var j = 0; j < m; j++) {

        if (item < second[j]) {
            isLess = true;
            break;
        } else {
            isLess = false;
            break;
        }
    }

    if (!isLess) {
        answer = 'NO';
        break;
    }
}

print(answer);

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const lengths = readline().split(' ');
  const choosenNumbers = readline().split(' ');
  const arrayA = readline().split(' ');
  const arrayB = readline().split(' ');
  const choosenNumbersFromA = parseInt(choosenNumbers[0])
  const choosenNumbersFromB = parseInt(choosenNumbers[1])

  console.log(helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) ? 'YES' : 'NO')
}

function helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {
  return arrayA[choosenNumbersFromA - 1] < arrayB[arrayB.length - choosenNumbersFromB]
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const lengths = readline();
  const choosenNumbers = readline();
  const arrayA = readline();
  const arrayB = readline();

  console.log(helper(parseInt(choosenNumbers.split(' ')[0]), arrayA.split(' '), arrayB.split(' ')) ? 'YES' : 'NO')
}

function helper(choosenNumbersFromA, arrayA, arrayB) {
  return arrayA[choosenNumbersFromA - 1] < arrayB[0]
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const lengths = readline();
  const choosenNumbers = readline();
  const arrayA = readline();
  const arrayB = readline();

  console.log(helper(choosenNumbers[0], arrayA, arrayB) ? 'YES' : 'NO')
}

function helper(choosenNumbersFromA, arrayA, arrayB) {
  return arrayA[choosenNumbersFromA - 1] < arrayB[0]
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const lengths = readline();
  const choosenNumbers = readline();
  const arrayA = readline();
  const arrayB = readline();

  console.log(helper(parseInt(choosenNumbers.split(' ')[0]), parseInt(choosenNumbers.split(' ')[1]), arrayA.split(' '), arrayB.split(' ')) ? 'YES' : 'NO')
}

function helper(choosenNumbersFromA, choosenNumbersFromB, arrayA, arrayB) {
  return arrayA[choosenNumbersFromA - 1] < arrayB[arrayB.length - choosenNumbersFromB - 1]
}

var data = readline().split(' ');
var Na = data[0];
var MasA=[];
var MasB=[];
var Nb = data[1];
var data = readline().split(' ');
var k = data[0]-1;
var m = data[1]-1;
var data = readline().split(' ');
for (i=0;i<Na;i++){
	MasA[i]=data[i];
}
var data = readline().split(' ');
for (i=0;i<Nb;i++){
	MasB[i]=data[i];
}
var result = "YES"
if (MasA[k]>=MasB[MasB.length-Nb]){
	result = "NO";
}
write(result);

var data = readline().split(' ');
var Na = data[0];
var MasA=[];
var MasB=[];
var Nb = data[1];
var data = readline().split(' ');
var k = data[0];
var m = data[1];
var data = readline().split(' ');
for (i=0;i<Na;i++){
	MasA[i]=data[i];
}
var data = readline().split(' ');
for (i=0;i<Nb;i++){
	MasB[i]=data[i];
}
var result = "YES"
if (MasA[k-1]>=MasB[MasB.length-m]){
	result = "NO";
}
//write(MasA[k-1]+" ");
//write(MasB[MasB.length-m]+ " ");
write(result);

function getInputs() {
    return readline().split(' ').map(function(x) { return parseInt(x) });
}

var inputs = getInputs();

var sizeA = inputs[0];
var sizeB = inputs[1];

var limits = getInputs();

var k = limits[0];
var m = limits[1];

var A = getInputs();
var B = getInputs();

var first = A.slice(0, k);
var second = B.slice(-m);

var answer = 'YES';

for (var i = 0; i < k; i++) {
    var item = first[i];

    var isLess = false;

    for (var j = 0; j < m; j++) {

        if (item < second[j]) {
            isLess = true;
            break;
        }
    }

    if (!isLess) {
        answer = 'NO';
        break;
    }
}

print(answer);

function getInputs() {
    return readline().split(' ').map(function(x) { return parseInt(x) });
}

var inputs = getInputs();

var sizeA = inputs[0];
var sizeB = inputs[1];

var limits = getInputs();

var k = limits[0];
var m = limits[1];

var A = getInputs();
var B = getInputs();

var first = A.slice(k);
var second = B.slice(-m);

var answer = 'YES';

for (var i = 0; i < k; i++) {
    var item = first[i];

    var isLess = false;

    for (var j = 0; j < m; j++) {

        if (item < second[j]) {
            isLess = true;
            break;
        }
    }

    if (!isLess) {
        answer = 'NO';
        break;
    }
}

print(answer);