Timer is Running

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.

abnandi04 | 801 |

KshamaGupta | 412 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

anshusingh20112001 | 181 |

abnandi04 | 776 |

KshamaGupta | 296 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

afreensartaj131 | 170 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4748 |

Login to report an issue on this page.