More Garden Troubles

No attempts yetTime limit2sMemory limit128 MB

Problem

Mr. Wincenty owns a garden and is famously the sort of person who cannot stand yard work. Some time after his earlier troubles with fallen leaves, spring arrived and brought a new headache: weeds began sprouting all over the garden. One day, after long hours in his workshop, Mr. Wincenty walked into the garden holding a portable flamethrower.

The garden consists of NN plots numbered from 11 to NN. Plot ii holds a whole number of weeds cic_i. Firing the flamethrower once at plot ii halves the number of weeds in plot ii and in the neighboring plots i1i-1 and i+1i+1.

Here "halving" means integer division by 22 (rounding down): 88 weeds become 44, and 55 weeds become 22. You may also aim the flamethrower at the non-existent plots 00 or N+1N+1; in that case only plot 11 or only plot NN is reduced, respectively.

Determine the minimum number of times Mr. Wincenty must fire the flamethrower so that every plot ends up with 00 weeds.

Input

The first line contains an integer ZZ (1Z101 \le Z \le 10), the number of test cases. The test cases follow.

Each test case begins with a line containing one integer NN (1N1061 \le N \le 10^6), the number of plots in the garden. The next line contains NN space-separated integers cic_i (0ci1060 \le c_i \le 10^6), the number of weeds in each plot.

Output

For each test case, print on its own line the minimum number of times the flamethrower must be used.