'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let counts = Array(20).fill(0)
    readline().split(' ').map(x => {
        counts[Math.log2(x)] += 1
    })
    let ans = [m],
        maxNum = 0,
        index = 0
    // console.log('Counts = ', counts)
    while (n) {
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(counts, ans[ans.length - 1])
        maxNum = Math.pow(2, index)
        if (index == -1) {
            index = findGoodIndex(counts, m)
            maxNum = Math.pow(2, index)
            ans.push(m - maxNum)
        } else {
            ans[ans.length - 1] -= maxNum
        }
        counts[index]--
        n--
    }
    console.log(ans.length)
}

function sortAscending(a, b) {
    return a - b
}

function findGoodIndex(counts, leftOver) {
    let index = 20
    while (index >= 0) {
        if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {
            return index
        } else {
            index--
        }
    }
    return index
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
		this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
		const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
		const left = i => (i << 1) + 1;
		const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		const cnt = Array(20).fill(0);
		for (let i = 0; i < n; i++) {
			cnt[Math.log2(w[i])]++;
		}

		let ans = 0, placed = 0;
		w.sort((x, y) => y - x);
		while (placed < n) {
			++ans;
			let avl = W;
			while(1) {
				let j;
				for (j = 20; j >= 0; j--) {
					if (cnt[j] && 2**j <= avl) break;
				}
				if (j >= 0) avl -= 2**j, cnt[j]--, placed++; else break;
			}
		}

		console.log(ans);
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
		this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
		const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
		const left = i => (i << 1) + 1;
		const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		let ans = 0;
		const mxq = new PriorityQueue((a, b) => a > b);
		w.sort((x, y) => y-x);
		for (let i = 0; i < n; i++) {
			const avl = mxq.peek();
			if (avl >= w[i]) {
				mxq.pop();
				mxq.push(avl-w[i]);
			} else {
				mxq.push(W-w[i]);
				ans++;
			}
		}

		console.log(ans);
	}
}

'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 x = readline();
  var toPrint = ''

  Array(Number(x)).fill(1).map((t, i) => {
    // const a = parseInt(readline());
    var [n, w] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    var b = new Array(1001).fill(0)
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // console.log(a)
    for (let j = 0; j < n; j++) {
      var count = 0
      while (a[j] > 1) {
        a[j] = Math.floor(a[j] / 2)
        count++
      }
      b[count] = b[count] + 1
    }

    var res = 0
    while (true) {
      var sum = w
      for (let j = b.length - 1; j >= 0; j--) {
        if (b[j] === 0) continue
        var val = Math.pow(2, j)
        var x = Math.floor(sum / val)
        var take = Math.min(b[j], x)
        b[j] = b[j] - take
        sum = sum - take * val
      }
      if (sum === w) break
      res++
    }
    toPrint = toPrint + res + '\n'
  })
  console.log(toPrint)

  // var b = a.sort((a, b) => Math.abs(a) - Math.abs(b))

}

function SUMnUMBER(x, y) {
  return Math.log(y) / Math.log(x);
}

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mi = Math.min;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, w, a) => {
    a.sort((x, y) => x - y);
    let uc = uniqcount(a);
    let h = 0;
    while (1) {
        let end = 1;
        for (const e of uc) {
            if (e[1] != 0) end = 0;
        }
        if (end) break;
        h++;
        let rem = w;
        for (let i = uc.length - 1; ~i; i--) {
            let w = uc[i][0];
            let use = mi(rem / w >> 0, uc[i][1]);
            rem -= use * w;
            uc[i][1] -= use;
        }
    }
    pr(h);
};

const uniqcount = (a) => {
    let n = a.length;
    let p = 0;
    let b = Array(n).fill(null);
    for (let i = 0; i < n; i++) {
        if (i == 0 || a[i] != a[i - 1]) b[p++] = [a[i], 0];
        b[p - 1][1]++;
    }
    return b.slice(0, p);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let counts = Array(20).fill(0)
    readline().split(' ').map(x => {
        counts[Math.log2(x)] += 1
    })
    let ans = [m],
        maxNum = 0,
        index = 0
    // console.log('Counts = ', counts)
    while (n) {
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(counts, ans[ans.length - 1])
        maxNum = Math.pow(2, index)
        if (index == -1) {
            maxNum = Math.pow(2, findGoodIndex(counts, m))
            ans.push(m - maxNum)
        } else {
            ans[ans.length - 1] -= maxNum
        }
        counts[index]--
        n--
    }
    console.log(ans.length)
}

function sortAscending(a, b) {
    return a - b
}

function findGoodIndex(counts, leftOver) {
    let index = 20
    while (index >= 0) {
        if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {
            return index
        } else {
            index--
        }
    }
    return index
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let counts = Array(20).fill(0)
    readline().split(' ').map(x => {
        counts[Math.log2(x)] += 1
    })
    let ans = [m],
        maxNum = 0,
        index = 0
    // console.log('Counts = ', counts)
    while (n) {
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(counts, ans[ans.length - 1])
        maxNum = Math.pow(2, index)
        if (index == -1) {
            ans.push(m - maxNum)
        } else {
            ans[ans.length - 1] -= maxNum
        }
        counts[index]--
        n--
    }
    console.log(ans.length)
}

function sortAscending(a, b) {
    return a - b
}

function findGoodIndex(counts, leftOver) {
    let index = 20
    while (index >= 0) {
        if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {
            return index
        } else {
            index--
        }
    }
    return index
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let counts = Array(20).fill(0)
    readline().split(' ').map(x => {
        counts[Math.log2(x)] += 1
    })
    let ans = [m],
        maxNum = 0,
        index = 0
    console.log('Counts = ', counts)
    while (n) {
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(counts, ans[ans.length - 1])
        maxNum = Math.pow(2, index)
        if (index == -1) {
            ans.push(m - maxNum)
        } else {
            ans[ans.length - 1] -= maxNum
        }
        counts[index]--
        n--
    }
    console.log(ans.length)
}

function sortAscending(a, b) {
    return a - b
}

function findGoodIndex(counts, leftOver) {
    let index = 20
    while (index >= 0) {
        if (counts[index] > 0 && Math.pow(2, index) <= leftOver) {
            return index
        } else {
            index--
        }
    }
    return index
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let arr = readline().split(' ').map(x => +x)
    let ans = [],
        maxNum = 0,
        index = 0
    arr.sort(sortAscend)
    console.log('arr = ', ...arr)
    while (arr.length) {
        // find current max in arr => always the last
        maxNum = arr[arr.length - 1]
        // console.log('maxNum = ', maxNum)
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(maxNum, ans, m)
        if (index == ans.length) {
            ans.push(m - maxNum)
        } else {
            ans[index] -= maxNum
        }
        // console.log('ans = ', ans)
        arr.pop()
    }
    console.log(ans.length)
}

function sortAscend(a, b) {
    return a - b
}

function findGoodIndex(maxNum, arr, m) {
    let index = 0
    while (index < arr.length) {
        if (arr[index] >= maxNum) {
            return index
        }
        index++
    }
    return index
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main()
});

function readline() {
    return inputString[currentLine++]
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    let testCases = readline()
    while (testCases--)
        solve()
}

// function to solve problems
function solve() {
    let [n, m] = readline().split(' ')
    let arr = readline().split(' ').map(x => +x)
    let ans = [],
        maxNum = 0,
        index = 0
    arr.sort()
    while (arr.length) {
        // find current max in arr - always the last
        maxNum = arr[arr.length - 1]
        // better approach would be to store the maximum in order in the best possible way
        // greedy approach
        index = findGoodIndex(maxNum, ans, m)
        if (index == ans.length) {
            ans.push(m - maxNum)
        } else {
            ans[index] -= maxNum
        }
        arr.pop()
    }
    console.log(ans.length)
}

function findGoodIndex(maxNum, arr, m) {
    let index = 0
    while (index < arr.length) {
        if (arr[index] >= maxNum) {
            return index
        }
        index++
    }
    return index
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
	    this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
	    const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
	    const left = i => (i << 1) + 1;
	    const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

const mxq = new PriorityQueue((a, b) => a > b);

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		w.sort((x, y) => y-x);

		let ans = 0;
		for (let i = 0; i < n; i++) {
			const avl = mxq.peek();
			if (avl >= w[i]) {
				avl && mxq.pop();
				mxq.push(avl-w[i]);
			} else {
				mxq.push(W-w[i]);
				ans++;
			}
		}
		console.log(ans);
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
	    this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
	    const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
	    const left = i => (i << 1) + 1;
	    const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

const mxq = new PriorityQueue((a, b) => a > b);

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		w.sort((x, y) => y-x);

		let ans = 0;
		for (let i = 0; i < n; i++) {
			const avl = mxq.peek();
			if (avl >= w[i]) {
				mxq.pop();
				mxq.push(avl-w[i]);
			} else {
				mxq.push(W-w[i]);
				ans++;
			}
		}
		console.log(ans);
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

// PriorityQueue implementated using array based binary heap
// PriorityQueue methods
//  push(...values)
// 	peek()
//  pop()
//  size()
//  replace(value)

class PriorityQueue {

	constructor(comparator = (a, b) => a > b) {
	    this.top = 0;
		this._heap = [];
		this._comparator = comparator;
	}
	size() {
		return this._heap.length;
	}
	isEmpty() {
		return this.size() == 0;
	}
	peek() {
		return this._heap[this.top];
	}
	push(...values) {
		values.forEach(value => {
				this._heap.push(value);
				this._siftUp();
				});
		return this.size();
	}
	pop() {
		const poppedValue = this.peek();
		const bottom = this.size() - 1;
		if (bottom > this.top) {
			this._swap(this.top, bottom);
		}
		this._heap.pop();
		this._siftDown();
		return poppedValue;
	}
	replace(value) {
		const replacedValue = this.peek();
		this._heap[this.top] = value;
		this._siftDown();
		return replacedValue;
	}
	_greater(i, j) {
		return this._comparator(this._heap[i], this._heap[j]);
	}
	_swap(i, j) {
		[this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
	}
	_siftUp() {
	    const parent = i => ((i + 1) >>> 1) - 1;
		let node = this.size() - 1;
		while (node > this.top && this._greater(node, parent(node))) {
			this._swap(node, parent(node));
			node = parent(node);
		}
	}
	_siftDown() {
	    const left = i => (i << 1) + 1;
	    const right = i => (i + 1) << 1;
		let node = this.top;
		while (
				(left(node) < this.size() && this._greater(left(node), node)) ||
				(right(node) < this.size() && this._greater(right(node), node))
			  ) {
			let maxChild = (right(node) < this.size() && this._greater(right(node), left(node))) ? right(node) : left(node);
			this._swap(node, maxChild);
			node = maxChild;
		}
	}
}

const mxq = new PriorityQueue((a, b) => a > b);

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		w.sort((x, y) => y-x);

		let ans = 0;
		for (let i = 0; i < n; i++) {
			const avl = mxq.pop();
			if (avl >= w[i]) {
				mxq.push(avl-w[i]);
			} else {
				mxq.push(W-w[i]);
				ans++;
			}
		}
		console.log(ans);
	}
}

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

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

function pow (b, i) {
	if (!i) return 1;
	return b * pow(b, i - 1);
}

function indx (n) {
	for (let i = 0; i <= 30; i++) {
		const pw = 1 << i;
		if (n & pw) return i;
	}
}

function main () {
	let T = rn();
	while (T--) {
		const [n, W] = rna();
		const w = rna();

		w.sort((x, y) => y - x);

		const used = Array(31).fill(-1);
		for (let i = 0; i <= 30; i++) {
			const pw = 1 << i;
			if (W & pw) {
				used[i] = 0;
			}
		}

		for (let i = 0; i < n; i++) {
			let b = indx(w[i]);
			let done = false;
			for (let j = 30; j >= 0; j--) {
				if (used[j] >= 0) {
					if (w[i] <= used[j] % pow(2, j)) {
						used[j] += w[i];
						done = true;
						break;
					}
				}
			}
			if (!done) {
				if (used[b] >= 0) {
					used[b] += w[i];
				} else {
					for (let j = 30; j >= 0; j--) {
						if (used[j] >= 0) {
							used[j] += w[i];
							break;
						}
					}
				}
			}
		}

		let ans = 0;
		for (let i = 0; i <= 30; i++) {
			ans = Math.max(ans, Math.ceil(used[i] / pow(2, i)));
		}

		console.log(ans);
	}
}

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mx = Math.max;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, w, a) => {
    let m = new Map();
    for (const e of a) m.set(e, m.get(e) + 1 || 1);
    let max = mx.apply(Math, a);
    pr(m.get(max))
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, w, a) => {
    let sum = a.reduce((x, y) => x + y);
    pr(ce(sum / w))
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i + 1]);
            i += 2;
        }
    });
};

main()


function solve() {
   const n = Number(read());
   const a = readArray(Number);
   const b = [];
   const odd = (n & 1);
   for (let i = 0; i < n - odd; i++) {
      if (i & 1) {
         b.push(-a[i - 1]);
         continue;
      }
      b.push(a[i + 1]);
   }
   if (odd) {
      const end = [n - 3, n - 2, n - 1];
      while(a[end[0]] + a[end[1]] === 0) {
         end.push(end.shift());
      }
      b[end[0]] = a[end[2]];
      b[end[1]] = a[end[2]];
      b[end[2]] = - a[end[0]] - a[end[1]];
   }
   write(b.join(' '));
}

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

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i+=2) {
			b.push(a[i+1], -a[i]);
		}

		if (n&1) {
			const c = a.slice(-3);
			if (c[0] + c[1] != 0 && b.length < n) b.push(c[2], c[2], -(c[0]+c[1]));
			if (c[0] + c[2] != 0 && b.length < n) b.push(c[1], -(c[0]+c[2]), c[1]);
			if (c[1] + c[2] != 0 && b.length < n) b.push(-(c[1]+c[2]), c[0], c[0]);
		}

		console.log(b.join(' '));
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function rotateLeft (ar, k) {
	while (k--) ar.push(ar.shift());
}

function rotateRight (ar, k) {
	while (k--) ar.unshift(ar.pop());
}

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i++) {
			if (i&1) {
				b.push(-a[i-1])
			} else {
				b.push(a[i+1]);
			}
		}

		if (n&1) {
			const c = a.slice(-3);
			for (let i = 0; i < 3; i++) {
				if (c[0] + c[1] != 0) {
					const res = [c[2], c[2], -(c[0]+c[1])];
					rotateRight(res, i);
					b.push(...res);
					break;
				}
				rotateLeft(c, 1);
			}
		}

		console.log(b.join(' '));
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i++) {
			if (i&1) {
				b.push(-a[i-1])
			} else {
				b.push(a[i+1]);
			}
		}

		if (n&1) {
			let x = a[n-3], y = a[n-2], z = a[n-1], flg;
			if (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {
				b.push(x > 0 ? 1 : -1);
				b.push(y > 0 ? 1 : -1);
				b.push(z > 0 ? -2 : 2);
			} else {
				if (Math.abs(x) == Math.abs(y)) [y, z] = [z, y], flg = 1;
				if (x * y < 0) {
					b.push(z, z, -(x + y));
				} else {
					b.push(z, -z, -(x - y));
				}
				if (flg) b.push(b.pop(), b.pop());
			}
		}

		console.log(b.join(' '));
	}
}

'use strict';

function solve(n, a) {
  if (n === 2) return `${a[1]} ${-a[0]}`;
  const res = [];
  for (let i = 0; i < n - 1; i += 2) {
    res[i] = a[i + 1];
    res[i + 1] = -a[i];
  }
  if (n % 2 === 0) return res.join(' ');
  const [x, y, z] = a.slice(-3);
  if (x + y === 0) {
    res[n - 3] = z;
    res[n - 2] = 2 * z;
    res[n - 1] = -(x + 2 * y);
  } else {
    res[n - 3] = z;
    res[n - 2] = z;
    res[n - 1] = -(x + y);
  }
  return res.join(' ');
}

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

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

const readline = require('readline')

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

function solve(n, arr) {
    const ans = []
    const limit = (n & 1) ? n - 3 : n
    for (let i = 0; i < limit; i += 2) {
        ans[i] = -arr[i + 1]
        ans[i + 1] = arr[i]
    }
    if (n & 1) {
        const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])
        return ans.concat(rest).join(' ')
    } else {
        return ans.join(' ')
    }
}
function helper(a, b, c) {
    if (a === b && b === c) {
        return [1, 1, -2]
    } else if (a === b) {
        // return [c, c, 2 * a]
        if (c & 1) {
            if (c === 1) {
                return [-1, 2, -a]
            } else if (c === -1) {
                return [-2, 1, -a]
            }
            return [(c - 1) / 2, (c + 1) / 2, -a]
        } else {
            return [c / 2, c / 2, -a]
        }
    } else if (b === c) {
        if (a & 1) {
            if (a === 1) {
                return [-b, -1, 2]
            } else if (a === -1) {
                return [-b, -2, 1]
            }
            return [-b, (a - 1) / 2, (a + 1) / 2]
        } else {
            return [-b, a / 2, a / 2]
        }
    } else if (a === c) {
        if (b & 1) {
            if (b === 1) {
                return [-1, -a, 2]
            } else if (b === -1) {
                return [-2, -a, 1]
            }
            return [(b - 1) / 2, -a, (b + 1) / 2]
        } else {
            return [b / 2, -a, b / 2]
        }
    }
    let d
    d = a - b
    if (Math.abs(d) < 1e4) {
        return [c, -c, -d]
    }
    d = a - c
    if (Math.abs(d) < 1e4) {
        return [b, -d, -b]
    }
    d = b - c
    return [-d, a, -a]
}

function solve() {
   const n = Number(read());
   const a = readArray(Number);
   const b = [];
   const odd = (n & 1);
   for (let i = 0; i < n - odd; i++) {
      if (i & 1) {
         b.push(-a[i - 1]);
         continue;
      }
      b.push(a[i + 1]);
   }
   if (odd) {
      b[n - 3] = a[n - 1];
      b[n - 2] = a[n - 1];
      b[n - 1] = -a[n - 2] - a[n - 3];
   }
   write(b.join(' '));
}

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

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = 0;
   let minAbsIndex = -1;
   let jopa = 0;
   const a = readArray((value, index) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      const curJopa = pDivCount(curAbsA);
      if (curJopa > jopa) {
         jopa = curJopa;
         minAbsA = curA;
         minAbsIndex = index;
      }
      return curA;
   });
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
   /*let xxx = 0;
   for (let i = 0; i < n; i++) {
      xxx += Math.abs(b[i]);
   }
   write(xxx);*/
}

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

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = 0;
   let minAbsIndex = -1;
   let jopa = 0;
   const a = readArray((value, index) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      const curJopa = pDivCount(curAbsA);
      if (curJopa > jopa || curJopa === jopa && curAbsA < minAbsA) {
         jopa = curJopa;
         minAbsA = curA;
         minAbsIndex = index;
      }
      return curA;
   });
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
   /*let xxx = 0;
   for (let i = 0; i < n; i++) {
      xxx += Math.abs(b[i]);
   }
   write(xxx);*/
}

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

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      if (n % i !== 0) {
         continue;
      }
      ans++;
      while(n % i === 0) {
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = 0;
   let minAbsIndex = -1;
   const a = readArray((value, index) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      if (curAbsA > minAbsA) {
         minAbsA = curA;
         minAbsIndex = index;
      }
      return curA;
   });
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
   /*let xxx = 0;
   for (let i = 0; i < n; i++) {
      xxx += a[i] * b[i];
   }
   write(xxx);*/
}

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

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = Infinity;
   let minAbsIndex = -1;
   let glcm = 1;
   const a = readArray((value) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      glcm = lcm(glcm, curAbsA);
      return curA;
   });
   for (let i = 0; i < n; i++) {
      const x = Math.floor(glcm / Math.abs(a[i]));
      if (x < minAbsA) {
         minAbsA = x;
         minAbsIndex = i;
      }
   }
   minAbsA = Math.abs(a[minAbsIndex]);
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
   /*let xxx = 0;
   for (let i = 0; i < n; i++) {
      xxx += a[i] * b[i];
   }
   write(xxx);*/
}

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

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = Infinity;
   let minAbsIndex = -1;
   let glcm = 1;
   const a = readArray((value) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      glcm = lcm(glcm, curAbsA);
      return curA;
   });
   for (let i = 0; i < n; i++) {
      const x = Math.floor(glcm / Math.abs(a[i]));
      if (x < minAbsA) {
         minAbsA = x;
         minAbsIndex = i;
      }
   }
   minAbsA = Math.abs(a[minAbsIndex]);
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
   let xxx = 0;
   for (let i = 0; i < n; i++) {
      xxx += Math.abs(b[i]);
   }
   write(xxx);
}

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

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

const acode = 'a'.charCodeAt(0);
const zcode = 'z'.charCodeAt(0);

function solve() {
   const n = Number(read());
   let minAbsA = Infinity;
   let minAbsIndex = -1;
   const a = readArray((value, index) => {
      const curA = Number(value);
      const curAbsA = Math.abs(curA);
      if (curAbsA < minAbsA) {
         minAbsA = curA;
         minAbsIndex = index;
      }
      return curA;
   });
   const b = [];
   let sum = 0;
   for (let i = 0; i < n; i++) {
      if (i === minAbsIndex) {
         continue;
      }
      const x = lcm(Math.abs(a[i]), minAbsA);
      sum += x;
      b[i] = Math.floor(x / a[i]);
   }
   b[minAbsIndex] = - Math.floor(sum / a[minAbsIndex]);
   write(b.join(' '));
}

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

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

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

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

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

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

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i++) {
			if (i&1) {
				b.push(-a[i-1])
			} else {
				b.push(a[i+1]);
			}
		}

		if (n&1) {
			let x = a[n-3], y = a[n-2], z = a[n-3];
			if (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {
				if (x > 0) b.push(1); else b.push(-1);
				if (y > 0) b.push(1); else b.push(-1);
				if (z > 0) b.push(-2); else b.push(2);
			} else if (Math.abs(x) == Math.abs(y)) {
				if (x * z < 0) {
					b.push(y, -(x + z), y);
				} else {
					b.push(y, -(x - z), -y);
				}
			} else {
				if (x * y < 0) {
					b.push(z, z, -(x + y));
				} else {
					b.push(z, -z, -(x - y));
				}
			}
		}

		console.log(b.join(' '));
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i++) {
			if (i&1) {
				b.push(-a[i-1])
			} else {
				b.push(a[i+1]);
			}
		}

		if (n&1) {
			let x = a[n-3], y = a[n-2], z = a[n-3];
			if (Math.abs(x) == Math.abs(y) && Math.abs(y) == Math.abs(z)) {
				if (x > 0) b.push(1); else b.push(-1);
				if (y > 0) b.push(1); else b.push(-1);
				if (z > 0) b.push(-2); else b.push(2);
			} else if (Math.abs(x) == Math.abs(y)) {
				if (a[n-3] * a[n-1] < 0) {
					b.push(a[n-2], a[n-2], -(a[n-3] + a[n-1]));
				} else {
					b.push(a[n-2], -a[n-2], -(a[n-3] - a[n-1]));
				}

			} else {
				if (a[n-3] * a[n-2] < 0) {
					b.push(a[n-1], a[n-1], -(a[n-3] + a[n-2]));
				} else {
					b.push(a[n-1], -a[n-1], -(a[n-3] - a[n-2]));
				}
			}
		}

		console.log(b.join(' '));
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const b = [];
		for (let i = 0; i < (n&1 ? n-3 : n); i++) {
			if (i&1) {
				b.push(-a[i-1])
			} else {
				b.push(a[i+1]);
			}
		}

		if (n&1) {
			// a[n-3], a[n-2], a[n-1]
			if (a[n-3] * a[n-2] < 0) {
				b.push(a[n-1], a[n-1], -(a[n-3] + a[n-2]));
			} else {
				b.push(a[n-1], -a[n-1], -(a[n-3] - a[n-2]));
			}
		}

		console.log(b.join(' '));
	}
}

'use strict';

function solve(n, a) {
  if (n === 2) return `${a[1]} ${-a[0]}`;
  const res = [];
  for (let i = 0; i < n - 3; i += 2) {
    res[i] = a[i + 1];
    res[i + 1] = -a[i];
  }
  const [x, y, z] = a.slice(-3);
  if (x + y === 0) {
    res[n - 3] = z;
    res[n - 2] = 2 * z;
    res[n - 1] = -(x + 2 * y);
  } else {
    res[n - 3] = z;
    res[n - 2] = z;
    res[n - 1] = -(x + y);
  }
  return res.join(' ');
}

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

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

'use strict';

function solve(n, a) {
  let sum = 0,
      res = new Array(n),
      last = a[a.length - 1];
  for (let i = 0; i < n - 1; i++) {
    let flag = a[i] < 0 ? -1 : 1;
    if (sum < 0) {
      sum += flag * a[i];
      res[i] = flag * last;
    } else {
      sum += -1 * flag * a[i];
      res[i] = -flag * last;
    }
  }
  res[n - 1] = -sum;
  return res.join(' ');
}

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

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

const readline = require('readline')

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

function solve(n, arr) {
    const ans = []
    const limit = (n & 1) ? n - 3 : n
    for (let i = 0; i < limit; i += 2) {
        ans[i] = -arr[i + 1]
        ans[i + 1] = arr[i]
    }
    if (n & 1) {
        const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])
        return ans.concat(rest).join(' ')
    } else {
        return ans.join(' ')
    }
}
function helper(a, b, c) {
    if (a === b && b === c) {
        return [1, 1, -2]
    } else if (a === b) {
        // return [c, c, 2 * a]
        if (c & 1) {
            return [(c - 1) / 2, (c + 1) / 2, -a]
        } else {
            return [c / 2, c / 2, -a]
        }
    } else if (b === c) {
        if (a & 1) {
            return [-b, (a - 1) / 2, (a + 1) / 2]
        } else {
            return [-b, a / 2, a / 2]
        }
    } else if (a === c) {
        if (b & 1) {
            return [(b - 1) / 2, -a, (b + 1) / 2]
        } else {
            return [b / 2, -a, b / 2]
        }
    }
    let d
    d = a - b
    if (Math.abs(d) < 1e4) {
        return [c, -c, -d]
    }
    d = a - c
    if (Math.abs(d) < 1e4) {
        return [b, -d, -b]
    }
    d = b - c
    return [-d, a, -a]
}

const readline = require('readline')

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

function solve(n, arr) {
    const ans = []
    const limit = (n & 1) ? n - 3 : n
    for (let i = 0; i < limit; i += 2) {
        ans[i] = -arr[i + 1]
        ans[i + 1] = arr[i]
    }
    if (n & 1) {
        const rest = helper(arr[limit], arr[limit + 1], arr[limit + 2])
        return ans.concat(rest).join(' ')
    } else {
        return ans.join(' ')
    }
}
function helper(a, b, c) {
    let d
    d = a - b
    if (Math.abs(d) < 1e4) {
        return [c, -c, -d]
    }
    d = a - c
    if (Math.abs(d) < 1e4) {
        return [b, -d, -b]
    }
    d = b - c
    return [-d, a, -a]
}


/**
 * Created by artyom.
 */

len = readline();
a = readline().split(' ').map(function (v) {
    return parseInt(v);
});

function calcRight(start) {
    var pos = start + 1;
    while (pos <= len && a[pos] <= a[pos - 1]) {
        pos++;
    }
    return pos - start;
}

b = [calcRight(0)];
r = [b[0]];
for (var i = 1; i < len; i++) {
    if (a[i] > a[i - 1]) {
        r[i] = calcRight(i);
        b[i] = r[i] + b[i - 1];
    } else {
        r[i] = r[i - 1] - 1;
        b[i] = a[i] < a[i - 1] ? r[i] : b[i - 1];
    }
}

print(Math.max.apply(Math, b));

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var n=parseInt(readline());

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

var max=0;
for(var i=0;i<arr.length;i++){
    var count=1;
      for(var j=i;j<arr.length;j++){
         if(arr[j+1]!=undefined){
              if(arr[j+1]<=arr[j]){
               count++;
              }else{
                  break;
              }

         }

         max=Math.max(max,count);
      }
      for(var k=i;k>=0;k--){
        if(k-1>=0){
        if(arr[k-1]<=arr[k]){
            count++;
           }else{
               break;
           }

        }

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

}
print(max);

var inputLength = readline()
var input = readline().split(" ").map(x => parseInt(x)); // num will be an array [1,2,3]

var maxSections = 0, currentSections, pointer;
for (var i = 0; i < inputLength; i++) {
  currentSections = 0;
  for (pointer = i; pointer > 0; pointer--) {
    if (input[pointer - 1] > input[pointer]) {
      break;
    }
    currentSections++;
  }
  for (pointer = i; pointer < inputLength - 1; pointer++) {
    if (input[pointer + 1] > input[pointer]) {
      break;
    }
    currentSections++;
  }
  if (currentSections > maxSections) {
    maxSections = currentSections;
  }
}
print(maxSections + 1)

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const hs = ipt.split(EOL)[1].split(' ').map(v => parseInt(v))
  let c = 1
  let b = 1
  let i = 0
  while (i < hs.length) {
    for (let k = i - 1; k >= 0; k--) {
      if (hs[k] <= hs[k + 1]) c++
      else break
    }
    i++
    for (; i < hs.length; i++) {
      if (hs[i] <= hs[i - 1]) c++
      else break
    }
    if (c > b) b = c
    c = 1
  }
  console.log(b)
})

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var n=parseInt(readline());

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

var max=0;
for(var i=0;i<arr.length;i++){
    var count=1;
    var c=i;
      for(var j=i+1;j<arr.length;j++){

              if(arr[j]<=arr[c]){
               count++;
              }else{
                  break;
              }
             c++;

      }
       c=i;
      for(var k=i-1;k>=0;k--){

        if(arr[k]<=arr[c]){
            count++;
           }else{
               break;
           }
         c--;

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

}
print(max)

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const hs = ipt.split(EOL)[1].split(' ').map(v => parseInt(v))
  let c = 1
  let b = 1
  let i = 0
  while (i < hs.length) {
    for (let k = i - 1; k >= 0; k--) {
      if (hs[k] < hs[k + 1]) c++
      else break
    }
    i++
    for (; i < hs.length; i++) {
      if (hs[i] < hs[i - 1]) c++
      else break
    }
    if (c > b) b = c
    c = 1
  }
  console.log(b)
})

/**
 * Created by artyom.
 */

n = readline();
a = readline().split(' ');
len = a.length;

function calcRight(start) {
    var pos = start + 1;
    while (pos <= len && a[pos] <= a[pos - 1]) {
        pos++;
    }
    return pos - start;
}

b = [calcRight(0)];
r = [b[0]];
for (var i = 1; i < len; i++) {
    if (a[i] > a[i - 1]) {
        r[i] = calcRight(i);
        b[i] = r[i] + b[i - 1];
    } else {
        r[i] = r[i - 1] - 1;
        b[i] = r[i];
    }
}
print(Math.max.apply(Math, b));

/**
 * Created by artyom.
 */

n = readline();
a = readline().split(' ');
len = a.length;

function calcRight(start) {
    var pos = start + 1;
    while (pos <= len && a[pos] <= a[pos - 1]) {
        pos++;
    }
    return pos - start;
}

b = [calcRight(0)];
r = [b[0]];
for (var i = 1; i < len; i++) {
    if (a[i] > a[i - 1]) {
        r[i] = calcRight(i);
        b[i] = r[i] + b[i - 1];
    } else {
        r[i] = r[i - 1] - 1;
        b[i] = a[i] < a[i - 1] ? r[i] : b[i - 1];
    }
}
print(Math.max.apply(Math, b));

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var n=parseInt(readline());

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

var max=0;
for(var i=0;i<arr.length;i++){
    var count=1;
      for(var j=i+1;j<arr.length;j++){

              if(arr[j+1]<=arr[j]){
               count++;
              }else{
                  break;
              }

    }

         max=Math.max(max,count);

      for(var k=i-1;k>=0;k--){

        if(arr[k-1]<=arr[k]){
            count++;
           }else{
               break;
           }

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

}
print(max);


(function() {
    var read = {
        number: function() {
            return +readline();
        },
        arr: function(divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function(divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var line = read.arrNumber(' ');
    var n = line[0];
    var m = line[1];
    var h = line[2];

    var ms = read.arrNumber(' ');
    var ns = read.arrNumber(' ');

    var res;
    for(var i = 0; i < n; i++) {
        line = read.arrNumber(' ');
        res = [];
        line.forEach(function (count, index) {
           res[index] = count
               ? (ms[index] > ns[i] ? ns[i] : ms[index])
               : 0
        });
        print(res.join(' '));
    }

}());

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function readLines(cb) {
    const lines = [];
    let read;
    rl.on('line', function(line) {
        if (!read) {
            const first = line.split(' ').map(x=>parseInt(x));
            read = first[0] +2;
        } else {
            lines.push(line);
        }
        if (lines.length === read) {
            rl.close();
            cb(lines);
        }
    });
};
readLines(doIt);

function doIt(lines) {
    const frontView = lines[0].split(' ').map(x=>parseInt(x));
    const leftView = lines[1].split(' ').map(x=>parseInt(x));
    const matrix = lines.slice(2).map(line => line.split(' ').map(x=>parseInt(x)));

    for (let row = 0; row < leftView.length; row++) {
        const aRow = [];
        for (let col = 0; col < frontView.length;col++) {
            if (matrix[row][col] === 0)
                aRow.push(0);
            else {
                aRow.push(Math.min(frontView[col], leftView[row]));;
            }
        }
        console.log(aRow.join(' '));
    }
}

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

function sol() {
  const [meta, front, left, ...top] = input
    .split('\n')
    .map(line => line.split(' ').map(Number));

  const [n, m, h] = meta;
  const result = [];
  for (let k = 0; k < n; ++k)
    result.push(Array(m).fill(0));

  // front: 0 .. m-1
  // fill all columns with maximum value
  for (let i = 0; i < m; ++i) {
    for (let j = 0; j < n; ++j) {
      if (top[j][i] === 0) continue;
      result[j][i] = front[i];
    }
  }

  // left: 0 .. n-1
  for (let j = 0; j < n; ++j) {
    for (let i = 0; i < m; ++i) {
      if (top[j][i] === 0) continue;
      if (result[j][i] > left[j]) {
        result[j][i] = left[j];
      }
    }
  }

  process.stdout.write(
    result.map(line => line.join(' ')).join('\n'),
    'utf8',
    () => process.stdout.end()
  );
}


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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var treeNum = integers[0], delta = integers[1];
	var trees = tokenizeIntegers(readline());
	var bestCost = treeNum, bestActions;
		maxStartingHeight = 1000;

	for (var start = 1; start <= maxStartingHeight; ++start) {
		var height = start, cost = 0;
		var actions = [];
		for (var i = 0; i < treeNum; ++i) {
			if (trees[i] != height) {
				cost += 1;
				actions.push([height < trees[i] ? "-" : "+",
						i+1, Math.abs(height-trees[i])].join(" "));
			}
			height += delta;
		}
		if (cost < bestCost) {
			bestCost = cost;
			bestActions = actions;
		}
	}

	print(bestCost);
	if (bestCost > 0) {
		print(bestActions.join("\n"));
	}
}

main();

print(function(n, k) {
	var a = readline().split(' ').map(Number);
	var min = 1e6;
	var s = 0;
	for (var i = 1; i <= 1000; i++) {
		var x = 0;
		for (var j = 0; j < n; j++) {
			if (a[j] !== i + j * k) {
				x++;
			}
		}
		if (x < min) {
			min = x;
			s = i
		}
	}
	var ans = [];
	for (var i = 0; i < n; i++) {
		var x = s + i * k - a[i];
		if (x > 0) {
			ans.push('+ ' + (i + 1) + ' ' + x);
		} else if (x < 0) {
			ans.push('- ' + (i + 1) + ' ' + (-x));
		}
	}

	return ans.length == 0 ? ans.length : ans.length + '\n' + ans.join('\n')
}.apply(0, readline().split(' ').map(Number)));

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var treeNum = integers[0], delta = integers[1];
	var trees = tokenizeIntegers(readline());
	var bestCost = treeNum, bestActions;
		maxStartingHeight = 1000;

	for (var start = 1; start <= maxStartingHeight; ++start) {
		var current = start, cost = 0;
		var actions = [];
		for (var i = 0; i < treeNum; ++i) {
			if (trees[i] != current) {
				cost += 1;
				actions.push([current < trees[i] ? "-" : "+",
						i+1, Math.abs(current-trees[i])].join(" "));
			}
			current += delta;
		}
		if (cost < bestCost) {
			bestCost = cost;
			bestActions = actions;
		}
	}

	print(bestCost);
	if (bestCost > 0) {
		print(bestActions.join("\n"));
	}
}

main();

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var treeNum = integers[0], delta = integers[1];
	var trees = tokenizeIntegers(readline());
	var bestCost = treeNum, bestActions;
		maxStartingHeight = 1000;

	for (var start = 1; start <= maxStartingHeight; ++start) {
		var current = start, cost = 0;
		var actions = [];
		for (var i = 0; i < treeNum; ++i) {
			if (current > maxStartingHeight) {
				cost += treeNum - i;
				break;
			}
			if (trees[i] != current) {
				cost += 1;
				actions.push([current < trees[i] ? "-" : "+",
						i+1, Math.abs(current-trees[i])].join(" "));
			}
			current += delta;
		}
		if (cost < bestCost) {
			bestCost = cost;
			bestActions = actions;
		}
	}

	print(bestCost);
	if (bestCost > 0) {
		print(bestActions.join("\n"));
	}
}

main();


function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var a0 = [];
   var a1 = [];
   var s = [];
   for (var i = 0; i < n; i++) {
      var x = BigInt(a[i]);
      if (i & 1) {
         a1.push(x);
      } else {
         a0.push(x);
      }
   }
   s.push(a0[0]);
   for (var i = 1; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   for (var i = 0; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   var ans = 0n;
   var hn = Math.floor((n + 1) / 2);
   for (var i = 0; i < n; i++) {
      var sn = s[i + hn] - s[i];
      if (sn > ans) {
         ans = sn;
      }
   }
   write('' + ans);
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

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

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

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

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

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

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

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

function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var a0 = [];
   var a1 = [];
   var s = [];
   for (var i = 0; i < n; i++) {
      var x = BigInt(a[i]);
      if (i & 1) {
         a1.push(x);
      } else {
         a0.push(x);
      }
   }
   s.push(a0[0]);
   for (var i = 1; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   for (var i = 0; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   var ans = 0n;
   var hn = Math.floor((n + 1) / 2);
   for (var i = 0; i < n; i++) {
      var sn = s[i + hn] - s[i];
      if (sn > ans) {
         ans = sn;
      }
   }
   write('' + ans);
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

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

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

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

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

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

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

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

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    // tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();
        let a = [], sum = 0;
        for(let i = 0; i < N; i++) {
            a.push(nextInt());
            sum += a[i];
        }

        if (N===1) {
            print(sum);
            continue;
        }

        for(let i = 0; i < N; i++) {
            a.push(a[i]);
        }

        let at = [take(a, 0), take(a, 1)];
        let st = [accum(at[0]), accum(at[1])];
        // console.log(at);
        // console.log(st);

        let result = sum;
        for(let i = 0; i < N; i++) {
            let j = i + N - 2;
            let odd = (i+1)%2;
            // console.log(st[odd][j] - st[odd][i], i, j, odd, st[odd][j], st[odd][i]);
            result = Math.min(result, st[odd][j] - st[odd][i]);
        }
        // console.log(result);

        print(sum - result);
    }
}

function take(a, odd) {
    let b = [...a];
    for(let i = 0; i < b.length; i++) {
        if (i % 2 !== odd) {
            b[i] = 0;
        }
    }
    return b;
}

function accum(a) {
    let b = [...a];
    for(let i = 1; i < b.length; i++) {
        b[i] = b[i-1] + b[i];
    }
    return b;
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var a0 = [];
   var a1 = [];
   var s = [];
   for (var i = 0; i < n; i++) {
      var x = BigInt(a[i]);
      if (i & 1) {
         a1.push(x);
      } else {
         a0.push(x);
      }
   }
   a.length = 0;
   s.push(a0[0]);
   for (var i = 1; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   for (var i = 0; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   var ans = 0n;
   var hn = Math.floor((n + 1) / 2);
   for (var i = 0; i < n; i++) {
      var sn = s[i + hn] - s[i];
      if (sn > ans) {
         ans = sn;
      }
   }
   write('' + ans);
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

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

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

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

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

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

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

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

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

function solve() {
   var n = Number(read());
   var a = read().split(' ').map(BigInt);
   a.sort(sortF);
   var ans = 0n;
   for (var i = Math.floor(n / 2); i < n; i++) {
      ans += a[i];
   }
   write('' + ans);
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

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

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

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

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

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

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

function solve() {
   var n = Number(read());
   var a = read().split(' ');
   var a0 = [];
   var a1 = [];
   var s = [];
   for (var i = 0; i < n; i++) {
      var x = BigInt(a[i]);
      if (i & 1) {
         a1.push(x);
      } else {
         a0.push(x);
      }
   }
   s.push(a0[0]);
   for (var i = 1; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   for (var i = 0; i < a0.length; i++) {
      s.push(s[s.length - 1] + a0[i]);
   }
   for (var i = 0; i < a1.length; i++) {
      s.push(s[s.length - 1] + a1[i]);
   }
   var ans = 0n;
   var hn = Math.floor((n + 1 / 2));
   for (var i = 0; i < n; i++) {
      var sn = s[i + hn - 1] - s[i]
      if (sn > ans) {
         ans = sn;
      }
   }
   write('' + ans);
}

function init() {
   var T;
   T = 1;
   //T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function readArray(mapF) {
   return read().split(' ').map(mapF);
}

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

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

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

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

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

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

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

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    // tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();
        let a = [], sum = 0;
        for(let i = 0; i < N; i++) {
            a.push(nextInt());
            sum += a[i];
        }

        for(let i = 0; i < N; i++) {
            a.push(a[i]);
        }

        let at = [take(a, 0), take(a, 1)];
        let st = [accum(at[0]), accum(at[1])];
        // console.log(at);
        // console.log(st);

        let result = sum;
        for(let i = 0; i < N; i++) {
            let j = i + N - 2;
            let odd = (i+1)%2;
            // console.log(st[odd][j] - st[odd][i], i, j, odd, st[odd][j], st[odd][i]);
            result = Math.min(result, st[odd][j] - st[odd][i]);
        }
        // console.log(result);

        print(sum - result);
    }
}

function take(a, odd) {
    let b = [...a];
    for(let i = 0; i < b.length; i++) {
        if (i % 2 !== odd) {
            b[i] = 0;
        }
    }
    return b;
}

function accum(a) {
    let b = [...a];
    for(let i = 1; i < b.length; i++) {
        b[i] = b[i-1] + b[i];
    }
    return b;
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    // tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();
        let a = [], sum = 0;
        for(let i = 0; i < N; i++) {
            a.push(nextInt());
            sum += a[i];
        }

        for(let i = 0; i < N; i++) {
            a.push(a[i]);
        }

        let at = [take(a, 0), take(a, 1)];
        let st = [accum(at[0]), accum(at[1])];

        let result = sum;
        for(let i = 0; i < N; i++) {
            let j = i + N-2;
            let odd = i%2;
            result = Math.min(result, st[odd][j] - st[odd][i]);
        }

        print(sum - result);
    }
}

function take(a, odd) {
    let b = [...a];
    for(let i = 0; i < b.length; i++) {
        if (i % 2 === odd) {
            b[i] = 0;
        }
    }
    return b;
}

function accum(a) {
    let b = [...a];
    for(let i = 1; i < b.length; i++) {
        b[i] = b[i-1] + b[i];
    }
    return b;
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});