This page is still under construction.

Parts of this page are still being built. What you see may change.

Magazine Delivery

Time limit1sMemory limit128 MB

Summary
Three cars start at L1 and must deliver to locations in strict order 2,3,...,N, with only one car moving at a time; minimize the total completion time.
Level

Hard8 of 10

Topics
Dynamic programming, Shortest path, Implementation, Greedy
Solved
No attempts yet

Problem

A courier company in Tehran must deliver magazines to NN locations in the city, labeled L1L_1 through LNL_N. The company assigns 3 cars to the job. At time 00, all 3 cars and the magazines are at L1L_1. There are plenty of magazines at L1L_1, and a car may load as many as it wants. A copy must be delivered to every location, subject to the following rules:

  • For every i=2,…,Ni = 2, \dots, N, the delivery to LiL_i may happen only after the delivery to Li−1L_{i-1} is complete.
  • At any moment only one of the three cars is driving; the other two rest at their current locations.

The time for a car to travel between LiL_i and LjL_j (in either direction) is a positive integer Di,jD_{i,j}.

Arrange the delivery schedule so that the time by which all NN locations have received magazines is minimized. Write a program to compute this minimum completion time.

Input

The input contains MM instances of the problem (1≤M≤101 \le M \le 10). The first line is MM. The instances follow one after another.

Each instance begins with a line containing NN (N≤30N \le 30). The next N−1N-1 lines describe the distances: line ii (for i=1,…,N−1i = 1, \dots, N-1) contains Di,jD_{i,j} for j=i+1,…,Nj = i+1, \dots, N, separated by spaces. Distances are symmetric (Di,j=Dj,iD_{i,j} = D_{j,i}).

Output

Print MM lines, one per instance. Each line is the minimum time needed to deliver magazines to all NN locations of that instance.

Examples3

  1. Example 1

    Input
    1
    5
    10 20 3 4
    5 10 20
    8 18
    19
    
    Expected output
    22
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    0
    
  3. Example 3

    Input
    1
    2
    7
    
    Expected output
    7