← Home
```go
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	buf, _ := io.ReadAll(os.Stdin)
	pos := 0

	nextInt := func() int {
		for pos < len(buf) && (buf[pos] < '0' || buf[pos] > '9') && buf[pos] != '-' {
			pos++
		}
		if pos >= len(buf) {
			return 0
		}
		sign := 1
		if buf[pos] == '-' {
			sign = -1
			pos++
		}
		res := 0
		for pos < len(buf) && buf[pos] >= '0' && buf[pos] <= '9' {
			res = res*10 + int(buf[pos]-'0')
			pos++
		}
		return res * sign
	}

	t := nextInt()
	if t == 0 {
		return
	}

	for tc := 0; tc < t; tc++ {
		n := nextInt()
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			a[i] = int64(nextInt())
		}
		b := make([]int64, n)
		for i := 0; i < n; i++ {
			b[i] = int64(nextInt())
		}

		var dp [3][3]int64
		const MinInt = -int64(1e18)
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[i][j] = MinInt
			}
		}
		dp[0][0] = 0

		for i := 0; i < n; i++ {
			c1 := a[i]
			if b[i] > a[i] {
				c1 = b[i]
			}
			c2 := a[i] + b[i]

			var nextDp [3][3]int64
			for x := 0; x < 3; x++ {
				for y := 0; y < 3; y++ {
					nextDp[x][y] = MinInt
				}
			}

			for s1 := 0; s1 < 3; s1++ {
				for s2 := 0; s2 < 3; s2++ {
					active := 0
					if s1 == 1 {
						active++
					}
					if s2 == 1 {
						active++
					}
					
					var cost int64
					if active == 1 {
						cost = c1
					} else if active == 2 {
						cost = c2
					} else {
						cost = 0
					}

					var best int64 = MinInt
					for p1 := 0; p1 <= s1; p1++ {
						for p2 := 0; p2 <= s2; p2++ {
							if dp[p1][p2] > best {
								best = dp[p1][p2]
							}
						}
					}
					if best != MinInt {
						nextDp[s1][s2] = best + cost
					}
				}
			}
			dp = nextDp
		}

		var ans int64 = MinInt
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if dp[i][j] > ans {
					ans = dp[i][j]
				}
			}
		}
		fmt.Println(ans)
	}
}
```