While at Iceberg Corporation, Oussama worked on a high-frequency cryptocurrency trading system. He tried to implement it using multiple programming languages, but they were all slow. Therefore, he decided to make his own programming language and use it internally in the company. He prepared the specifications and sent them to Rami, who will write a compiler for that. While doing this task, Rami encountered a problem : sometimes, Rami will take some $$$N$$$ elements of different sizes and try to store them in memory. The $$$i$$$th element has size $$$2^{S_i}$$$.
Computer systems are very complicated. You can think of the memory as a block of cells. The cells are numbered 0,1,2,3, and so on (To ease things, you may assume that the memory is infinite). Each cell can store one unit of storage, and the storage starts from position 0. For example, if you were storing 3 pieces of sizes $$${2,4,1}$$$, the first element will occupy cells $$${0,1}$$$, the second will occupy cells $$${2,3,4,5}$$$, while the third will occupy cell 6. The smallest cell occupied by an element is called memory address. In the previous example, the address at which we stored our elements are 0,2,6. Now here is the catch: in reality, computers only store elements of size $$$2^{S_i}$$$ in addresses divisible by $$$2^{S_i}$$$. This is done to make access faster. For example, elements of size 2 can only be stored in addresses $$${0,2,4,6,...}$$$, while elements of size 4 can occupy addresses $$${0,4,8,12,...}$$$. So in the previous example, the placements of the elements isn't valid. What a computer will do in reality is place the element 2 at address 0, leave cells 2 and 3 empty, and place the element of size 4 at address 4, then place element of size 1 at address 8, occupying a total of 9 units of storage. Notice that we wasted 2 units of storage so we can align the element of size 4 with address 4. This problem is called Memory alignment. (You thought this was a programming contest, not a computer architecture course, didn't you?)
While trying to optimize the runtime performance of the new programming language, he wrote an algorithm to optimize the placement of elements in memory. In fact, the algorithm won't take elements in order but will rearrange them in some order to minimize the total space occupied by them. Oussama wanted to test Rami's algorithm, so he asks you to write an algorithm that outputs the minimum possible space occupied by the elements.
The first line contains the number of testcases $$$1 \le T \le 10^3$$$.
The first line of each testcase contains only one integer $$$ 1\le N \le 10^3.$$$
The second line of each testcase contains $$$N$$$ integers $$$ 0 \le S_1, \dots ,S_N \le 20$$$.
Please note that the size of element $$$i$$$ is $$$2^{S_i}$$$.
Print a single integer : the minimum possible memory occupied by the elements.
330 0 031 2 231 2 4
3 10 22