← Home
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

type PointVal struct {
	w int64
	i int
}

var partitions [][]int

func init() {
	var gen func(mask int, current []int)
	gen = func(mask int, current []int) {
		if mask == 15 {
			cp := make([]int, len(current))
			copy(cp, current)
			partitions = append(partitions, cp)
			return
		}
		first := 0
		for (mask & (1 << first)) != 0 {
			first++
		}
		unassigned := (15 ^ mask) &^ (1 << first)
		sub := unassigned
		for {
			newPart := (1 << first) | sub
			gen(mask|newPart, append(current, newPart))
			if sub == 0 {
				break
			}
			sub = (sub - 1) & unassigned
		}
	}
	gen(0, []int{})
}

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

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

	nextInt64 := func() int64 {
		for pos < len(data) && data[pos] <= ' ' {
			pos++
		}
		if pos >= len(data) {
			return 0
		}
		sign := int64(1)
		if data[pos] == '-' {
			sign = -1
			pos++
		}
		res := int64(0)
		for pos < len(data) && data[pos] > ' ' {
			res = res*10 + int64(data[pos]-'0')
			pos++
		}
		return res * sign
	}

	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	t := nextInt()
	for tc := 0; tc < t; tc++ {
		n := nextInt()
		x := make([]int64, n)
		for i := 0; i < n; i++ {
			x[i] = nextInt64()
		}
		y := make([]int64, n)
		for i := 0; i < n; i++ {
			y[i] = nextInt64()
		}
		c := make([]int64, n)
		var sumC int64
		for i := 0; i < n; i++ {
			c[i] = nextInt64()
			sumC += c[i]
		}

		var top [16][]PointVal
		for m := 1; m <= 15; m++ {
			top[m] = make([]PointVal, 0, 4)
		}

		for i := 0; i < n; i++ {
			v0 := -2 * x[i]
			v1 := 2 * x[i]
			v2 := -2 * y[i]
			v3 := 2 * y[i]

			for m := 1; m <= 15; m++ {
				w := -c[i]
				if (m & 1) != 0 {
					w += v0
				}
				if (m & 2) != 0 {
					w += v1
				}
				if (m & 4) != 0 {
					w += v2
				}
				if (m & 8) != 0 {
					w += v3
				}

				top[m] = append(top[m], PointVal{w, i})
				for j := len(top[m]) - 1; j > 0; j-- {
					if top[m][j].w > top[m][j-1].w {
						top[m][j], top[m][j-1] = top[m][j-1], top[m][j]
					} else {
						break
					}
				}
				if len(top[m]) > 4 {
					top[m] = top[m][:4]
				}
			}
		}

		maxScore := int64(math.MinInt64)

		for _, p := range partitions {
			if len(p) > n {
				continue
			}

			var dfs func(partIdx int, currentSum int64)
			used := make([]int, 0, 4)

			dfs = func(partIdx int, currentSum int64) {
				if partIdx == len(p) {
					if currentSum > maxScore {
						maxScore = currentSum
					}
					return
				}

				m := p[partIdx]
				for _, pv := range top[m] {
					already := false
					for _, u := range used {
						if u == pv.i {
							already = true
							break
						}
					}
					if !already {
						used = append(used, pv.i)
						dfs(partIdx+1, currentSum+pv.w)
						used = used[:len(used)-1]
					}
				}
			}

			dfs(0, 0)
		}

		fmt.Fprintln(out, sumC+maxScore)
	}
}