#Python solution to "Garden Hopping" from 2025 CS@UCF Summer camp

#This solution uses dynamic programming and memoization

test_count = int(input())

for _ in range(test_count):
    stone_count = int(input())

    stones = []

    #since all numbers have 1 as a divisor, we can set default costs to be the cost if we only made steps of size 1
    costs = []

    total_cost = 0
    for price in map(int,input().split()):
        total_cost += price
        costs.append(total_cost)
        stones.append(price)

    # We can then compute the stones that can be jumped to next in O(sqrt(N)) by observing that if "a" divides "b"
    # then there is some integer "c" such that "a" * "c" = "b". Notice that if "a" <= sqrt("b"), then
    # "c" >= sqrt("b"), and that there are no integer pairs that multiply to "b"
    # such that both numbers are greater than the square root of "b". As such, we only need to directly check
    # candidate divisors <= sqrt("b"), and they will automatically find all divisors >= sqrt("b")

    # "start" is where we will pick up from for our DP. By sweeping from left to right, we can
    # ensure that we've found the best of all possible paths to each space we visit
    for start in range(stone_count):
        small_divisor = 1
        # This is another way of making sure divisor <= sqrt(start),
        # without having to deal with error-prone floating point numbers
        # We use ("start" + 1) to make our 0-indexed array match the 1-indexed problem statement
        while((small_divisor * small_divisor) <= (start + 1) and (start + small_divisor) < stone_count):
            if(((start +1) % small_divisor) == 0):
                large_divisor = (start + 1) // small_divisor
                # costs[start + divisor] will end up storing the cheapest of all possible 
                # paths to stone (start + divisor) where "divisor" is either the large or small divisor of
                # start. ("a" or "c") in the pure mathematics explanation
                costs[start + small_divisor] = min(costs[start + small_divisor], costs[start] + stones[start + small_divisor])

                if((start + large_divisor) < stone_count):
                    costs[start + large_divisor] = min(costs[start + large_divisor], costs[start] + stones[start + large_divisor])

            small_divisor += 1

    print(costs[stone_count - 1])

