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.

mantan_g | 267 |

tushki | 198 |

aksht7 | 182 |

ayush1101 | 128 |

namansharmacse17 | 110 |

ARUN_PUNDIR | 730 |

manishgupta8497 | 627 |

AMAN__JAIN | 625 |

Abhimanyu_kumar | 562 |

AJ786 | 541 |

blackshadows | 5335 |

Ibrahim Nash | 5223 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4584 |

Login to report an issue on this page.