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

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

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


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

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

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

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


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

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

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


'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    if (cache[i][j] === undefined) cache[i][j] = {};
    const inside = () => {
      let res = [];
      if (nums[i] > p && nums[j] > p) {
        if (nums[i] > nums[j]) {
          if (r[i] - i + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i, j - 1, nums[j]]);
        } else if (nums[i] < nums[j]) {
          if (j - l[j] + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i + 1, j, nums[i]]);
        } else {
          res.push([i, j - 1, nums[j]]);
          res.push([i + 1, j, nums[i]]);
        }
      } else if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      } else if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        if (a) res = false;
      } else if (a && b) res = false;
      if (!cache[i][j][p]) cache[i][j][p] = res;
      return !!cache[i][j][p];
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    a=rows[1].split(" ").map(x=>+x);

    var L=0,R=a.length-1;
    var e=winner(-1,L,R,0);
    console.log(["Alice","Bob"][e]);
})

var a;

function winner(min,L,R,player){
  while (1){
    if (R==L) return (a[L]>min?player:1-player);
    if (a[L]>min){
      if (a[R]>min){
         if (R==L+1) return player;
         if (R==L+2) return ((a[L+1]<=a[L])||(a[L+1]<=a[R])?player:1-player);
         if ((a[L+1]<=a[L])&&(a[R]<=a[L])) return player;
         if ((a[R-1]<=a[R])&&(a[L]<=a[R])) return player;
         if (a[L]>a[R]){
          if (winner(a[L],L+1,R,1-player)==player) return player;
          min=a[R--];player=1-player;
         } else {
          if (winner(a[R],L,R-1,1-player)==player) return player;
          min=a[L++];player=1-player;
         }
      } else { // forzato L
        var i=L+1;
        while (a[i]>a[i-1]) i++;
        return ((i-L)%2)?player:1-player;
      }
    } else {
      if (a[R]>min){ // forzato R
        var i=R-1;
        while (a[i]>a[i+1]) i--;
        return ((R-i)%2)?player:1-player;
      } else return 1-player;
    }
  }
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const h = new Map(),
        e = [],
        ne = [],
        d = new Map(),
        dp = new Map();
  const add = (i, j) => {
    if (!h.has(i)) {
      h.set(i, -1);
      d.set(i, 0);
      dp.set(i, 0);
    }
    if (!h.has(j)) {
      h.set(j, -1);
      d.set(j, 0);
      dp.set(j, 0);
    }
    e.push(j);
    ne.push(h.get(i));
    d.set(j, d.get(j) + 1);
    h.set(i, ne.length - 1);
  };
  const queue = [[n - 1, -1]];
  for (let [u, pre] of queue) {
    const i = Math.floor(u / n),
          j = u % n;
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j] || nums[j] >= nums[i] && nums[j] >= nums[j - 1] || i === j) {
      dp.set(u, 1);
    } else {
      if (nums[i] > pre && nums[j] > pre) {
        if (nums[i] < nums[j]) {
          const v = (i + 1) * n + j;
          add(v, u);
          queue.push([v, nums[i]]);
          if (j - l[j] + 1 & 1) dp.set(u, 1);
        } else if (nums[i] > nums[j]) {
          const v = i * n + j - 1;
          add(v, u);
          queue.push([v, nums[j]]);
          if (r[i] - i + 1 & 1) dp.set(u, 1);
        } else {
          let v = (i + 1) * n + j;
          add(v, u);
          queue.push([v, nums[i]]);
          v = i * n + j - 1;
          add(v, u);
          queue.push([v, nums[j]]);
        }
      } else if (nums[i] > pre) {
        const v = (i + 1) * n + j;
        add(v, u);
        queue.push([v, nums[i]]);
      } else if (nums[j] > pre) {
        const v = i * n + j - 1;
        add(v, u);
        queue.push([v, nums[j]]);
      }
    }
  }
  {
    const q = [];
    for (let [i, cnt] of d) {
      if (!cnt) q.push(i);
    }
    for (let u of q) {
      for (let i = h.get(u); ~i; i = ne[i]) {
        const v = e[i];
        dp.set(v, dp.get(v) | dp.get(u) ^ 1);
        if (d.get(v) === 1) {
          q.push(v);
        }
        d.set(v, d.get(v) - 1);
      }
    }
    if (dp.get(n - 1)) return 'Alice';
    return 'Bob';
  }
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    a=rows[1].split(" ").map(x=>+x);

    var L=0,R=a.length-1;
    var e=winner(-1,L,R,0);
    console.log(["Alice","Bob"][e]);
})

var a;

function winner(min,L,R,player){
  while (1){
    if (R==L) return (a[L]>min?player:1-player);
    if (a[L]>min){
      if (a[R]>min){
         if (R==L+1) return player;
         if (R==L+2) return ((a[L+1]<=a[L])||(a[L+1]<=a[R])?player:1-player);
         if ((a[L+1]<=a[L])&&(a[R]<=a[L])) return player;
         if ((a[R-1]<=a[R])&&(a[L]<=a[R])) return player;
         if (a[L]>a[R]){
          if (winner(a[L],L+1,R,1-player)==player) return player;
          min=a[R--];player=1-player;
         } else {
          if (winner(a[R],L,R-1,1-player)==player) return player;
          min=a[L++];player=1-player;
         }
      } else { // forzato L
        var i=L+1;
        while (a[i]>a[L]) i++;
        return (i-L)%2?player:1-player;
      }
    } else {
      if (a[R]>min){ // forzato R
        var i=R-1;
        while (a[i]>a[R]) i--;
        return (R-i)%2?player:1-player;
      } else return 1-player;
    }
  }
}

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    var a=rows[1].split(" ").map(x=>1*x);

    var lastSeq=-1;
    var L=0,R=a.length-1;
    var turn=0; //0=alice 1=bob turn
    while (R-L>=0){
        //console.log("choices:"+a[L]+","+a[R])
        if (a[L]>lastSeq){
            if (a[R]>lastSeq){ // scelta
                lastSeq=a[L++];
            } else lastSeq=a[L++]; //forzata
        } else {
            if (a[R]>lastSeq) lastSeq=a[R--]; // forzata
            else break; // nessuna possibilità
        }
        //console.log(turn+" plays "+lastSeq)
        turn=1-turn;
    }
    console.log(["Alice","Bob"][1-turn]);
})

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    var a=rows[1].split(" ").map(x=>1*x);

    var lastSeq=-1;
    var L=0,R=a.length-1;
    var turn=0; //0=alice 1=bob turn
    while (R-L>=0){
        //console.log("choices:"+a[L]+","+a[R])
        if (a[L]>lastSeq){
            lastSeq=a[L++]
        } else if (a[R]>lastSeq){
            lastSeq=a[R--]
        } else break;
        //console.log(turn+" plays "+lastSeq)
        turn=1-turn;
    }
    console.log(["Alice","Bob"][1-turn]);
})

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    var a=rows[1].split(" ").map(x=>1*x);

    var lastSeq=-1;
    var L=0,R=a.length-1;
    var turn=0; //0=alice 1=bob turn
    while (R-L>=0){
        console.log("choices:"+a[L]+","+a[R])
        if (a[L]>lastSeq){
            lastSeq=a[L++]
        } else if (a[R]>lastSeq){
            lastSeq=a[R--]
        } else break;
        console.log(turn+" plays "+lastSeq)
        turn=1-turn;
    }
    console.log(["Alice","Bob"][1-turn]);
})

let s = []
process.stdin.on('data', l => s+=l)
process.stdin.on('end', () => {
    var rows=s.split("\n")
    var n=1*rows[0];
    var a=rows[1].split(" ");

    var lastSeq=-1;
    var L=0,R=a.length-1;
    var turn=0; //0=alice 1=bob turn
    while (R-L>0){
        if (a[L]>lastSeq){
            lastSeq=a[L++]
        } else if (a[R]>lastSeq){
            lastSeq=a[R--]
        } else break;
        turn=1-turn;
    }
    console.log(["Alice","Bob"][1-turn]);
})

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    if (cache[i][j] === undefined) cache[i][j] = {};
    const inside = () => {
      let res = [];
      if (nums[i] > p && nums[j] > p) {
        if (nums[i] > nums[j]) {
          if (r[i] - i + 1 & 1) {
            cache[i][j][p] = true;
          }
          res.push([i, j - 1, nums[j]]);
        } else if (nums[i] < nums[j]) {
          if (i - l[i] + 1 & 1) {
            cache[i][j][p] = true;
          }
          res.push([i + 1, j, nums[i]]);
        } else {
          res.push([i, j - 1, nums[j]]);
          res.push([i + 1, j, nums[i]]);
        }
      } else if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      } else if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        if (a) res = false;
      } else if (a && b) res = false;
      if (!cache[i][j][p]) cache[i][j][p] = res;
      return !!cache[i][j][p];
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    if (cache[i][j] === undefined) cache[i][j] = {};
    const inside = () => {
      let res = [];
      if (nums[i] > p && nums[j] > p) {
        if (nums[i] > nums[j]) {
          if (r[i] - i + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i, j - 1, nums[j]]);
        } else if (nums[i] < nums[j]) {
          if (i - l[i] + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i + 1, j, nums[i]]);
        } else {
          res.push([i, j - 1, nums[j]]);
          res.push([i + 1, j, nums[i]]);
        }
      } else if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      } else if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        if (a) res = false;
      } else if (a && b) res = false;
      if (!cache[i][j][p]) cache[i][j][p] = res;
      return !!cache[i][j][p];
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    if (cache[i][j] === undefined) cache[i][j] = {};
    const inside = () => {
      let res = [];
      if (nums[i] > p && nums[j] > p) {
        if (nums[i] > nums[j]) {
          if (r[i] - i + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i, j - 1, nums[j]]);
        } else if (nums[i] < nums[j]) {
          if (i - l[i] + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i + 1, j, nums[i]]);
        } else {
          res.push([i, j - 1, nums[j]]);
          res.push([i + 1, j, nums[i]]);
        }
      } else if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      } else if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        if (a) res = false;
      } else if (a && b) res = false;
      if (!cache[i][j][p]) cache[i][j][p] = res;
      return cache[i][j][p];
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    if (cache[i][j] === undefined) cache[i][j] = {};
    const inside = () => {
      let res = [];
      if (nums[i] > p && nums[j] > p) {
        if (nums[i] > nums[j]) {
          if (r[i] - i + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i, j - 1, nums[j]]);
        } else if (nums[i] < nums[j]) {
          if (i - l[i] + 1 & 1) {
            cache[i][j][p] = true;
            return [];
          }
          res.push([i + 1, j, nums[i]]);
        } else {
          res.push([i, j - 1, nums[j]]);
          res.push([i + 1, j, nums[i]]);
        }
      } else if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      } else if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        if (a) res = false;
      } else if (a && b) res = false;
      if (!cache[i][j][p]) cache[i][j][p] = res;
      return res;
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j) return [() => [], () => false];
    if (nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j]) return [() => [], () => true];
    if (nums[j] >= nums[i] && nums[j] >= nums[j - 1]) return [() => [], () => true];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    const inside = () => {
      let res = [];
      if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      }
      if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        res = !a;
      }
      res = !a && !b;
      if (cache[i][j] === undefined) cache[i][j] = {};
      cache[i][j][p] = res;
      return res;
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const l = new Array(n).fill(-1),
        r = new Array(n).fill(n);
  {
    let pre = -1;
    for (let i = 0; i < n; i++) {
      var _nums;
      if (nums[i] >= ((_nums = nums[i - 1]) !== null && _nums !== void 0 ? _nums : Infinity)) pre = i;
      l[i] = pre;
    }
    pre = n;
    for (let i = n - 1; i >= 0; i--) {
      var _nums2;
      if (nums[i] >= ((_nums2 = nums[i + 1]) !== null && _nums2 !== void 0 ? _nums2 : Infinity)) pre = i;
      r[i] = pre;
    }
  }
  const cache = Array.from({
    length: n
  }, () => ({}));
  const dfs = RTI((i, j, p) => {
    var _cache$i$j2;
    if (i > j || nums[i] <= p && nums[j] <= p) return [() => [], () => false];
    if (((_cache$i$j2 = cache[i][j]) === null || _cache$i$j2 === void 0 ? void 0 : _cache$i$j2[p]) !== undefined) return [() => [], () => cache[i][j][p]];
    const inside = () => {
      let res = [];
      if (nums[i] > p) {
        res.push([i + 1, j, nums[i]]);
      }
      if (nums[j] > p) {
        res.push([i, j - 1, nums[j]]);
      }
      return res;
    };
    const after = (args, childResult) => {
      const [a, b] = childResult;
      let res = true;
      if (b === undefined) {
        res = !a;
      }
      res = !a && !b;
      if (cache[i][j] === undefined) cache[i][j] = {};
      cache[i][j][p] = res;
      return res;
    };
    return [inside, after];
  });
  if (dfs(0, n - 1, -1)) return 'Alice';
  return 'Bob';
}
function RTI(fn) {
  let res;
  const createNode = args => {
    return {
      args,
      result: [],
      curIndex: 0
    };
  };
  const dfs = (...args) => {
    const root = createNode([args]);
    root.cb = ([args], [result]) => res = result;
    const callStack = [root];
    while (callStack.length) {
      let curCall = callStack[callStack.length - 1];
      while (curCall && curCall.args.length === curCall.curIndex) {
        var _curCall$cb, _curCall;
        const res = (_curCall$cb = (_curCall = curCall).cb) === null || _curCall$cb === void 0 ? void 0 : _curCall$cb.call(_curCall, curCall.args, curCall.result);
        callStack.pop();
        curCall = callStack[callStack.length - 1];
        if (curCall) curCall.result[curCall.curIndex++] = res;
      }
      if (!curCall) break;
      const {
        args,
        curIndex
      } = curCall;
      {
        const res = fn(...args[curIndex]);
        const [inside, after] = res;
        let nextCall = inside();
        const node = createNode(nextCall);
        node.cb = after;
        callStack.push(node);
      }
    }
    return res;
  };
  return dfs;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        nums = new Array(n);
  for (let i = 0; i < n; i++) nums[i] = rn();
  const h = new Map(),
        e = [],
        ne = [],
        d = new Map();
  const add = (i, j) => {
    if (!h.has(i)) {
      h.set(i, -1);
      d.set(i, 0);
    }
    if (!h.has(j)) {
      h.set(j, -1);
      d.set(j, 0);
    }
    e.push(j);
    ne.push(h.get(i));
    d.set(j, d.get(j) + 1);
    h.set(i, ne.length - 1);
  };
  const queue = [[n - 1, -1]],
        dp = new Map();
  for (let [u, pre] of queue) {
    const i = Math.floor(u / n),
          j = u % n;
    if (nums[i] >= nums[i + 1] && nums[i] >= nums[j] || nums[j] >= nums[i] && nums[j] >= nums[j - 1] || i === j) {
      dp.set(u, 1);
    } else {
      if (nums[i] > pre) {
        const v = (i + 1) * n + j;
        add(v, u);
        queue.push([v, nums[i]]);
      }
      if (nums[j] > pre) {
        const v = i * n + j - 1;
        add(v, u);
        queue.push([v, nums[j]]);
      }
    }
  }
  {
    const q = [];
    for (let [i, cnt] of d) {
      if (!cnt) q.push(i);
    }
    for (let u of q) {
      for (let i = h.get(u); ~i; i = ne[i]) {
        const v = e[i];
        if (dp.has(v)) {
          dp.set(v, dp.get(v) | ~dp.get(u));
        } else {
          dp.set(v, dp.get(u) ^ 1);
        }
        if (d.get(v) === 1) {
          q.push(v);
        }
        d.set(v, d.get(v) - 1);
      }
    }
    if (dp.get(n - 1)) return 'Alice';
    return 'Bob';
  }
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


var g = readline();
var strs = [];
for(var i =0;i<g;i++){
    strs.push(readline());
}

strs = strs.sort(function(a, b){
    return a.length - b.length;
})

var flag = true;
for(i=0;i<strs.length;i++){
    var searchFlag =true;
    if(!searchFlag) break;
    for(b=i+1;b<strs.length;b++){
        if(strs[b].indexOf(strs[i]) == -1){
            flag =false;
            searchFlag = false;
            break;
        }
    }
}

if(flag){
    print("YES");
    for(var i=0;i<strs.length;i++){
        print(strs[i]);
    }
}else
print("NO");

  var n = parseInt(readline());
  var s = [];
  for(var i = 0; i < n; i += 1) {
    s[i] = readline();
  }
  var g = [];
  for(var i = 0; i < n; i += 1) {
    g[i] = [];
  }
  for(var i = 0; i < n; i += 1) {
    for(var j = i; j < n; j += 1) {
      if(s[i].includes(s[j]) && s[i] !== s[j]) {
        g[i][j] = 1;
      } else {
        g[i][j] = 0;
      }
      if(s[j].includes(s[i]) && s[i] !== s[j]) {
        g[j][i] = 1;
      } else {
        g[j][i] = 0;
      }
    }
    g[i][i] = 0;
  }
  var d = [];
  var q = [];
  for(var i = 0; i < n; i += 1) {
    d[i] = 0;
    for(var j = 0; j < n; j += 1) {
      if(g[j][i] === 1) {
        d[i] += 1;
      }
    }
    if(d[i] === 0) {
      q.push(i);
    }
  }
  var res = [];
  while(q.length > 0) {
    var v = q.pop();
    res.push(v);
    for(var i = 0; i < n; i += 1) {
      if(g[v][i] === 1) {
        g[v][i] = 0;
        d[i] -= 1;
        if(d[i] === 0) {
          q.push(i);
        }
      }
    }
  }
  var flag = true;
  for(var i = 0; i < n && flag; i += 1) {
    for(var j = 0; j < n && flag; j += 1) {
      if(g[i][j] === 1) {
        flag = false;
      }
    }
  }

  for(var i = 0; i < n && flag; i += 1) {
    for(var j = i; j < n && flag; j += 1) {
      if(!s[res[i]].includes(s[res[j]])) {
        flag = false;
      }
    }
  }

  if(flag) {
    print('YES');
    print(res.reverse().map(function(x) { return s[x]; }).join('\n'));
  } else {
    print('NO');
  }

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString='';
let currentLine=0;
process.stdin.on('data',inputStdin=>{
    inputString+=inputStdin;
});
process.stdin.on('end',_=>{
    inputString=inputString.trim().split("\n").map(string=>{
        return string.trim();
    });
    main();
});
function readLine()
{
    return inputString[currentLine++];
}
function main()
{
    const N=parseInt(readLine());
    let s=[];
    for(let i=0;i<N;++i)
    {
        s.push(readLine().trim());
    }
    s.sort((a,b)=>a.length-b.length);
    let prev=s[0];
    for(let i=1;i<N;++i)
    {
        if(prev.length==s[i].length)
        {
            if(prev!=s[i])
            {
                console.log("NO");
                return;
            }
        }
        else
        {
            if(!s[i].includes(prev))
            {
                console.log("NO");
                return;
            }
        }
        prev=s[i];
    }
    console.log("YES");
    for(let i=0;i<N;++i)
    {
        console.log(s[i]);
    }
}

var n = parseInt(readline());

input = [];

for(var i = 0; i < n; i++){
    input.push(readline());
}

input.sort(function(a, b) {
    return a.length - b.length;
});

solve(input);

function solve(input) {
    for(var i = 0; i < input.length - 1; i++) {
        if(input[i+1].search(input[i]) == -1) {
            print("NO");
            return;
        }
    }

    print("YES");
    for(var i = 0 ;i < input.length;i ++) {
        print(input[i]);
    }
}