#!/usr/bin/ruby

n = gets.to_i
n.times do |_|
  k = gets.to_i
  ys = gets.chomp.split(" ").map {|x| x.to_i}

  ans = -1

  for j in 0..(2*k) do

    xs = ys.clone

    j.times do |_|
      (k-2).downto(2) do |i| 
        if (xs[i] == 0) and (xs[i-1] > 0) and (xs[i-2] > 0)
          xs[i] = xs[i-2]
          xs[i-1] -= 1
          xs[i-2] = 0
        end
      end
    end

    (1..(k-2)).each do |i|
      if (xs[i] > 0) and (xs[i-1] > 0)
        xs[i] -= 1
        xs[i+1] += xs[i-1]
        xs[i-1] = 0
      end
    end
    ans = [ans, xs[k-1]].max

  end

  puts ans

end