Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \le i \le n-1$$$), this condition must be satisfied: $$$$$$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2$$$$$$For example, the arrays $$$[1, 2, 3, 4, 3]$$$, $$$[1, 1, 1]$$$ and $$$[5, 10]$$$ are dense. And the arrays $$$[5, 11]$$$, $$$[1, 4, 2]$$$, $$$[6, 6, 1]$$$ are not dense.You are given an array $$$a$$$ of $$$n$$$ integers. What is the minimum number of numbers you need to add to an array to make it dense? You can insert numbers anywhere in the array. If the array is already dense, no numbers need to be added.For example, if $$$a=[4,2,10,1]$$$, then the answer is $$$5$$$, and the array itself after inserting elements into it may look like this: $$$a=[4,2,\underline{\textbf{3}},\underline{\textbf{5}},10,\underline{\textbf{6}},\underline{\textbf{4}},\underline{\textbf{2}},1]$$$ (there are other ways to build such $$$a$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 50$$$).

For each test case, output one integer — the minimum number of numbers that must be added to the array to make it dense.

NoteThe first test case is explained in the statements.In the second test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},3]$$$.In the third test case, you can insert two elements, $$$a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1]$$$.In the fourth test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},4,2]$$$.In the fifth test case, the array $$$a$$$ is already dense.

let lines = require('fs').readFileSync(0).toString().split('\n');
let index = 0;
const readline = () => lines[index++];

let t = Number(readline());
for(let i = 0; i < t; i++) {
    readline();
    let arr = readline().split(' ').map(i=> +i);
    let result = 0;
    for(let j = 1; j < arr.length; j++) {
        let min = arr[j];
        let max = arr[j - 1];
        if (max < min) [min, max] = [max, min]
        while(min * 2 < max) {
            min *= 2
            result++
        }
    }
    console.log(result)
}

let {stdin} = process

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

let string = '';
let line = 0;

stdin.on('data', input => string += input);
stdin.on('end', () => {
    string = string.trim().split('\n').map(string => string.trim());
    main();
});

const readline = () => string[line++];

function main(){
 let t = Number(readline());
 for(let i = 0; i < t; i++) {
     readline();
     let arr = readline().split(' ').map(i=> +i);
     let result = 0;
     for(let j = 1; j < arr.length; j++) {
         let min = arr[j];
         let max = arr[j - 1];
         if (max < min) [min, max] = [max, min]
         while(min * 2 < max) {
             min *= 2
             result++
         }
     }
     console.log(result)
 }
}

let {stdin} = process

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

let string = '';
let line = 0;

stdin.on('data', input => string += input);
stdin.on('end', () => {
    string = string.trim().split('\n').map(string => string.trim());
    main();
});

const readline = () => string[line++];

function main(){
 let t = Number(readline());
 for(let i = 0; i < t; i++) {
     readline();
     let arr = readline().split(' ').map(i=> +i);
     let result = 0;
     for(let j = 1; j < arr.length; j++) {
         let min = arr[j];
         let max = arr[j - 1];
         if (max < min) [min, max] = [max, min]
         while(min * 2 < max) {
             min *= 2
             result++
         }
     }
     console.log(result)
 }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
 var a = parseInt(readline());
while (a--) {
   var ok =parseInt(readline());
   var arr = readline().split(" ")
   var c = 0;

   for (let i = 0; i < arr.length - 1; i++) {
      var max=Math.max(arr[i],arr[i+1])
     var min=Math.min(arr[i],arr[i+1]);
     while(min*2<max){
      //  console.log(a[i],min,max);
        min=min*2
        c++;
     }

   }

   console.log(c)

   // var [a,b,c] = readline().split(" ").map(Number);
   // var arr=new Array();
   // var num=1,ans;
   // for(let i=0;i<a;i++){
   //    arr[i]=new Array()
   //    for(let j=0;j<b;j++){
   //    arr[i][j]=num;
   //    if(num==c)
   //    ans=c
   //    num++;
   //    }
   // }
   // console.log(arr);
}

}

const solutionA = (inputs) => {
  // helper
  const getAns = (elements, array) => {
    let ans = 0;
    for (let i = 1; i < elements; i++) {
      const [ge, le] = array[i - 1] > array[i] ? [i - 1, i] : [i, i - 1];
      if (array[ge] / array[le] <= 2) continue;
      for (let j = array[le] * 2; j < array[ge]; j *= 2) {
        ans += 1;
      }
    }
    return ans;
  };

  const [, ...rest] = inputs;
  const q = rest.length;
  const ans = [];
  for (let i = 0; i < q; i += 2) {
    const elements = +rest[i];
    const array = rest[i + 1].split(" ").map((e) => Number(e));
    ans.push(getAns(elements, array));
  }
  console.log(ans.join("\n"));
};

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

const q = [];
rl.on("line", (line) => {
  line
    ? q.push(line)
    : rl.close();
}).on("close", () => {
  solutionA(q);
  process.exit();
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var t = lines[0];
    var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 0; j < e - 1; j++){
                var min = Math.min(k[j], k[j + 1]);
                var max = Math.max(k[j], k[j + 1]);
                while(max / min > 2){
                    max = Math.ceil(max / 2);
                    ans++;
                }
            }
            console.log(ans);
        }
    }
});

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

process.stdin.on('data' , data=>{
    input += data;
});
process.stdin.on('end' , ()=>{
    main(input);
});

function find(num1, num2){
    if(num1 < num2){
        let temp = num2;
        num2 = num1;
        num1 = temp;
    }
    let count = 0;
    for (let i = 0; num1 > num2; i++) {
        num1 = num1 / 2;
        count++;
    }
    return count - 1;
}

function main(input){
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let length = +input[z++];
        let arr = input[z++].split(' ').map(x=>Number(x));
        let swap = 0;
        for (let i = 0; i < length - 1; i++) {
            if(arr[i]*2 < arr[i+1] || arr[i] / 2 > arr[i+1]){
                swap = swap + find(arr[i], arr[i+1]);
            }
        }
        console.log(swap);
    }
}

'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++];
}

// Actual code...

function numBetween(a, b) {
    const small = Math.min(a, b);
    const big = Math.max(a, b);
    if (big / small > 2) return 1 + numBetween(small * 2, big);
    return 0;
}

function main() {
    const numCases = parseInt(readline());
    for (let i = 0; i < numCases; i++) {
        const numTerms = readline();
        const arr = readline()
            .split(" ")
            .map(str => parseInt(str));
        let numNeeded = 0;
        for (let j = 0; j < numTerms - 1; j++) {
            numNeeded += numBetween(arr[j], arr[j + 1]);
        }
        console.log(numNeeded);
    }
}

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let t = nl.num();
    let ans = [];
    for(let i = 0; i < t; i++) {
        let n = nl.num();
        let a = nl.nums();
        let cnt = 0;
        for(let j = 0; j < n - 1; j++){
            let x = a[j];
            let y = a[j + 1];
            if (x > y) {
                [x, y] = [y, x];
            }
            while(x * 2 < y) {
                cnt++;
                x *= 2;
            }
        }
        ans.push(cnt);
    }
	console.log(ans.join('\n'));

};

process.stdin.on('end', sol);

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

let input = [];

rl.on("line", (ln) => {
  input.push(ln);
}).on("close", () => {
  const T = input.shift();

  for (let i = 0; i < T; i++) {
    const N = input.shift();
    const nums = input.shift().split(" ");

    let sum = 0;
    for (let j = 0; j < N - 1; j++) {
      const min = Math.min(nums[j], nums[j + 1]);
      const max = Math.max(nums[j], nums[j + 1]);
      const div = max / min;

      let times = Math.log(div) / Math.log(2);
      times = times % 1 === 0 && times > 0 ? times - 1 : Math.floor(times);
      sum += times;
    }
    console.log(sum);
  }
});

/**
 * 02/19/21 morning
 * https://codeforces.com/contest/1490/problem/A
 */

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

const solve = (n, a) => {
    let res = 0;
    for (let i = 0; i + 1 < n; i++) {
        let min = mi(a[i], a[i + 1]);
        let max = mx(a[i], a[i + 1]);
        while (max > min && max / min > 2) {
            max = Math.ceil(max / 2);
            res++;
        }
    }
    pr(res);
};

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

main()

let fs = require("fs");
let allInput = fs.readFileSync(0).toString(); // STDIN_FILENO = 0
let allLines=allInput.split('\n');
let line=0;
const T=parseInt(allLines[line++]);
function count(a, b) {
    let c=0;
    while (a*2<b) {
        a*=2;
        c++;
    }
    while (b*2<a) {
        b*=2;
        c++;
    }
    return c;
}

for (let tt=0; tt<T; tt++) {
    const n=parseInt(allLines[line++]);
    const a=allLines[line++].split(" ").map(Number);
    let add=0;
    for (let ind=0; ind+1<n; ind++) {
        add+=count(a[ind], a[ind+1]);
    }
    console.log(add);
}

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 * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        solve()
        process.exit(0)
    }
})

function diff(max, min) {
    let res = 0
    while (max > min) {
        if ((Math.ceil(max / min)) > 2) {
            res++
            if (max % 2 === 0) max /=2
            else max = Math.floor(max / 2) + 1
        } else {
            return res
        }
    }
    return res
}

function isDense(arr) {
    let counter = 0
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] >= arr[i + 1]) {
            if (arr[i] / arr[i + 1] > 2) counter += diff(arr[i], arr[i + 1])
        } else {
            if (arr[i + 1] / arr[i] > 2) counter += diff(arr[i + 1], arr[i])
        }
    }
    console.log(counter)
}

function solve() {
    for (let i = 1; i < inputArr.length; i += 2) {
        isDense(inputArr[i])
    }
}

/*
 * File Created: Tuesday, 16th February 2021 3:32:09 pm
 * Author: Lukas Rimkus
 */

 'use-strict'

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

 let data = '';
 let currentLine = 0;

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

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

     let testCases = parseInt(data.shift());

     while(testCases--) {

        const n = parseInt(readLine());

        const arr = readLine().split(' ').map(Number);

        const res = a(n,arr);

        console.log(res)
     }
 });

 function get_ints() {
     return data.shift().split(' ').map(Number);
 }

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

 function a(n,arr){
     let count = 0;
     for(let i = 0 ; i < n - 1; i++){
         let max = Math.max(arr[i], arr[i+1]);
         let min = Math.min(arr[i], arr[i+1]);
         if(max/min > 2){
             while(min * 2 < max){
                 max = max / 2;
                 count++;
             }
         } else{
             continue;
         }
     }
     return count;
 }

 module.exports = a;

'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++];
}
/**
2
3 7
24 25 27
10 7
51 52 53 54 55 56 57 58 59 60
**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

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

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let n = readline();
    let a = readline().split(" ").map(Number);

    let count = 0;
    //console.log(a);
    for(let i=0;i<a.length - 1;i++) {
        let max = Math.max(a[i], a[i+1]);
        let min = Math.min(a[i], a[i+1]);
        //console.log(max / min)
        while((max / min) > 2) {
            max = Math.ceil(max / 2);
            count++;
        }
    }

    console.log(count);

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    var x = Number(readline())
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline())

        var a = readline().split(' ').map((x, i) => {
            return parseInt(x)
        })
        var res = 0
        for (var i = 0; i < a.length - 1; i++) {
            var min = Math.min(a[i + 1], a[i])
            var max = Math.max(a[i + 1], a[i])
            while (min*2 < max){
                min *=2
                res++
            }
            // console.log(res)
        }
        console.log(res)

    })

}

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

//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 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 N = nextInt();
		var list = nextIntArray(N);
		var output = 0;
		for(var j = 0; j < N - 1; j++){
			var max = Math.max(list[j], list[j + 1]);
			var min = Math.min(list[j], list[j + 1]);
			while(max > min * 2){
				min *= 2;
				output++;
			}
		}
		myout(output);
	}
}

var tc = parseInt(readline());
while(tc--) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    arr.forEach((value, index) => {
        if (index) {
            var min = Math.min(arr[index], arr[index-1]);
            var max = Math.max(arr[index], arr[index-1]);
            while (true) {
                if (min * 2 >= max) break;
                min *= 2;
                ++ans;
            }
        }
    });
    print(ans);
}

var tc = parseInt(readline())
while(tc--) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    // for(var i = 1; i < arr.length; i++) {
    //     if (i) {
    //         var min = Math.min(arr[i], arr[i-1]);
    //         var max = Math.max(arr[i], arr[i-1]);
    //         while (true) {
    //             if (min * 2 >= max) {
    //                 break;
    //             }
    //             min *= 2;
    //             ++ans;
    //         }
    //     }
    // }
    arr.forEach((val, i) => {
        if (i) {
            var min = Math.min(arr[i], arr[i-1]);
            var max = Math.max(arr[i], arr[i-1]);
            while (true) {
                if (min * 2 >= max) {
                    break;
                }
                min *= 2;
                ++ans;
            }
        }
    });
    print(ans)
}

var tc = parseInt(readline())
while(tc--) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    for(var i = 1; i < arr.length; i++) {
        if (i) {
            var min = Math.min(arr[i], arr[i-1]);
            var max = Math.max(arr[i], arr[i-1]);
            while (true) {
                if (min * 2 >= max) {
                    break;
                }
                min *= 2;
                ++ans;
            }
        }
    }
    print(ans)
}

var tc = parseInt(readline())
while(tc--) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    for(var i = 1; i < arr.length; i++) {
        if (i) {
            var min = Math.min(arr[i], arr[i-1]);
            var max = Math.max(arr[i], arr[i-1]);
            while (true) {
                if (min * 2 >= max) {
                    break;
                }
                min *= 2;
                ++ans;
            }
        }
    }
    // write(ans + '\n')
    print(ans)
}

var tc = parseInt(readline())
while(tc--) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    for(var i = 1; i < arr.length; i++) {
        if (i) {
            var min = Math.min(arr[i], arr[i-1]);
            var max = Math.max(arr[i], arr[i-1]);
            while (true) {
                if (min * 2 >= max) {
                    break;
                }
                min *= 2;
                ++ans;
            }
        }
    }
    write(ans + '\n')
}

var tc = parseInt(readline())
for(var t = 1; t <= tc; t++) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var ans = 0;
    for(var i = 1; i < arr.length; i++) {
        if (i) {
            var min = Math.min(arr[i], arr[i-1]);
            var max = Math.max(arr[i], arr[i-1]);
            while (true) {
                if (min * 2 >= max) {
                    break;
                }
                min *= 2;
                ++ans;
            }
        }
    }
    write(ans + '\n')
}

var tc = parseInt(readline())
for(var i = 1; i <= tc; i++) {
    var n = readline();
    var arr = readline().split(" ").map(i => Number(i));
    var result = 0;
    for(var j = 1; j < arr.length; j++) {
        var now = arr[j];
        var before = arr[j-1]
        if (now > before) {

        while (now > before * 2) {
            before *= 2
            result++
        }
        } else if (before > now * 2) {
            while (before > now * 2) {
                now *= 2
                result++
            }
        }
    }
    write(result + '\n')
}

var tc = parseInt(readline())
for(var i = 1; i <= tc; i++) {
    var n = readline();
    var arr = readline().split(' ').map(i => Number(i));
    var result = 0;
    for(var j = 1; j < arr.length; j++) {
        var now = arr[j];
        var before = arr[j-1]
        if (now > before) {

        while (now > before * 2) {
            before *= 2
            result++
        }
        } else if (before > now * 2) {
            while (before > now * 2) {
                now *= 2
                result++
            }
        }
    }
    write(result + '\n')
}

var num = parseInt(readline())
for(var i = 0; i < num; i++) {
    readline();
    var arr = readline().split(' ').map(i => Number(i));
    var result = 0;
    for(var j = 1; j < arr.length; j++) {
        var now = arr[j];
        var before = arr[j-1]
        if (now > before) {

        while (now > before * 2) {
            before *= 2
            result++
        }
        } else if (before > now * 2) {
            while (before > now * 2) {
                now *= 2
                result++
            }
        }
    }
    write(result + '\n')
}

var num = readline() * 1
for(var i = 0; i < num; i++) {
    readline();
    var arr = readline().split(' ').map(i => Number(i));
    var result = 0;
    for(var j = 1; j < arr.length; j++) {
        var now = arr[j];
        var before = arr[j-1]
        if (now > before) {

        while (now > before * 2) {
            before *= 2
            result++
        }
        } else if (before > now * 2) {
            while (before > now * 2) {
                now *= 2
                result++
            }
        }
    }
    write(result + '\n')
}

var row = readline().split(" ").map(function(x) { return parseInt(x); });
var n = row[0]; //input

for(var times = 0; times < n; times++) {
    var l = readline().split(" ").map(function(x) { return parseInt(x); })[0];
    var a = readline().split(" ").map(function(x) { return parseInt(x); });
    var result = 0;
    for(var i = 1; i < l; i++) {
        var previous = a[i - 1];
        var current = a[i];
        var max = Math.max(previous, current);
        var min = Math.min(previous, current);
        while(max / min > 2) {
            result++;
            var halfMax = Math.ceil(max / 2);
            max = Math.max(halfMax, min);
            min = Math.min(halfMax, min);
        }
    }
    write(result + "\n" );
}

var row = readline().split(" ").map(function(x) { return parseInt(x); });
var n = row[0]; //input

for(var times = 0; times < n; times++) {
    var l = readline().split(" ").map(function(x) { return parseInt(x); })[0];
    var a = readline().split(" ").map(function(x) { return parseInt(x); });
    var result = 0;
    for(var i = 1; i < l; i++) {
        var previous = a[i - 1];
        var current = a[i];
        var max = Math.max(previous, current);
        var min = Math.min(previous, current);
        while(max / min > 2) {
            result++;
            var halfMax = Math.ceil(max / 2);
            max = Math.max(halfMax, min);
            min = Math.min(halfMax, min);
        }
    }
    write(result + "\n");
}

var t = Number(readline());

while (t--) {
    var len = Number(readline());
    var arr = readline().split(" ");
    var ans = 0;

    for (var i = 0; i < len - 1; i++) {
        var a = Number(arr[i]);
        var b = Number(arr[i + 1]);
        var min = Math.min(a, b);

        while (min * 2 < Math.max(a, b)) {
            ans++;
            min *= 2;
        }

    }

    print(ans);
}

var t=parseInt(readline(), 10);
for (var i=0; i<t; i++) {
    var n=parseInt(readline(), 10);
    var w=readline().split(" ");
    var res=0;
    for (var j=1; j<n; j++) {
        var a=parseInt(w[j], 10);
        var b=parseInt(w[j-1], 10);
        var y=Math.log2(Math.max(a, b)/Math.min(a, b));
        if (y==Math.floor(y)&&y!=0) {
            y-=1;
        }
        res+=Math.floor(y);
    }
    print(res);
}

var Case = parseInt( readline() );
while(Case--){
  var n = readline();
  var A = readline().split(' ').map(i => Number(i));
  var Ans = 0;
  A.forEach((val,index) =>{
     if(index){
        var min = Math.min(A[index], A[index-1]);
        var max = Math.max(A[index], A[index-1]);
        while (min*2 < max) {
            min *= 2;
            Ans++;
        }
     }
  });
  print(Ans);
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
  // your code goes here
  var a = readline();
while (a--) {
   var arr = readline().split(" ")
   var c = 0;

   for (let i = 0; i < arr.length - 1; i++) {
      var max=Math.max(arr[i],arr[i+1])
     var min=Math.min(arr[i],arr[i+1]);
     while(min*2<max){
      //  console.log(a[i],min,max);
        min=min*2
        c++;
     }

   }

   console.log(c)

   // var [a,b,c] = readline().split(" ").map(Number);
   // var arr=new Array();
   // var num=1,ans;
   // for(let i=0;i<a;i++){
   //    arr[i]=new Array()
   //    for(let j=0;j<b;j++){
   //    arr[i][j]=num;
   //    if(num==c)
   //    ans=c
   //    num++;
   //    }
   // }
   // console.log(arr);
}

}

var row = readline().split(" ").map(function(x) { return parseInt(x); });
var n = row[0]; //input

for(var times = 0; times < n; times++) {
    var l = readline().split(" ").map(function(x) { return parseInt(x); })[0];
    var a = readline().split(" ").map(function(x) { return parseInt(x); });
    var result = 0;
    var current = [0,0];
    current[-1] = 0;
    var max = 0;
    var currentMax = 0;
    for(var i = 0; i < l; i++) {
        var currentIdx = a[i] % 3 == 2? -1 : a[i] % 3;
        current[currentIdx]++;
        if(current[currentIdx] > max || (current[currentIdx] == max && currentIdx < currentMax)) {
            max = current[currentIdx];
            currentMax = currentIdx;
        }
    }
    var equal = l / 3;
    var holding = 0;
    for(var times2 = 1; times2 < 3; times2++) {
        holding = current[currentMax] + holding - equal;
        result += holding;
        currentMax = currentMax + 1 > 1 ? -1 : currentMax + 1;
    }
    write(result + "\n");
}