You are given an array A[ ] of positive integers. You have to pick up some values from the array. The only condition is that at least one value among any four consecutive values must be picked. That means at least one among A[i], A[i+1], A[i+2], A[i+3] has to be picked. The aim is to pick values in such a way that the sum of the values is minimized.

**Input: **

The first line of input contains a single integer **T** denoting the number of test cases.Then **T** test cases follow. Each test case consists of two lines. The first line contains an integer N denoting the size of the array. The Second line of each test case contains N space separated positive integers denoting the values/elements in the array A[ ].

**Output:**

Corresponding to each test case, in a new line, print the minimum possible sum of the values that can be selected.

**Constraints:**

1 ≤ **T** ≤ 10

1 ≤ **N **≤ 100000

1 ≤ **A[i] **≤ 100000

**Example:**

**Input**

1

5

1 2 3 1 2

**Output**

1

**Explanation**

At least one among any 4 consecutive numbers has to be picked.

Given: 1 2 3 1 2

we have to pick at least one from the first 4 that means from 1 2 3 1

we have to pick at least one from the last 4 that means from 2 3 1 2

if we pick the second last 1, we satisfy both the conditions and the sum is minimised.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

makeitdonesolo | 64 |

ShubhamJain18 | 64 |

Bishnu Dev Panda | 54 |

DanishBansal | 50 |

abhithakur588 | 50 |

Bishnu Dev Panda | 777 |

yk12 | 512 |

okayboss | 490 |

DevMittal | 472 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.