Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good. Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window.Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders.

The only line contains four integers n, m, a, b (1 ≤ n, m ≤ 109, 1 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted.

Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b.

NoteThe images below illustrate statement tests.The first test:In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection.The second test:In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones.

'use strict';

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

//code

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _readline$split$map = readline().split(' ').map(Number);

var _readline$split$map2 = _slicedToArray(_readline$split$map, 4);

var n = _readline$split$map2[0];
var m = _readline$split$map2[1];
var a = _readline$split$map2[2];
var b = _readline$split$map2[3];

if (Math.floor((a - 1) / m) === Math.floor((b - 1) / m)) {
	print("1");
} else {
	var elInFirstLine = m - (a - 1) % m;
	var elInLastLine = b % m;
	var elInMiddleLines = b - a + 1 - elInFirstLine - elInLastLine;
	//first line
	var selections = 1,
	    fullWidthSelection = false;
	//middle lines
	if (elInMiddleLines !== 0) {
		fullWidthSelection = true;
		if (elInFirstLine !== m) {
			selections += 1;
		}
	} else if (elInFirstLine === m) {
		fullWidthSelection = true;
	}
	//last line
	if (!(elInLastLine === 0)) {
		if (fullWidthSelection && b === n) {} else if (elInFirstLine + elInLastLine === m && elInMiddleLines !== 0) {} else {
			selections += 1;
		}
	}
	print(selections);
}

'use strict';

/*let input = `11 4 3 10`.split('\n');
function print(output) {
	console.log(output);
}
function readline() {
	return input.shift();
}*/

//code

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _readline$split$map = readline().split(' ').map(Number);

var _readline$split$map2 = _slicedToArray(_readline$split$map, 4);

var n = _readline$split$map2[0];
var m = _readline$split$map2[1];
var a = _readline$split$map2[2];
var b = _readline$split$map2[3];

var elInFirstLine = m - (a - 1) % m;
var elInLastLine = Math.floor((a - 1) / m) === Math.floor((b - 1) / m) ? 0 : b % m;
var elInMiddleLines = b - a + 1 - elInFirstLine - elInLastLine;

var selections = 1;
selections += elInMiddleLines === 0 || elInFirstLine === m ? 0 : 1;
selections += elInLastLine === 0 || elInFirstLine + elInLastLine === m && elInMiddleLines !== 0 ? 0 : 1;
print(selections);


Michael is accused of violating the social distancing rules and creating a risk of spreading coronavirus. He is now sent to prison. Luckily, Michael knows exactly what the prison looks like from the inside, especially since it's very simple.The prison can be represented as a rectangle $$$a\times b$$$ which is divided into $$$ab$$$ cells, each representing a prison cell, common sides being the walls between cells, and sides on the perimeter being the walls leading to freedom. Before sentencing, Michael can ask his friends among the prison employees to make (very well hidden) holes in some of the walls (including walls between cells and the outermost walls). Michael wants to be able to get out of the prison after this, no matter which cell he is placed in. However, he also wants to break as few walls as possible.Your task is to find out the smallest number of walls to be broken so that there is a path to the outside from every cell after this.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 100$$$) — the number of test cases. Each of the following $$$t$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$1\leq a, b\leq 100$$$), representing a corresponding test case.

For each test case print the single integer on a separate line — the answer to the problem.

NoteSome possible escape plans for the example test cases are shown below. Broken walls are shown in gray, not broken walls are shown in black.

T = readline()
while(T--){
   c = readline().split(' ').map(c => +c)
   a = c[0]
   b = c[1]
   print(a*b)
}

T = readline()

while (T--) {
    n = readline().split(' ').map(x => +x)
    a = n[0]
    b = n[1]
    print(a*b)
}

function getInt(num){
    return parseInt(num, 10)
}

var t = parseInt(readline(), 10);

for(var i = 0; i<t; i++){
    var line1 = readline().split(' ').map(getInt);
    print(solution.apply(undefined,line1));
}
function solution(a, b){
    return a*b
}

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

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

let count = -1
let inputArr = []

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

function solve([a,b]) {
    console.log(a*b)
}

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var a = nextInt();
		var b = nextInt();
		myout(a * 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();
var mod = 998244353n
var maxN = 10e6 + 1

function main() {
  var x = parseInt(readline())
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    //   var a = new Array(n)
    //   var marked = new Array(n).fill(false)
    //   var found = new Array(n).fill(false)
    var [a,b] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    // var b = readline().split('').map((x, iii) => {
    //   return x
    // });
    console.log(a*b)
  })
}

function find(value, a) {
  var l = -1
  var r = a.length
  while (r > l + 1) {
    var m = Math.floor((r + l) / 2)
    // console.log(a[m], f, l, r)
    if (a[m] <= value) l = m
    if (a[m] > value) r = m
  }
  return r
}

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

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

let count = -1
let inputArr = []

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

function solve([a,b]) {
    console.log(a*b)
}

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


Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that each of them has a certain amount of berland dollars with them. The residents of Berland are nice people, so each person agrees to swap places with the person right behind him for just 1 dollar. More formally, if person a stands just behind person b, then person a can pay person b 1 dollar, then a and b get swapped. Of course, if person a has zero dollars, he can not swap places with person b.Residents of Berland are strange people. In particular, they get upset when there is someone with a strictly smaller sum of money in the line in front of them.Can you help the residents of Berland form such order in the line so that they were all happy? A happy resident is the one who stands first in the line or the one in front of who another resident stands with not less number of dollars. Note that the people of Berland are people of honor and they agree to swap places only in the manner described above.

The first line contains integer n (1 ≤ n ≤ 200 000) — the number of residents who stand in the line. The second line contains n space-separated integers ai (0 ≤ ai ≤ 109), where ai is the number of Berland dollars of a man standing on the i-th position in the line. The positions are numbered starting from the end of the line.

If it is impossible to make all the residents happy, print ":(" without the quotes. Otherwise, print in the single line n space-separated integers, the i-th of them must be equal to the number of money of the person on position i in the new line. If there are multiple answers, print any of them.

NoteIn the first sample two residents should swap places, after that the first resident has 10 dollars and he is at the head of the line and the second resident will have 9 coins and he will be at the end of the line. In the second sample it is impossible to achieve the desired result.In the third sample the first person can swap with the second one, then they will have the following numbers of dollars: 4 11 3, then the second person (in the new line) swaps with the third one, and the resulting numbers of dollars will equal to: 4 4 10. In this line everybody will be happy.

var n = Number(readline());

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

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

a.sort(function(x, y) {return x - y});

var isPossible = true;

for (var i = 0; i < n; i++) {
	a[i] += n - 1 - i;
	if (a[i] < 0) {
		isPossible = false;
		break;
	}
}

for (var i = 0; i < n - 1; i++) {
	if (a[i] > a[i+1]) {
		isPossible = false;
		break;
	}
}

if (!isPossible) {
	print(':(');
} else {
	print(a.join(' '));
}


Luke likes to eat. There are $$$n$$$ piles of food aligned in a straight line in front of him. The $$$i$$$-th pile contains $$$a_i$$$ units of food. Luke will walk from the $$$1$$$-st pile towards the $$$n$$$-th pile, and he wants to eat every pile of food without walking back. When Luke reaches the $$$i$$$-th pile, he can eat that pile if and only if $$$|v - a_i| \leq x$$$, where $$$x$$$ is a fixed integer, and $$$v$$$ is Luke's food affinity.Before Luke starts to walk, he can set $$$v$$$ to any integer. Also, for each $$$i$$$ ($$$1 \leq i \leq n$$$), Luke can change his food affinity to any integer before he eats the $$$i$$$-th pile.Find the minimum number of changes needed to eat every pile of food.Note that the initial choice for $$$v$$$ is not considered as a change.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows. For each test case, the first line contains two integers, $$$n, x$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq x \leq 10^9$$$) — the number of piles, and the maximum difference between the size of a pile and Luke's food affinity, such that Luke can eat the pile. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots , a_n$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output an integer on a separate line, which is the minimum number of changes needed.

NoteIn the first test case, Luke can set $$$v$$$ to $$$5$$$ before he starts to walk. And he can walk straight to eat every piles of food without changing $$$v$$$.In the second test case, Luke can set $$$v$$$ to $$$3$$$ before he starts to walk. And he could change $$$v$$$ to $$$10$$$ before he eats the second pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.In the fourth test case, Luke can set $$$v$$$ to $$$3$$$ before he starts to walk. And he could change $$$v$$$ to $$$8$$$ before he eats the sixth pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.In the fifth test case, Luke can set $$$v$$$ to $$$4$$$ before he starts to walk. And he could change $$$v$$$ to $$$6$$$ before he eats the fourth pile. Then he could change $$$v$$$ to $$$12$$$ before he eats the seventh pile. After that, he can walk straight to eat remaining food without changing $$$v$$$.

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, x = 0;
    for(i = 1; i <= t * 2; i++){
        var a = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = a[0], x = a[1];
        }else{
            var ans = 0;
            var min = 2e9;
            var max = 0;
            for(j = 0; j < n; j++){
                min = Math.min(min, a[j]);
                max = Math.max(max, a[j]);
                if(max - min > x * 2){
                    ans++;
                    min = max = a[j];
                }
            }
            console.log(ans);
        }
    }
});

var tests = parseInt(readline());
    var n, x;
    var arr;
    for (var t=0; t < tests; t++) {
        var nx = readline().split(' ').map(x=>parseInt(x));
        n = nx[0];
        x = nx[1];
        var f = readline().split(' ').map(x=>parseInt(x));
        var count = 0;
        var min = f[0], max = f[0];
        for (var i = 1; i < n; i++) {
            var fi = f[i];
            if (fi < min) {
                min = fi;
            }
            if (fi > max) {
                max = fi;
            }
            if (max - min > 2 * x) {
                count++;
                max = fi;
                min = fi;
            }
        }
        print(count);
    }


Alexandra has an even-length array $$$a$$$, consisting of $$$0$$$s and $$$1$$$s. The elements of the array are enumerated from $$$1$$$ to $$$n$$$. She wants to remove at most $$$\frac{n}{2}$$$ elements (where $$$n$$$ — length of array) in the way that alternating sum of the array will be equal $$$0$$$ (i.e. $$$a_1 - a_2 + a_3 - a_4 + \dotsc = 0$$$). In other words, Alexandra wants sum of all elements at the odd positions and sum of all elements at the even positions to become equal. The elements that you remove don't have to be consecutive.For example, if she has $$$a = [1, 0, 1, 0, 0, 0]$$$ and she removes $$$2$$$nd and $$$4$$$th elements, $$$a$$$ will become equal $$$[1, 1, 0, 0]$$$ and its alternating sum is $$$1 - 1 + 0 - 0 = 0$$$.Help her!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^3$$$, $$$n$$$ is even)  — length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 1$$$)  — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^3$$$.

For each test case, firstly, print $$$k$$$ ($$$\frac{n}{2} \leq k \leq n$$$) — number of elements that will remain after removing in the order they appear in $$$a$$$. Then, print this $$$k$$$ numbers. Note that you should print the numbers themselves, not their indices. We can show that an answer always exists. If there are several answers, you can output any of them.

NoteIn the first and second cases, alternating sum of the array, obviously, equals $$$0$$$.In the third case, alternating sum of the array equals $$$1 - 1 = 0$$$.In the fourth case, alternating sum already equals $$$1 - 1 + 0 - 0 = 0$$$, so we don't have to remove anything.

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 arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    let [count0, count1] = [0, 0];

    for (let i = 0; i < len; i++) {
      if (arr[i] === 1) count1++;
      else count0++;
    }

    if (count0 >= len / 2) {
      console.log(len / 2);
      console.log("0 ".repeat(len / 2).trim());
    } else {
      const l = len / 2 + ((len / 2) % 2);
      console.log(l);
      console.log("1 ".repeat(l).trim());
    }
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array();
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    var zero = 0;
    var one = 0;
    var odd = 0;
    var even = 0;
    for(var j = 0; j < N; j++){
      if(j % 2 == 0){
        even += list[j];
      }else{
        odd += list[j];
      }
      if(list[j] == 0){
        zero++;
      }else{
        one++;
      }
    }
    if(even != odd){
      if(one > zero){
        for(var j = 0; j < N; j++){
          if(list[j] == 0){
            list.splice(j, 1);
            j--;
          }
        }
        if(list.length % 2 == 1){
          list.pop();
        }
      }else{
        for(var j = 0; j < N; j++){
          if(list[j] == 1){
            list.splice(j, 1);
            j--;
          }
        }
      }
    }

    output.push(list.length);
    output.push(myconv(list, 8));
  }
  myout(myconv(output, 9));
}

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, step, fn) {
  let res;
  for (let i = a; i <= b; i += step) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, step, fn, init) {
  let arr = Array(Math.max(a, b) + 1);
  if (init) init(arr);
  for (let i = a; i <= b; i += step) arr[i] = 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(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = Math.min(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == min : v == min);
  return [this[i], i, min];
}
Array.prototype.max = function (fn) {
  let max = Math.max(...this.map((v, i) => fn ? fn(v, i) : v));
  let i = this.findIndex((v, i) => fn ? fn(v, i) == max : v == max);
  return [this[i], i, max];
}

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];
  }
}
// [m] = extendedEuclid(a, 998244353);
// let MOD = 998244353n;
// let gt = Arr(0, n, (i, a) => i == 0 ? 1n : a[i - 1] * BigInt(i) % MOD);
// let rgt = Arr(0, n, (i, a) => i <= 1 ? 1n : MOD - MOD / BigInt(i) * a[998244353 % i] % MOD);
// for (let i = 2; i < n; i++) rgt[i] = rgt[i] * rgt[i - 1] % MOD;
// let nCk = (n, k) => {
//   return gt[n] * rgt[k] * rgt[n - k] % MOD;
// }
// for (let i = dm[l.l]; i <= n + n; i += i & -i) s[i]++; // start from index 1

(async () => {
  await inputPromise;
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [];
  let t = $()
  while (t--) {
    let n = $()
    let a = $(n)
    let s = a.sum()
    if (s <= n / 2) {
      console.log(n - s);
      console.log(Array(n - s).fill(0).join(' '))
    } else {
      console.log((s / 2 | 0) * 2);
      console.log(Array((s / 2 | 0) * 2).fill(1).join(' '))
    }
  }
})();

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

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

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

    let [count0, count1] = [0, 0];

    for (let i = 0; i < len; i++) {
      if (arr[i] === 1) count1++;
      else count0++;
    }

    if (count0 >= len / 2) {
      console.log(len / 2);
      console.log("0 ".repeat(len / 2).trim());
    } else {
      const l = len / 2 + (len % 2);
      console.log(l);
      console.log("1 ".repeat(l).trim());
    }
  }
}

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 countOne = 0;
    for (let i = 0; i < len; i++) if (arr[i] === 1) countOne++;

    if (countOne === 0 || countOne % 2 === 0) {
      console.log(len);
      console.log(`${arr.join(" ")}`);
    } else {
      const oneIndex = arr.findIndex((n) => n === 1);
      arr.splice(oneIndex, 1);
      console.log(`${arr.length}`);
      console.log(`${arr.join(" ")}`);
    }
  }
}

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

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

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

    let [maxIndex, sum, oneArr, zeroArr] = [0, arr[0], [], []];

    if (arr[0] === 0) zeroArr.push(0);
    else oneArr.push(1);

    for (let i = 1; i <= len - 1; i++) {
      if (arr[i] === 0) zeroArr.push(0);
      else oneArr.push(1);

      if (i % 2 !== 0) {
        sum -= arr[i];
      } else sum += arr[i];
      if (sum === 0) maxIndex = i;
    }
    if (oneArr.length === 0 || maxIndex === 0) {
      console.log(zeroArr.length);
      console.log(`${zeroArr.join(" ")}`);
    } else {
      arr = arr.slice(0, maxIndex + 1);
      console.log(arr.length);
      console.log(`${arr.join(" ")}`);
    }
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array();
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    var zero = 0;
    var one = 0;

    for(var j = 0; j < N; j++){
      if(list[j] == 0){
        zero++;
      }else{
        one++;
      }
    }
    if(one > zero){
      for(var j = 0; j < N; j++){
        if(list[j] == 0){
          list.splice(j, 1);
          j--;
        }
      }
    }else if(one < zero){
      for(var j = 0; j < N; j++){
        if(list[j] == 1){
          list.splice(j, 1);
          j--;
        }
      }
    }
    if(list.length % 2 == 1){
      list.pop();
    }
    output.push(list.length);
    output.push(myconv(list, 8));
  }
  myout(myconv(output, 9));
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array();
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    var odd = 0;
    var even = 0;
    for(var j = 0; j < N; j++){
      if(j % 2 == 0){
        even += list[j];
      }else{
        odd += list[j];
      }
    }
    if(odd > even){
      for(var j = 1; j < N; j += 2){
        if(list[j - 1] == 0 && list[j] == 1){
          list.splice(j, 1);
          j--;
          odd--;
        }
        if(odd == even){
          break;
        }
      }
    }else if(odd < even){
      for(var j = 0; j < N; j += 2){
        if(list[j] == 1 && list[j + 1] == 0){
          list.splice(j, 1);
          j--;
          even--;
        }
        if(odd == even){
          break;
        }
      }
    }
    output.push(list.length);
    output.push(myconv(list, 8));
  }
  myout(myconv(output, 9));
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array();
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var list = nextIntArray();
    var odd = 0;
    var even = 0;
    for(var j = 0; j < N; j++){
      if(j % 2 == 0){
        even += list[j];
      }else{
        odd += list[j];
      }
    }
    if(odd > even){
      for(var j = 1; j < N; j += 2){
        if(list[j] == 1){
          list.splice(j, 1);
          j--;
          odd--;
        }
        if(odd == even){
          break;
        }
      }
    }else if(odd < even){
      for(var j = 0; j < N; j += 2){
        if(list[j] == 1){
          list.splice(j, 1);
          j--;
          even--;
        }
        if(odd == even){
          break;
        }
      }
    }
    output.push(list.length);
    output.push(myconv(list, 8));
  }
  myout(myconv(output, 9));
}


You have an array $$$a$$$ of length $$$n$$$. For every positive integer $$$x$$$ you are going to perform the following operation during the $$$x$$$-th second:  Select some distinct indices $$$i_{1}, i_{2}, \ldots, i_{k}$$$ which are between $$$1$$$ and $$$n$$$ inclusive, and add $$$2^{x-1}$$$ to each corresponding position of $$$a$$$. Formally, $$$a_{i_{j}} := a_{i_{j}} + 2^{x-1}$$$ for $$$j = 1, 2, \ldots, k$$$. Note that you are allowed to not select any indices at all. You have to make $$$a$$$ nondecreasing as fast as possible. Find the smallest number $$$T$$$ such that you can make the array nondecreasing after at most $$$T$$$ seconds.Array $$$a$$$ is nondecreasing if and only if $$$a_{1} \le a_{2} \le \ldots \le a_{n}$$$.You have to answer $$$t$$$ independent test cases.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^{4}$$$) — the number of test cases. The first line of each test case contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the length of array $$$a$$$. It is guaranteed that the sum of values of $$$n$$$ over all test cases in the input does not exceed $$$10^{5}$$$. The second line of each test case contains $$$n$$$ integers $$$a_{1}, a_{2}, \ldots, a_{n}$$$ ($$$-10^{9} \le a_{i} \le 10^{9}$$$).

For each test case, print the minimum number of seconds in which you can make $$$a$$$ nondecreasing.

NoteIn the first test case, if you select indices $$$3, 4$$$ at the $$$1$$$-st second and $$$4$$$ at the $$$2$$$-nd second, then $$$a$$$ will become $$$[1, 7, 7, 8]$$$. There are some other possible ways to make $$$a$$$ nondecreasing in $$$2$$$ seconds, but you can't do it faster.In the second test case, $$$a$$$ is already nondecreasing, so answer is $$$0$$$.In the third test case, if you do nothing at first $$$2$$$ seconds and select index $$$2$$$ at the $$$3$$$-rd second, $$$a$$$ will become $$$[0, 0]$$$.

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        if(n === 1){
            console.log(0);
            continue;
        }else if(n === 2){
            if(a[0] <= a[1]){
                console.log(0);
            }else{
                console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));
            }
            continue;
        }

        let max = 0;
        for(let i = 1; i < n; i++){
            if(a[i] < a[i-1]){
                max = Math.max(max, a[i-1]-a[i]);
                a[i] = a[i-1];
            }
        }

        console.log(Math.ceil(Math.log2(max+1)));
    }
}

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, nums) {
  let mx = nums[0];
  let mxChange = 0;
  nums.forEach(val => {
    mx = Math.max(mx, val);
    mxChange = Math.max(mxChange, mx - val);
  })
  let k = 0;
  while (mxChange > 0) {
    mxChange -= 1 << k;
    ++k;
  }
  return k;
}

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

  const test = readLine()[0];
  for (let t = 1; t <= test; ++t) {
    const n = readLine()[0];
    const nums = readLine();
    const S = solve(n, nums);
    console.log(S);
  }
}

const readline = require("readline");

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

let arr = [];

rl.on("line", (line) => {
    arr.push(line);
}).on("close", () => {
    solve(arr);
    process.exit(0);
});

function solve(lines) {
    let row = 0;
    let t = +lines[row++];
    for(let i = 0; i < t; i++) {
        let n = +lines[row++];
        numbers_arr = lines[row++].split(" ").map(x => +x);
        calc_seconds(numbers_arr);
    }
}

function calc_seconds(arr) {
    let max = arr[0];
    let max_diff = 0;
    for(let i = 0; i < arr.length; i++) {
        if(arr[i] < max && max - arr[i] > max_diff) {
            max_diff = max - arr[i];
        }
        if(arr[i] > max) {
            max = arr[i];
        }
    }
    console.log(closest_lower_pow(max_diff));
}

function closest_lower_pow(num) {
    if(num == 0) {
        return 0;
    }
    let power = 0;
    while(Math.pow(2, power) <= num) {
        power++;
    }
    return power;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
  inputString = inputString.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(a, n) {
  let max = a[0];
  let diff = 0;
  for (let i = 1; i < n; i++) {
    diff = Math.max(diff, max - a[i]);
    max = Math.max(max, a[i]);
  }
  let t = diff.toString(2);
  return t === '0' ? t : t.length;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(a, n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

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

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

    for (let t = 1; t <= tests; t++) {
        var N = nextInt();
        var a = [];
        var mx = -1000000007;
        var maxDiff = 0;
        for (let i = 0; i < N; i++) {
            a.push(nextInt());
            if (a[i] < mx) {
                maxDiff = Math.max(maxDiff, mx-a[i]);
            } else {
                mx = a[i];
            }
        }
        var res = 0, sum = 1;
        while (sum-1 < maxDiff) {
            res++;
            sum *= 2;
        }
        print(res);
    }
}
// ----------------------------------- Template -----------------------------------
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();
});

wt = write;
rd = readline;

for(_ = parseInt(rd()); _ ; _--){
	n = parseInt(rd());
	arr = rd().split(" ").map(function(x){ return parseInt(x); });
	max = arr[n - 1], ans = 0;
	min = max;
	mp = {};
	for(i = n - 2; i >= 0; i--){
		max = arr[i];
		tmp = max - min;
		tmp = Math.max(tmp,0);
		cnt = 0;
		// wt(tmp);
		while(tmp > 0){
			cnt += 1;
			tmp = parseInt(tmp / 2);
		}
		// wt(" " + cnt + '\n');
		ans = Math.max(cnt, ans);
		min = Math.min(min, arr[i]);
		// wt(cnt + '\n');
	}
	wt(ans + '\n');
}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        if(n === 1){
            console.log(0);
            continue;
        }else if(n === 2){
            if(a[0] <= a[1]){
                console.log(0);
            }else{
                console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));
            }
            continue;
        }
        let res = 0;
        let s = 0;
        let c = 0;
        for(let i = n-2; i >= 0; i--){
            if(a[i] < a[i+1]){
                let sum = c*a[i+1]-s+1;
                res += Math.ceil(Math.log2(sum));
                c = 0;
                s = 0;
            }else{
                c += 1;
                s += a[i+1];
            }
        }

        console.log(res);
    }
}

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

    A();
});

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

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

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

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        if(n === 1){
            console.log(0);
            continue;
        }else if(n === 2){
            if(a[0] <= a[1]){
                console.log(0);
            }else{
                console.log(Math.ceil(Math.log2(a[0]-a[1]+1)));
            }
            continue;
        }
        let res = 0;
        let s = 0;
        let c = 0;
        for(let i = n-2; i >= 0; i--){
            if(a[i] < a[i+1]){
                let sum = c*a[i+1]-s+1;
                res = Math.max(res, Math.ceil(Math.log2(sum)));
                c = 0;
                s = 0;
            }else{
                c += 1;
                s += a[i+1];
            }
        }

        console.log(res);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
  inputString = inputString.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(a, n) {
  let t = 0;
  let swap = true;
  while (swap) {
    swap = false;
    let x = Math.pow(2, t);
    for (let i = 1; i < n; i++) {
      if (a[i] < a[i - 1]) {
        a[i] += x;
        swap = true;
      }
    }
    if (!swap) break;
    t++;
  }
  return t;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(a, n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

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

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

    for (let t = 1; t <= tests; t++) {
        var N = nextInt();
        var a = [];
        var mx = -1000000007;
        var maxDiff = 0;
        for (let i = 0; i < N; i++) {
            a.push(next());
            if (a[i] < mx) {
                maxDiff = Math.max(maxDiff, mx-a[i]);
            } else {
                mx = a[i];
            }
        }
        var res = 0, sum = 1;
        if (maxDiff == 0) {
            print(0);
        } else {
            while (sum-1 < maxDiff) {
                res++;
                sum *= 2;
            }
            print(res);
        }
    }
}
// ----------------------------------- Template -----------------------------------
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 = nextInt();

    for (let t = 1; t <= tests; t++) {
        var N = nextInt();
        var a = [];
        var mx = -1000000007;
        var maxDiff = 0;
        for (let i = 0; i < N; i++) {
            a.push(next());
            if (a[i] < mx) {
                maxDiff = Math.max(maxDiff, mx-a[i]);
            } else {
                mx = a[i];
            }
        }
        if (maxDiff == 0) {
            print(0);
        } else {
            print(Math.ceil(Math.log2(maxDiff))+1);
        }
    }
}
// ----------------------------------- Template -----------------------------------
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();
});


Consider a tunnel on a one-way road. During a particular day, $$$n$$$ cars numbered from $$$1$$$ to $$$n$$$ entered and exited the tunnel exactly once. All the cars passed through the tunnel at constant speeds.A traffic enforcement camera is mounted at the tunnel entrance. Another traffic enforcement camera is mounted at the tunnel exit. Perfectly balanced.Thanks to the cameras, the order in which the cars entered and exited the tunnel is known. No two cars entered or exited at the same time.Traffic regulations prohibit overtaking inside the tunnel. If car $$$i$$$ overtakes any other car $$$j$$$ inside the tunnel, car $$$i$$$ must be fined. However, each car can be fined at most once.Formally, let's say that car $$$i$$$ definitely overtook car $$$j$$$ if car $$$i$$$ entered the tunnel later than car $$$j$$$ and exited the tunnel earlier than car $$$j$$$. Then, car $$$i$$$ must be fined if and only if it definitely overtook at least one other car.Find the number of cars that must be fined.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$), denoting the number of cars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$), denoting the ids of cars in order of entering the tunnel. All $$$a_i$$$ are pairwise distinct. The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le n$$$), denoting the ids of cars in order of exiting the tunnel. All $$$b_i$$$ are pairwise distinct.

NoteThe first example is depicted below:Car $$$2$$$ definitely overtook car $$$5$$$, while car $$$4$$$ definitely overtook cars $$$1$$$, $$$2$$$, $$$3$$$ and $$$5$$$. Cars $$$2$$$ and $$$4$$$ must be fined.In the second example car $$$5$$$ was definitely overtaken by all other cars.In the third example no car must be fined.

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const n = parseInt(arr.shift())
  const aS = arr[0].split(' ')
  const bS = arr[1].split(' ')

  let aI= {}, bI = {}
  for(let i = 0; i < n; i++) {
    aS[i] = parseInt(aS[i])
    bS[i] = parseInt(bS[i])
    aI[aS[i]] = i
    bI[bS[i]] = i
    // console.log("asd", aS[i], bS[i], i)
  }

  let count = 0;
  for(let i = 1; i < n; i++) {
    // if((aI[aS[i]] - aI[aS[i - 1]]) > (bI[aS[i]] - bI[aS[i - 1]])){
    if(bI[aS[i]] - bI[aS[i - 1]] < 0){
      count ++
      // console.log(aS[i], aS[i - 1])
      // console.log(bS[i], bS[i - 1], i)
      aS[i] = aS[i - 1]
    }
  }

  console.log(count)
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const n = parseInt(arr.shift())
  const aS = arr[0].split(' ')
  const bS = arr[1].split(' ')

  let aI= {}, bI = {}
  for(let i = 0; i < n; i++) {
    aS[i] = parseInt(aS[i])
    bS[i] = parseInt(bS[i])
    aI[aS[i]] = i
    bI[bS[i]] = i
    if(n == 7) console.log(aS[i], bS[i], i)
  }

  let count = 0;
  for(let i = 1; i < n; i++) {
    if((aI[aS[i]] - aI[aS[i - 1]]) > (bI[aS[i]] - bI[aS[i - 1]])){
      count ++
      aS[i] = aS[i - 1]
      if(n == 7) console.log(aS[i], bS[i], i)
    }
  }

  console.log(count)
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const n = parseInt(arr.shift())
  const aS = arr[0].split(' ')
  const bS = arr[1].split(' ')

  let aI= {}, bI = {}
  for(let i = 0; i < n; i++) {
    aI[parseInt(aS[i])] = i
    bI[parseInt(bS[i])] = i
  }

  let count = 0;
  for(let i = 1; i < n; i++) {
    if((aI[aS[i]] - aI[aS[i - 1]]) > (bI[aS[i]] - bI[aS[i - 1]])){
      count ++
      aS[i] = aS[i - 1]
    }
  }

  console.log(count)
})


Vova is playing a computer game. There are in total $$$n$$$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $$$k$$$.During each turn Vova can choose what to do:   If the current charge of his laptop battery is strictly greater than $$$a$$$, Vova can just play, and then the charge of his laptop battery will decrease by $$$a$$$;  if the current charge of his laptop battery is strictly greater than $$$b$$$ ($$$b<a$$$), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by $$$b$$$;  if the current charge of his laptop battery is less than or equal to $$$a$$$ and $$$b$$$ at the same time then Vova cannot do anything and loses the game. Regardless of Vova's turns the charge of the laptop battery is always decreases.Vova wants to complete the game (Vova can complete the game if after each of $$$n$$$ turns the charge of the laptop battery is strictly greater than $$$0$$$). Vova has to play exactly $$$n$$$ turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each query is presented by a single line. The only line of the query contains four integers $$$k, n, a$$$ and $$$b$$$ ($$$1 \le k, n \le 10^9, 1 \le b < a \le 10^9$$$) — the initial charge of Vova's laptop battery, the number of turns in the game and values $$$a$$$ and $$$b$$$, correspondingly.

For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.

NoteIn the first example query Vova can just play $$$4$$$ turns and spend $$$12$$$ units of charge and then one turn play and charge and spend $$$2$$$ more units. So the remaining charge of the battery will be $$$1$$$.In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be $$$0$$$ after the last turn.

(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 q = read.number();
    var res = '';
    while (q) {
        q--;

        var line = read.arrNumber(' ');
        var k = line[0];
        var n = line[1];
        var a = line[2];
        var b = line[3];

        if (k <= b * n) {
            res += '-1\n';
        }
        else {
            function f(l, r) {
                var i = l + Math.ceil((r - l) / 2);
                if(l >= r) {
                    return l;
                }
                var con =  (i * a + b * (n - i) < k );
                if(con && ((i + 1) * a + b * (n - (i + 1)) >= k)) {
                    return i;
                }
                if(con) {
                    return f(i + 1, r);
                }
                else {
                    return f(l ,i - 1);
                }
            }

            res += Math.min(n, f(0, n)) + '\n';
        }
    }
    print(res);

}());

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	if (prob[0] - prob[3] * prob[1] <= 0) {
		write ('-1\n');
		continue;
	}
	if (prob[0] == prob[1] * prob[2]) {
		write ((prob[1] - 1) + '\n');
		continue;
	}
	var hehe = (prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]);
	if (hehe == Math.floor(hehe)) {
		write(Math.min(hehe - 1, prob[1]) + '\n');
	} else {
		write(Math.min(Math.floor(hehe), prob[1]) + '\n');
	}
}

var numberOfRounds = parseInt(readline());

for (var i = 0; i < numberOfRounds; i++) {
    var parameters = readline().split(" ");
    var k = parseInt(parameters[0]);
    var n = parseInt(parameters[1]);
    var a = parseInt(parameters[2]);
    var b = parseInt(parameters[3]);

    if (k - a * n > 0) {
        print(n);
        continue;
    }

    var maxRoundsWithoutCharge = Math.floor((k - 1) / a);
    if (maxRoundsWithoutCharge === n) {
        print(maxRoundsWithoutCharge);
        continue;
    }

    print(findSolution(0, maxRoundsWithoutCharge))
}

function findSolution(from, to) {
    var delta = Math.ceil((to - from) / 2)
    var currentMiddle = from + delta;

    var middle = canFinishOnCharge(k - currentMiddle * a, n - currentMiddle, b);
    var right = canFinishOnCharge(k - (currentMiddle + 1) * a, n - (currentMiddle + 1), b);

    if (middle && !right) {
        return currentMiddle;
    }

    if (!currentMiddle) {
        return -1;
    }

    if (currentMiddle === to) {
        return findSolution(from, from)
    }

    if (currentMiddle === from) {
        return findSolution(top, top);
    }

    if (!middle) {
        return findSolution(from, currentMiddle)
    }

    return findSolution(currentMiddle, to);
}

function canFinishOnCharge(kMod, nLeft, b) {
    return kMod - nLeft * b < 1
        ? 0
        : 1;
}

var numberOfRounds = parseInt(readline());

for (var i = 0; i < numberOfRounds; i++) {
    var parameters = readline().split(" ");
    var k = parseInt(parameters[0]);
    var n = parseInt(parameters[1]);
    var a = parseInt(parameters[2]);
    var b = parseInt(parameters[3]);

    if (k - a * n > 0) {
        print(n);
        continue;
    }

    var maxRoundsWithoutCharge = Math.floor((k - 1) / a);
    if (maxRoundsWithoutCharge === n) {
        print(maxRoundsWithoutCharge);
        continue;
    }

    print(bin_search(k, n, a, b))
}

function bin_search(k, n, a, b) {
    var left = -1
    var right = k
    while (right - left > 1) {
        var mid = Math.ceil((right + left) / 2);
        if (condition(k, n, a, b, mid)) {
            left = mid;
        } else {
            right = mid;
        }
    }

    return left;
}

function condition(k, n, a, b, roundsWithoutCharge) {
    return canFinishOnCharge(k - roundsWithoutCharge * a, n - roundsWithoutCharge, b);
}

function canFinishOnCharge(kMod, nLeft, b) {
    return kMod - nLeft * b < 1
        ? 0
        : 1;
}

"use strict";

var q = +readline()

while (q--) {
    var input = readline().split(' ').map(value => +value);
    var k = input[0];
    var n = input[1];
    var a = input[2];
    var b = input[3];
    var delta = a - b;
    var maxMovesWithCharge = Math.floor(k/b);

    if (maxMovesWithCharge < n) {
        write('-1\n');
    } else if (maxMovesWithCharge === n && !(k%b)) {
        write('-1\n');
    } else {
        var batteryUsageWithCharge = n*b;
        var batteryRemains = k - batteryUsageWithCharge - 1;
        var result = Math.floor(batteryRemains/delta);
        write(Math.min(result, n) + '\n');
    }
}

(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 q = read.number();
    var res = '';
    while (q) {
        q--;

        var line = read.arrNumber(' ');
        var k = line[0];
        var n = line[1];
        var a = line[2];
        var b = line[3];

        if (k <= b * n) {
            res += '-1\n';
        }
        else {
            function f(l, r) {
                var i = l + Math.ceil((r - l) / 2);
                if(l >= r) {
                    return r;
                }
                var con =  (i * a + b * (n - i) < k );
                if(con && ((i + 1) * a + b * (n - (i + 1)) >= k)) {
                    return i;
                }
                if(con) {
                    return f(l + i,r);
                }
                else {
                    return f(l ,r - i);
                }
            }

            res += f(0, n) + '\n';
        }
    }
    print(res);

}());

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	write(prob[0] - prob[3] * prob[1] <= 0 ? '-1\n' : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\n');
}

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	write(prob[0] - prob[3] * prob[1] <= 0 ? '-1\n' : Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3])) + '\n');
}

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	write(prob[0] - prob[3] * prob[1] <= 0
	? '-1\n'
	: prob[0] === prob[1] * prob[2]
	    ? (prob[1] - 1) + '\n'
	    : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\n');
}

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	write(prob[0] - prob[3] * prob[1] <= 0
	? '-1\n'
	: prob[0] == prob[1] * prob[2]
	    ? (prob[1] - 1) + '\n'
	    : Math.min(prob[1], Math.floor((prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]))) + '\n');
}

var q = parseInt(readline());
//	write(countDays);
for (var i = 0; i < q; i++) {
	var prob = readline().split(' ');
	if (prob[0] - prob[3] * prob[1] <= 0) {
		write ('-1\n');
		continue;
	}
	if (prob[0] == prob[1] * prob[2]) {
		write ((prob[1] - 1) + '\n');
		continue;
	}
	var hehe = (prob[0] - prob[3] * prob[1]) / (prob[2] - prob[3]);
	if (hehe == Math.floor(hehe)) {
		write(hehe - 1 + '\n');
	} else {
		write(Math.floor(hehe) + '\n');
	}
}

var numberOfRounds = parseInt(readline());

for (var i = 0; i < numberOfRounds; i++) {
    var parameters = readline().split(" ");
    var k = parseInt(parameters[0]);
    var n = parseInt(parameters[1]);
    var a = parseInt(parameters[2]);
    var b = parseInt(parameters[3]);

    if (k - a * n > 0) {
        print(n);
        continue;
    }

    var solutionFound = false;
    var roundsWithoutCharge = Math.floor(k / a);

    while (!solutionFound) {
        if (canFinishOnCharge(k - roundsWithoutCharge * a, n - roundsWithoutCharge, b)) {
            solutionFound = true;
            print(roundsWithoutCharge);
        }

        roundsWithoutCharge--;
    }

    if (!solutionFound) {
        print(-1);
    }
}

function canFinishOnCharge(kMod, nLeft, b) {
    return kMod - nLeft * b < 1
        ? 0
        : 1;
}