import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { static BufferedReader br; static PrintWriter pw; public static void main(String[] args) throws Exception { br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); pw = new PrintWriter(System.out); for (int i = 0; i < t; i++) { solve(); } br.close(); pw.flush(); } static void solve() throws Exception { int n = Integer.parseInt(br.readLine()); String[] sa = br.readLine().split(" "); int[] a = new int[n + 2]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } long[] dp = new long[n + 3]; for (int i = 3; i < n + 3; i++) { dp[i] = Math.max(dp[i], dp[i - 1]); dp[i] = Math.max(dp[i], dp[i - 2]); int[] b = new int[3]; for (int j = 1; j <= 3; j++) { b[j - 1] = a[(i - j) % n]; } if (check(b)) { dp[i] = Math.max(dp[i], dp[i - 3] + a[i - 3]); } } pw.println(dp[n + 2]); } static boolean check(int[] a) { if (a[0] != a[2]) { if (a[0] < a[1] && a[1] > a[2]) return true; if (a[0] > a[1] && a[1] < a[2]) return true; } return false; } }