package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
        //writer.Printf("%v\n", red)
        //writer.Printf("%v\n", green)
        //writer.Printf("%v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) int64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		aRes := a[i]
		bRes := binarySearchAscLessThan(b, aRes)
		cRes := binarySearchAscGreaterThan(c, aRes)
		tmp := compute(aRes, bRes, cRes)
        //writer.Printf("%d %d %d %d\n", aRes, bRes, cRes, tmp)
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func binarySearchAscLessThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
    curr := int64(0) // value here doesn't matter
    hasVal := false
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] < val {
            if !hasVal {
                curr = sl[m]
                hasVal = true
            } else if sl[m] > curr {
				curr = sl[m]
			}
			l = m + 1
		} else {
			r = m - 1
		}
	}
    if !hasVal {
        return sl[0]
    }
	return curr
}

func binarySearchAscGreaterThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
	curr := int64(0) // value here doesn't matter
    hasVal := false
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] > val {
            if !hasVal {
                curr = sl[m]
                hasVal = true
            } else if sl[m] < curr {
				curr = sl[m]
			}
			r = m - 1
		} else {
			l = m + 1
		}
	}
    if !hasVal {
        return sl[len(sl)-1]
    }
	return curr
}

func compute(a, b, c int64) int64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) int64 {
	return a * a
}

package main

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

const N = 100100
var nt int
var na, nb, nc int
var a[][] int
var Len[3] int

func findLeft(id int, val int) int {
	var l = 0
	var r = Len[id] - 1
	var pos = -1
	for l <= r {
		var mid = (l + r) >> 1
		if a[id][mid] <= val {
			pos = a[id][mid]
			l = mid + 1
		} else {
			r = mid - 1
		}
	}
	return pos
}

func findRight(id int, val int) int {
	var l = 0
	var r = Len[id] - 1
	var pos = -1
	for l <= r {
		var mid = (l + r) >> 1
		if a[id][mid] >= val {
			pos = a[id][mid]
			r = mid - 1
		} else {
			l = mid + 1
		}
	}
	return pos
}

func min(a uint64, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func comp(a int, b int, c int) uint64 {
	var d1 = int64(a) - int64(b)
	var d2 = int64(a) - int64(c)
	var d3 = int64(b) - int64(c)
	return uint64(d1 * d1 + d2 * d2 + d3 * d3)
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d\n", &nt)
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d %d %d\n", &na, &nb, &nc)
		a = make([][]int, 3)
		a[0] = make([]int, na)
		a[1] = make([]int, nb)
		a[2] = make([]int, nc)
		Len[0] = na
		Len[1] = nb
		Len[2] = nc

		for i := 0; i < na; i++ {
			fmt.Fscanf(reader,"%d", &a[0][i])
		}
		fmt.Fscanf(reader, "\n")
		for i := 0; i < nb; i++ {
			fmt.Fscanf(reader,"%d", &a[1][i])
		}
		fmt.Fscanf(reader, "\n")
		for i := 0; i < nc; i++ {
			fmt.Fscanf(reader, "%d", &a[2][i])
		}
		fmt.Fscanf(reader, "\n")

		for i := 0; i < 3; i++ {
			sort.Ints(a[i])
		}

		var ret = uint64(math.MaxUint64)
		for i := 0; i < 3; i++ {
			for _, val := range a[i] {
				for j := 0; j < 3; j++ {
					for k := 0; k < 3; k++ {
						if i != j && i != k && j != k {
							var L = findLeft(j, val)
							var R = findRight(k, val)
							if L == -1 || R == -1 {
								continue
							}
							ret = min(ret, comp(L, val, R))
						}
					}
				}

			}
		}
		fmt.Fprintf(writer, "%d\n", ret)
	}

}

// https://codeforces.com/contest/1337/problem/D
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

func main () {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReaderSize(os.Stdin, 1000*1000)
	output := bufio.NewWriterSize(os.Stdout, 1000*1000)
	fmt.Fscanln(input, &T)

	for i := 0; i < T; i++ {
		var r, g, b int
		fmt.Fscan(input, &r, &g, &b)
		rs := make([]uint64, r)
		gs := make([]uint64, g)
		bs := make([]uint64, b)
		for i := 0; i < r; i++ {
			fmt.Fscan(input, &rs[i])
		}
		for i := 0; i < g; i++ {
			fmt.Fscan(input, &gs[i])
		}
		for i := 0; i < b; i++ {
			fmt.Fscan(input, &bs[i])
		}

		sort.Slice(rs, func (i, j int) bool {return rs[i] < rs[j]})
		sort.Slice(gs, func (i, j int) bool {return gs[i] < gs[j]})
		sort.Slice(bs, func (i, j int) bool {return bs[i] < bs[j]})
		fmt.Fprintln(output, solve(rs, gs, bs))
	}

	output.Flush()
}

func solve(rs, gs, bs []uint64) uint64 {
	ans := uint64(18e18)

	for i := 0; i < len(rs); i++ {
		ans = min(ans, calc(rs[i], gs, bs))
		ans = min(ans, calc(rs[i], bs, gs))
	}
	for i := 0; i < len(gs); i++ {
		ans = min(ans, calc(gs[i], rs, bs))
		ans = min(ans, calc(gs[i], bs, rs))
	}
	for i := 0; i < len(bs); i++ {
		ans = min(ans, calc(bs[i], gs, rs))
		ans = min(ans, calc(bs[i], rs, gs))
	}

	return ans
}

func calc(y uint64, xs, zs []uint64) uint64 {
	xi := sort.Search(len(xs), func(i int) bool {return xs[i] >= y})
	zi := sort.Search(len(zs), func(i int) bool {return zs[i] >= y})
	if xi == len(xs) {
		xi--
	}
	if zi == len(zs) {
		return uint64(18e18)
	}

	x, z := xs[xi], zs[zi]
	if x > y {
		if xi == 0 {
			return uint64(18e18)
		}
		x = xs[xi - 1]
	}
	if x > y {
		panic("invalid")
	}

	return (x-y)*(x-y) + (y-z)*(y-z) + (z-x)*(z-x)
}

func min(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	unique := func(a []int) []int {
		n := len(a)
		j := 0
		for i := 1; i < n; i++ {
			if a[j] != a[i] {
				j++
				a[j] = a[i]
			}
		}
		return a[:j+1]
	}
	orderP3 := [6][3]int{{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}
	//upperBound := func(a []int, x int) int { return sort.Search(len(a), func(i int) bool { return a[i] > x }) }
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	calcSum := func(x, y, z int64) int64 { return (x-y)*(x-y) + (y-z)*(y-z) + (x-z)*(x-z) }

	solve := func(_case int) (ans int64) {
		ans = math.MaxInt64
		n := make([]int, 3)
		for i := range n {
			Fscan(in, &n[i])
		}
		a := [3][]int{}
		for i := range a {
			a[i] = make([]int, n[i])
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			sort.Ints(a[i])
			a[i] = unique(a[i])
		}
		for _, p3 := range orderP3 {
			b := [3][]int{}
			for i, p := range p3 {
				b[i] = a[p]
			}
			j := 0
			for _, v := range b[0] {
				for ; j < len(b[1]) && b[1][j] < v; j++ {
				}
				if j == len(b[1]) {
					break
				}
				w := b[1][j]

				mid := (v + w) >> 1
				lowK := sort.SearchInts(b[2], mid)

				for k := lowK - 3; k < lowK+3; k++ {
					if k >= 0 && k < len(b[2]) {
						sum := calcSum(int64(v), int64(w), int64(b[2][k]))
						ans = min(ans, sum)
					}
				}
			}
		}
		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve(_case))
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	unique := func(a []int) []int {
		n := len(a)
		j := 0
		for i := 1; i < n; i++ {
			if a[j] != a[i] {
				j++
				a[j] = a[i]
			}
		}
		return a[:j+1]
	}
	orderP3 := [6][3]int{{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}
	calc := func(x, y, z int64) int64 { return (x-y)*(x-y) + (y-z)*(y-z) + (x-z)*(x-z) }

	var t int
	n := [3]int{}
	for Fscan(in, &t); t > 0; t-- {
		for i := range n {
			Fscan(in, &n[i])
		}
		a := [3][]int{}
		for i, l := range n {
			a[i] = make([]int, l)
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			sort.Ints(a[i])
			a[i] = unique(a[i])
		}
		ans := int64(9e18)
		for _, p3 := range orderP3 {
			b := [3][]int{}
			for i, p := range p3 {
				b[i] = a[p]
			}
			j := 0
			for _, v := range b[0] {
				for ; j < len(b[1]) && b[1][j] < v; j++ {
				}
				if j == len(b[1]) {
					break
				}
				w := b[1][j]
				lowK := sort.SearchInts(b[2], (v+w)/2)
				for k := lowK - 1; k <= lowK+1; k++ {
					if k >= 0 && k < len(b[2]) {
						if sum := calc(int64(v), int64(w), int64(b[2][k])); sum < ans {
							ans = sum
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("%v\n", red)
		//writer.Printf("%v\n", green)
		//writer.Printf("%v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) int64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		aRes := a[i]
		bRes := binarySearchLargestValueLessThan(b, aRes)
		cRes := binarySearchSmallestValueGreaterThan(c, aRes)
		tmp := compute(aRes, bRes, cRes)
		//writer.Printf("%d %d %d %d\n", aRes, bRes, cRes, tmp)
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func binarySearchLargestValueLessThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
	curr := sl[0]
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] < val {
			if sl[m] > curr {
				curr = sl[m]
			}
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return curr
}

func binarySearchSmallestValueGreaterThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
	curr := sl[len(sl)-1]
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] > val {
			if sl[m] < curr {
				curr = sl[m]
			}
			r = m - 1
		} else {
			l = m + 1
		}
	}
	return curr
}

func compute(a, b, c int64) int64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) int64 {
	return a * a
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func greaterThan(x uint64, arr []uint64) (uint64, bool) {
	low, mid, high := 0, 0, len(arr)-1

	for low <= high {
		mid = (low + high) / 2
		if arr[mid] > x {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	if low == 0 {
		return 0, false
	}

	return arr[low-1], true
}

func lesserThan(x uint64, arr []uint64) (uint64, bool) {
	low, mid, high := 0, 0, len(arr)-1

	for low <= high {
		mid = (low + high) / 2
		if arr[mid] >= x {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	if low == len(arr) {
		return 0, false
	}

	return arr[low], true
}

func sqr(a, b uint64) uint64 {
	return a*a + b*b - 2*a*b
}

func calcScore(a, b, c []uint64) uint64 {
	var score uint64
	score = math.MaxUint64

	for _, ga := range a {
		gb, ok1 := lesserThan(ga, b)
		gc, ok2 := greaterThan(gb, c)

		if !ok1 || !ok2 {
			continue
		}

		tmp := sqr(ga, gb) + sqr(gb, gc) + sqr(gc, ga)

		if tmp < score {
			score = tmp
		}
	}

	return score
}

func sortUint(arr []uint64) {
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return uint64(i)
	}

	t := input()

	for ; t > 0; t-- {
		nr, ng, nb := input(), input(), input()

		r := make([]uint64, nr)
		for i := range r {
			r[i] = input()
		}

		g := make([]uint64, ng)
		for i := range g {
			g[i] = input()
		}

		b := make([]uint64, nb)
		for i := range b {
			b[i] = input()
		}

		sortUint(r)
		sortUint(g)
		sortUint(b)

		scores := make([]uint64, 6)
		var minScore uint64 = math.MaxUint64

		scores[0] = calcScore(r, g, b)
		scores[1] = calcScore(r, b, g)
		scores[2] = calcScore(g, b, r)
		scores[3] = calcScore(b, g, r)
		scores[4] = calcScore(g, r, b)
		scores[5] = calcScore(b, r, g)

		for _, val := range scores {
			if val < minScore {
				minScore = val
			}
		}

		fmt.Println(minScore)
	}
}

package main

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

func main() {

	var num_tests int

	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &num_tests)

	for i := 0; i < num_tests; i++ {

		var res int64 = math.MaxInt64
		var num [3]int
		fmt.Fscanf(in, "%d %d %d\n", &num[0], &num[1], &num[2])
		var all []int
		var gems [3][]int
		var x int

		for j := 0; j < 3; j++ {
			for p := 0; p < num[j]; p++ {
				fmt.Fscanf(in, "%d", &x)
				gems[j] = append(gems[j], x)
				all = append(all, x)
			}
			fmt.Fscanf(in, "\n")
			sort.Ints(gems[j])
		}
		sort.Ints(all)

		for j := 0; j < len(all); j++ {

			best := [3]int64{-1, -1, -1}

			for p := 0; p < 3; p++ {
				idx := sort.Search(len(gems[p]), func(x int) bool { return gems[p][x] >= all[j] })
				if idx > 0 {
					best[p] = int64(gems[p][idx-1])
				}

				if idx < len(gems[p]) {
					if best[p] == -1 {
						best[p] = int64(gems[p][idx])
					} else {
						if math.Abs(float64(all[j]-int(best[p]))) > math.Abs(float64(all[j]-gems[p][idx])) {
							best[p] = int64(gems[p][idx])
						}
					}
				}
			}

			tmp_res := (best[0]-best[1])*(best[0]-best[1]) + (best[1]-best[2])*(best[1]-best[2]) + (best[2]-best[0])*(best[2]-best[0])

			// fmt.Println(all[j])
			// fmt.Printf("%d %d %d\n", best[0], best[1], best[2])
			// fmt.Println(tmp_res)
			if tmp_res < res {
				res = tmp_res
			}
		}
		fmt.Println(res)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1336/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t       int
	r, g, b int
	R, G, B []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		r, g, b = ReadInt3()
		R, G, B = ReadInt64Slice(r), ReadInt64Slice(g), ReadInt64Slice(b)
		R = append(R, -(1 << 30), 1<<31)
		G = append(G, -(1 << 30), 1<<31)
		B = append(B, -(1 << 30), 1<<31)

		solve()
	}
}

func solve() {
	sort.SliceStable(R, func(i, j int) bool { return R[i] < R[j] })
	sort.SliceStable(G, func(i, j int) bool { return G[i] < G[j] })
	sort.SliceStable(B, func(i, j int) bool { return B[i] < B[j] })
	// PrintfDebug("R: %v\n", R)
	// PrintfDebug("B: %v\n", B)
	// PrintfDebug("G: %v\n", G)

	ans := int64(INF_INT64)

	// for i := 1; i <= g; i++ {
	// 	gw := G[i]
	// 	uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= gw })
	// 	lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] < gw })
	// 	RT := []int64{R[uridx], R[lridx]}
	// 	ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= gw })
	// 	lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] < gw })
	// 	BT := []int64{B[ubidx], B[lbidx]}

	// 	for j := 0; j < len(RT); j++ {
	// 		for k := 0; k < len(BT); k++ {
	// 			rw, bw := RT[j], BT[k]
	// 			val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
	// 			ChMin(&ans, val)
	// 		}
	// 	}
	// }
	// for i := 1; i <= r; i++ {
	// 	rw := R[i]
	// 	ugidx := BinarySearch(g+1, -1, func(mid int) bool { return G[mid] >= rw })
	// 	lgidx := BinarySearch(0, g+2, func(mid int) bool { return G[mid] < rw })
	// 	GT := []int64{G[ugidx], G[lgidx]}
	// 	ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= rw })
	// 	lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] < rw })
	// 	BT := []int64{B[ubidx], B[lbidx]}

	// 	for j := 0; j < len(GT); j++ {
	// 		for k := 0; k < len(BT); k++ {
	// 			gw, bw := GT[j], BT[k]
	// 			val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
	// 			ChMin(&ans, val)
	// 		}
	// 	}
	// }
	// for i := 1; i <= b; i++ {
	// 	bw := B[i]
	// 	uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= bw })
	// 	lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] < bw })
	// 	RT := []int64{R[uridx], R[lridx]}
	// 	ugidx := BinarySearch(g+1, -1, func(mid int) bool { return G[mid] >= bw })
	// 	lgidx := BinarySearch(0, g+2, func(mid int) bool { return G[mid] < bw })
	// 	GT := []int64{G[ugidx], G[lgidx]}

	// 	for j := 0; j < len(RT); j++ {
	// 		for k := 0; k < len(GT); k++ {
	// 			rw, gw := RT[j], GT[k]
	// 			val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
	// 			ChMin(&ans, val)
	// 		}
	// 	}
	// }
	ChMin(&ans, sub(r, g, b, R, G, B))
	ChMin(&ans, sub(r, b, g, R, B, G))
	ChMin(&ans, sub(g, r, b, G, R, B))

	fmt.Println(ans)
}

func sub(r, g, b int, R, G, B []int64) int64 {
	ans := int64(INF_INT64)

	for i := 1; i <= g; i++ {
		gw := G[i]
		uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= gw })
		lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] <= gw })
		RT := []int64{R[uridx], R[lridx]}
		ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= gw })
		lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] <= gw })
		BT := []int64{B[ubidx], B[lbidx]}

		for j := 0; j < len(RT); j++ {
			for k := 0; k < len(BT); k++ {
				rw, bw := RT[j], BT[k]

				if IsProductOverflow(gw-rw, gw-rw, INF_INT64) {
					continue
				}
				if IsProductOverflow(gw-bw, gw-bw, INF_INT64) {
					continue
				}
				if IsProductOverflow(rw-bw, rw-bw, INF_INT64) {
					continue
				}

				val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
				ChMin(&ans, val)
			}
		}
	}

	return ans
}

func IsProductOverflow(i, j, m int64) bool {
	return float64(i)*float64(j) > float64(m)
}

func IsAddOverflow(i, j, m int64) bool {
	return float64(i)+float64(j) > float64(m)
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int64, target int64) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func greaterThan(x uint64, arr []uint64) uint64 {
	low, mid, high := 0, 0, len(arr)-1

	for low <= high {
		mid = (low + high) / 2
		if arr[mid] >= x {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	if low == len(arr) {
		return arr[low-1]
	}

	return arr[low]
}

func sqr(a, b uint64) uint64 {
	return a*a + b*b - 2*a*b
}

func calcScore(a, b, c []uint64) uint64 {
	var score uint64
	score = math.MaxUint64

	for _, ga := range a {
		gb := greaterThan(ga, b)
		gc := greaterThan(gb, c)
		tmp := sqr(ga, gb) + sqr(gb, gc) + sqr(gc, ga)

		if tmp < score {
			score = tmp
		}
	}

	return score
}

func sortUint(arr []uint64) {
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return uint64(i)
	}

	t := input()

	for ; t > 0; t-- {
		nr, ng, nb := input(), input(), input()

		r := make([]uint64, nr)
		for i := range r {
			r[i] = input()
		}

		g := make([]uint64, ng)
		for i := range g {
			g[i] = input()
		}

		b := make([]uint64, nb)
		for i := range b {
			b[i] = input()
		}

		sortUint(r)
		sortUint(g)
		sortUint(b)

		scores := make([]uint64, 6)
		var minScore uint64 = math.MaxUint64

		scores[0] = calcScore(r, g, b)
		scores[1] = calcScore(r, b, g)
		scores[2] = calcScore(g, b, r)
		scores[3] = calcScore(b, g, r)
		scores[4] = calcScore(g, r, b)
		scores[5] = calcScore(b, r, g)

		for _, val := range scores {
			if val < minScore {
				minScore = val
			}
		}

		fmt.Println(minScore)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func greaterThan(x uint64, arr []uint64) (uint64, bool) {
	low, mid, high := 0, 0, len(arr)-1

	for low <= high {
		mid = (low + high) / 2

		if arr[mid] >= x {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	if low >= len(arr) {
		return 0, false
	}

	return arr[low], true
}

func sqr(a, b uint64) uint64 {
	return (a - b) * (a - b)
}

func calcScore(a, b, c []uint64) uint64 {
	var score uint64
	score = math.MaxUint64

	for _, ga := range a {
		gb, isOkay := greaterThan(ga, b)
		if !isOkay {
			break
		}

		gc, isOkay := greaterThan(gb, c)
		if !isOkay {
			break
		}

		tmp := sqr(ga, gb) + sqr(gb, gc) + sqr(gc, ga)

		if tmp < score {
			score = tmp
		}
	}

	return score
}

func sortUint(arr []uint64) {
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return uint64(i)
	}

	t := input()

	for ; t > 0; t-- {
		nr, ng, nb := input(), input(), input()

		r := make([]uint64, nr)
		for i := range r {
			r[i] = input()
		}

		g := make([]uint64, ng)
		for i := range g {
			g[i] = input()
		}

		b := make([]uint64, nb)
		for i := range b {
			b[i] = input()
		}

		sortUint(r)
		sortUint(g)
		sortUint(b)

		scores := make([]uint64, 6)
		var minScore uint64 = math.MaxUint64

		scores[0] = calcScore(r, g, b)
		scores[1] = calcScore(r, b, g)
		scores[2] = calcScore(g, b, r)
		scores[3] = calcScore(b, g, r)
		scores[4] = calcScore(g, r, b)
		scores[5] = calcScore(b, r, g)

		for _, val := range scores {
			if val < minScore {
				minScore = val
			}
		}

		fmt.Println(minScore)
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

func greaterThan(x uint64, arr []uint64) (uint64, bool) {
	low, mid, high := 0, 0, len(arr)-1

	for low < high {
		mid = (low + high) / 2

		if arr[mid] > x {
			high = mid - 1
		} else {
			low = mid + 1
		}
	}

	if low >= len(arr) {
		return 0, false
	}

	return arr[low], true
}

func sqr(a, b uint64) uint64 {
	return (a - b) * (a - b)
}

func calcScore(a, b, c []uint64) uint64 {
	var score uint64
	score = math.MaxUint64

	for _, ga := range a {
		gb, isOkay := greaterThan(ga, b)
		if !isOkay {
			break
		}

		gc, isOkay := greaterThan(gb, c)
		if !isOkay {
			break
		}

		tmp := sqr(ga, gb) + sqr(gb, gc) + sqr(gc, ga)

		if tmp < score {
			score = tmp
		}
	}

	return score
}

func sortUint(arr []uint64) {
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 1024*1024)
	scanner.Split(bufio.ScanWords)

	input := func() uint64 {
		scanner.Scan()
		i, _ := strconv.ParseUint(scanner.Text(), 10, 64)
		return uint64(i)
	}

	t := input()

	for ; t > 0; t-- {
		nr, ng, nb := input(), input(), input()

		r := make([]uint64, nr)
		for i := range r {
			r[i] = input()
		}

		g := make([]uint64, ng)
		for i := range g {
			g[i] = input()
		}

		b := make([]uint64, nb)
		for i := range b {
			b[i] = input()
		}

		sortUint(r)
		sortUint(g)
		sortUint(b)

		scores := make([]uint64, 6)
		var minScore uint64 = math.MaxUint64

		scores[0] = calcScore(r, g, b)
		scores[1] = calcScore(r, b, g)
		scores[2] = calcScore(g, b, r)
		scores[3] = calcScore(b, g, r)
		scores[4] = calcScore(g, r, b)
		scores[5] = calcScore(b, r, g)

		for _, val := range scores {
			if val < minScore {
				minScore = val
			}
		}

		fmt.Println(minScore)
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {

	var num_tests int
	fmt.Scanf("%d\n", &num_tests)

	for i := 0; i < num_tests; i++ {

		var res int64 = math.MaxInt64
		var num [3]int
		fmt.Scanf("%d %d %d\n", &num[0], &num[1], &num[2])
		fmt.Printf("%d %d %d", num[0], num[1], num[2])
		var all []int
		var gems [3][]int
		var x int

		for j := 0; j < 3; j++ {
			for p := 0; p < num[j]; p++ {
				fmt.Scanf("%d\n", &x)
				gems[j] = append(gems[j], x)
				all = append(all, x)
			}
			sort.Ints(gems[j])
		}
		sort.Ints(all)

		for j := 0; j < len(all); j++ {

			best := [3]int64{-1, -1, -1}

			for p := 0; p < 3; p++ {
				idx := sort.Search(len(gems[p]), func(x int) bool { return gems[p][x] >= all[j] })
				if idx > 0 {
					best[p] = int64(gems[p][idx-1])
				}

				if idx < len(gems[p]) {
					if best[p] == -1 {
						best[p] = int64(gems[p][idx])
					} else {
						if math.Abs(float64(all[j]-int(best[p]))) > math.Abs(float64(all[j]-gems[p][idx])) {
							best[p] = int64(gems[p][idx])
						}
					}
				}
			}

			tmp_res := (best[0]-best[1])*(best[0]-best[1]) + (best[1]-best[2])*(best[1]-best[2]) + (best[2]-best[0])*(best[2]-best[0])

			// fmt.Println(all[j])
			// fmt.Printf("%d %d %d\n", best[0], best[1], best[2])
			// fmt.Println(tmp_res)
			if tmp_res < res {
				res = tmp_res
			}
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {

	var num_tests int
	fmt.Scanf("%d\n", &num_tests)

	for i := 0; i < num_tests; i++ {

		var res int64 = math.MaxInt64
		var num [3]int
		fmt.Scanf("%d %d %d\n", &num[0], &num[1], &num[2])
		var all []int
		var gems [3][]int
		var x int

		for j := 0; j < 3; j++ {
			for p := 0; p < num[j]; p++ {
				fmt.Scanf("%d\n", &x)
				gems[j] = append(gems[j], x)
				all = append(all, x)
			}
			sort.Ints(gems[j])
		}
		sort.Ints(all)

		for j := 0; j < len(all); j++ {

			best := [3]int64{-1, -1, -1}

			for p := 0; p < 3; p++ {
				idx := sort.Search(len(gems[p]), func(x int) bool { return gems[p][x] >= all[j] })
				if idx > 0 {
					best[p] = int64(gems[p][idx-1])
				}

				if idx < len(gems[p]) {
					if best[p] == -1 {
						best[p] = int64(gems[p][idx])
					} else {
						if math.Abs(float64(all[j]-int(best[p]))) > math.Abs(float64(all[j]-gems[p][idx])) {
							best[p] = int64(gems[p][idx])
						}
					}
				}
			}

			tmp_res := (best[0]-best[1])*(best[0]-best[1]) + (best[1]-best[2])*(best[1]-best[2]) + (best[2]-best[0])*(best[2]-best[0])

			// fmt.Println(all[j])
			// fmt.Printf("%d %d %d\n", best[0], best[1], best[2])
			// fmt.Println(tmp_res)
			if tmp_res < res {
				res = tmp_res
			}
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {

	var num_tests int
	fmt.Scanf("%d\n", &num_tests)

	for i := 0; i < num_tests; i++ {

		var res int64 = math.MaxInt64
		var num [3]int
		fmt.Scanf("%d%d%d\n", &num[0], &num[1], &num[2])
		var all []int
		var gems [3][]int
		var x int

		for j := 0; j < 3; j++ {
			for p := 0; p < num[j]; p++ {
				fmt.Scanf("%d\n", &x)
				gems[j] = append(gems[j], x)
				all = append(all, x)
			}
			sort.Ints(gems[j])
		}
		sort.Ints(all)

		for j := 0; j < len(all); j++ {

			best := [3]int64{-1, -1, -1}

			for p := 0; p < 3; p++ {
				idx := sort.Search(len(gems[p]), func(x int) bool { return gems[p][x] >= all[j] })
				if idx > 0 {
					best[p] = int64(gems[p][idx-1])
				}

				if idx < len(gems[p]) {
					if best[p] == -1 {
						best[p] = int64(gems[p][idx])
					} else {
						if math.Abs(float64(all[j]-int(best[p]))) > math.Abs(float64(all[j]-gems[p][idx])) {
							best[p] = int64(gems[p][idx])
						}
					}
				}
			}

			tmp_res := (best[0]-best[1])*(best[0]-best[1]) + (best[1]-best[2])*(best[1]-best[2]) + (best[2]-best[0])*(best[2]-best[0])

			// fmt.Println(all[j])
			// fmt.Printf("%d %d %d\n", best[0], best[1], best[2])
			// fmt.Println(tmp_res)
			if tmp_res < res {
				res = tmp_res
			}
		}
		fmt.Println(res)
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1336/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t       int
	r, g, b int
	R, G, B []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		r, g, b = ReadInt3()
		R, G, B = ReadInt64Slice(r), ReadInt64Slice(g), ReadInt64Slice(b)
		R = append(R, -(1 << 30), 1<<30)
		G = append(G, -(1 << 30), 1<<30)
		B = append(B, -(1 << 30), 1<<30)

		solve()
	}
}

func solve() {
	sort.SliceStable(R, func(i, j int) bool { return R[i] < R[j] })
	sort.SliceStable(G, func(i, j int) bool { return G[i] < G[j] })
	sort.SliceStable(B, func(i, j int) bool { return B[i] < B[j] })
	// PrintfDebug("R: %v\n", R)
	// PrintfDebug("B: %v\n", B)
	// PrintfDebug("G: %v\n", G)

	ans := int64(INF_INT64)

	for i := 1; i <= g; i++ {
		gw := G[i]
		uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= gw })
		lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] < gw })
		RT := []int64{R[uridx], R[lridx]}
		ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= gw })
		lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] < gw })
		BT := []int64{B[ubidx], B[lbidx]}

		for j := 0; j < len(RT); j++ {
			for k := 0; k < len(BT); k++ {
				rw, bw := RT[j], BT[k]
				val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
				ChMin(&ans, val)
			}
		}
	}

	fmt.Println(ans)
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int64, target int64) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1336/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t       int
	r, g, b int
	R, G, B []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		r, g, b = ReadInt3()
		R, G, B = ReadInt64Slice(r), ReadInt64Slice(g), ReadInt64Slice(b)
		R = append(R, -(1 << 30), 1<<30)
		G = append(G, -(1 << 30), 1<<30)
		B = append(B, -(1 << 30), 1<<30)

		solve()
	}
}

func solve() {
	sort.SliceStable(R, func(i, j int) bool { return R[i] < R[j] })
	sort.SliceStable(G, func(i, j int) bool { return G[i] < G[j] })
	sort.SliceStable(B, func(i, j int) bool { return B[i] < B[j] })
	// PrintfDebug("R: %v\n", R)
	// PrintfDebug("B: %v\n", B)
	// PrintfDebug("G: %v\n", G)

	ans := int64(INF_INT64)

	for i := 1; i <= g; i++ {
		gw := G[i]
		uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= gw })
		lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] < gw })
		RT := []int64{R[uridx], R[lridx]}
		if uridx+1 < len(R) {
			RT = append(RT, R[uridx+1])
		}
		if lridx-1 >= 0 {
			RT = append(RT, R[lridx-1])
		}
		ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= gw })
		lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] < gw })
		BT := []int64{B[ubidx], B[lbidx]}
		if ubidx+1 < len(B) {
			BT = append(BT, B[ubidx+1])
		}
		if lbidx-1 >= 0 {
			BT = append(BT, B[lbidx-1])
		}

		for j := 0; j < len(RT); j++ {
			for k := 0; k < len(BT); k++ {
				rw, bw := RT[j], BT[k]
				val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
				ChMin(&ans, val)
			}
		}
	}

	fmt.Println(ans)
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int64, target int64) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1336/B
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t       int
	r, g, b int
	R, G, B []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		r, g, b = ReadInt3()
		R, G, B = ReadInt64Slice(r), ReadInt64Slice(g), ReadInt64Slice(b)
		R = append(R, -(1 << 30), 1<<30)
		G = append(G, -(1 << 30), 1<<30)
		B = append(B, -(1 << 30), 1<<30)

		solve()
	}
}

func solve() {
	sort.SliceStable(R, func(i, j int) bool { return R[i] < R[j] })
	sort.SliceStable(G, func(i, j int) bool { return G[i] < G[j] })
	sort.SliceStable(B, func(i, j int) bool { return B[i] < B[j] })
	// PrintfDebug("R: %v\n", R)
	// PrintfDebug("B: %v\n", B)
	// PrintfDebug("G: %v\n", G)

	ans := int64(INF_INT64)

	for i := 1; i <= g; i++ {
		gw := G[i]
		uridx := BinarySearch(r+1, -1, func(mid int) bool { return R[mid] >= gw })
		lridx := BinarySearch(0, r+2, func(mid int) bool { return R[mid] <= gw })
		RT := []int64{R[uridx], R[lridx]}
		if uridx+1 < len(R) {
			RT = append(RT, R[uridx+1])
		}
		if lridx-1 >= 0 {
			RT = append(RT, R[lridx-1])
		}
		ubidx := BinarySearch(b+1, -1, func(mid int) bool { return B[mid] >= gw })
		lbidx := BinarySearch(0, b+2, func(mid int) bool { return B[mid] <= gw })
		BT := []int64{B[ubidx], B[lbidx]}
		if ubidx+1 < len(B) {
			BT = append(BT, B[ubidx+1])
		}
		if lbidx-1 >= 0 {
			BT = append(BT, B[lbidx-1])
		}

		for j := 0; j < len(RT); j++ {
			for k := 0; k < len(BT); k++ {
				rw, bw := RT[j], BT[k]
				val := (gw-rw)*(gw-rw) + (gw-bw)*(gw-bw) + (rw-bw)*(rw-bw)
				ChMin(&ans, val)
			}
		}
	}

	fmt.Println(ans)
}

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int64, target int64) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int64) int64 {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

func BinarySearch(initOK, initNG int, isOK func(mid int) bool) (ok int) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

type Stone struct {
	t int // 1, 2, 3 means: r, g, b
	w int64
}

type SortBy []Stone

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].w < a[j].w }

func main () {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReaderSize(os.Stdin, 1000*1000)
	output := bufio.NewWriterSize(os.Stdout, 1000*1000)
	fmt.Fscanln(input, &T)

	for i := 0; i < T; i++ {
		var r, g, b int
		var tmp int64
		fmt.Fscan(input, &r, &g, &b)
		stones := make([]Stone, r + g + b)
		for i := 0; i < r; i++ {
			fmt.Fscan(input, &tmp)
			stones[i].t = 1
			stones[i].w = tmp
		}
		for i := 0; i < g; i++ {
			fmt.Fscan(input, &tmp)
			stones[i + r].t = 2
			stones[i + r].w = tmp
		}
		for i := 0; i < b; i++ {
			fmt.Fscan(input, &tmp)
			stones[i + r + g].t = 3
			stones[i + r + g].w = tmp
		}

		fmt.Fprintln(output, solve(stones))
	}

	output.Flush()
}

func solve(stones []Stone) int64 {
	sort.Sort(SortBy(stones))
	ans := int64(9000000000000000000)
	segment := len(stones)
	for i := 0; i < len(stones) - 2; i++ {
		if stones[i + 1].t == stones[i].t {
			continue
		}
		x := i
		y := x + 1
		z := y + 1
		for z < len(stones) && (stones[z].t == stones[x].t || stones[z].t == stones[y].t) {
			z++
		}

		if segment >= z - x {
			if z < len(stones) {
				for k := y; k < z; k++ {
					if stones[k].t == stones[y].t {
						ans = min(ans, weight(stones[x].w, stones[k].w, stones[z].w))
					}
				}
			}
			segment = z - x
		}
	}

	return ans
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func weight(x, y, z int64) int64 {
	return (x-y)*(x-y) + (y-z)*(y-z) + (z-x)*(z-x)
}

// http://acm.timus.ru/problem.aspx?space=1&num=1741
package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

type Stone struct {
	t int // 1, 2, 3 means: r, g, b
	w int64
}

type SortBy []Stone

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].w < a[j].w }

func main () {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReaderSize(os.Stdin, 1000*1000)
	output := bufio.NewWriterSize(os.Stdin, 1000*1000)
	fmt.Fscanln(input, &T)

	for i := 0; i < T; i++ {
		var r, g, b int
		var tmp int64
		fmt.Fscan(input, &r, &g, &b)
		stones := make([]Stone, r + g + b)
		for i := 0; i < r; i++ {
			fmt.Fscan(input, &tmp)
			stones[i].t = 1
			stones[i].w = tmp
		}
		for i := 0; i < g; i++ {
			fmt.Fscan(input, &tmp)
			stones[i + r].t = 2
			stones[i + r].w = tmp
		}
		for i := 0; i < b; i++ {
			fmt.Fscan(input, &tmp)
			stones[i + r + g].t = 3
			stones[i + r + g].w = tmp
		}

		fmt.Fprintln(output, solve(stones))
	}

	output.Flush()
}

func solve(stones []Stone) int64 {
	sort.Sort(SortBy(stones))
	ans := int64(9000000000000000000)
	for i := 0; i < len(stones) - 2; i++ {
		if stones[i + 1].t == stones[i].t {
			continue
		}
		x := i
		y := x + 1
		z := y + 1
		for z < len(stones) && (stones[z].t == stones[x].t || stones[z].t == stones[y].t) {
			z++
		}
		if z < len(stones) {
			for k := x + 1; k < z; k++ {
				ans = min(ans, weight(stones[x].w, stones[k].w, stones[z].w))
			}
		}
	}

	return ans
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func weight(x, y, z int64) int64 {
	return (x-y)*(x-y) + (y-z)*(y-z) + (z-x)*(z-x)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	//searchRange := func(l, r int, f func(int) bool) int {
	//	i, j := l, r
	//	for i < j {
	//		h := (i + j) >> 1
	//		if f(h) {
	//			j = h
	//		} else {
	//			i = h + 1
	//		}
	//	}
	//	return i
	//}
	unique := func(a []int) (res []int) {
		n := len(a)
		res = make([]int, 1, n)
		res[0] = a[0]
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				res = append(res, a[i])
			}
		}
		return
	}
	orderP3 := [6][3]int{{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}
	upperBound := func(a []int, x int) int { return sort.Search(len(a), func(i int) bool { return a[i] > x }) }
	min := func(a, b int64) int64 {
		if a < b {
			return a
		}
		return b
	}
	calcSum := func(x, y, z int64) int64 {
		return (x-y)*(x-y) + (y-z)*(y-z) + (x-z)*(x-z)
	}

	solve := func(_case int) (ans int64) {
		ans = math.MaxInt64
		a := [3][]int{}
		n := make([]int, 3)
		for i := range n {
			Fscan(in, &n[i])
		}
		for i := range a {
			a[i] = make([]int, n[i])
			for j := range a[i] {
				Fscan(in, &a[i][j])
			}
			sort.Ints(a[i])
			a[i] = unique(a[i])
		}
		for _, p3 := range orderP3 {
			b := [3][]int{}
			for i := range b {
				b[i] = a[p3[i]]
			}
			j := 0
			for _, v := range b[0] {
				for ; j < len(b[1]) && b[1][j] < v; j++ {
				}
				if j == len(b[1]) {
					break
				}
				w := b[1][j]
				mid := (v + w) >> 1
				lowK := sort.SearchInts(b[2], mid)
				if lowK < len(b[2]) {
					sum := calcSum(int64(v), int64(w), int64(b[2][lowK]))
					ans = min(ans, sum)
				}
				lowK = upperBound(b[2], mid)
				if lowK < len(b[2]) {
					sum := calcSum(int64(v), int64(w), int64(b[2][lowK]))
					ans = min(ans, sum)
				}
				if (v+w)&1 == 1 {
					mid = (v+w)>>1 + 1
					lowK = sort.SearchInts(b[2], mid)
					if lowK < len(b[2]) {
						sum := calcSum(int64(v), int64(w), int64(b[2][lowK]))
						ans = min(ans, sum)
					}
					lowK = upperBound(b[2], mid)
					if lowK < len(b[2]) {
						sum := calcSum(int64(v), int64(w), int64(b[2][lowK]))
						ans = min(ans, sum)
					}
				}
			}
		}

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		Fprintln(out, solve(_case))
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("red: %v\n", red)
		//writer.Printf("green: %v\n", green)
		//writer.Printf("blue: %v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a uint64, rest ...uint64) uint64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) uint64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		bRes := binarySearchAscLessThan(b, a[i])
		cRes := binarySearchAscGreaterThan(c, a[i])
		tmp := compute(a[i], bRes, cRes)
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func binarySearchAscLessThan(sl []int64, val int64) int64 {
    l := 0
    r := len(sl)-1
    curr := sl[l + ((r-l)/2)]
    for l <= r {
        m := l + ((r-l)/2)
        if sl[m] <= val {
            if sl[m] > curr {
                curr = sl[m]
            }
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return curr
}

func binarySearchAscGreaterThan(sl []int64, val int64) int64 {
    l := 0
    r := len(sl)-1
    curr := sl[l + ((r-l)/2)]
    for l <= r {
        m := l + ((r-l)/2)
        if sl[m] >= val {
            if sl[m] < curr {
                curr = sl[m]
            }
            r = m - 1
        } else {
            l = m + 1
        }
    }
    return curr
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("red: %v\n", red)
		//writer.Printf("green: %v\n", green)
		//writer.Printf("blue: %v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a uint64, rest ...uint64) uint64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) uint64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		bi := sort.Search(len(b), func(idx int) bool {
			return b[idx] >= a[i]
		})
		ci := sort.Search(len(c), func(idx int) bool {
			return c[idx] >= a[i]
		})
		if bi == len(b) {
			bi--
		}
		if ci == len(c) {
			ci--
		}
        //writer.Printf("%d %d %d\n", a[i], b[bi], c[ci])
		tmp := compute(a[i], b[bi], c[ci])
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := []int64{}
		for ; nr > 0; nr-- {
			red = append(red, reader.NextInt64())
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		green := []int64{}
		for ; ng > 0; ng-- {
			green = append(green, reader.NextInt64())
		}
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		blue := []int64{}
		for ; nb > 0; nb-- {
			blue = append(blue, reader.NextInt64())
		}
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		pr, pg, pb := 0, 0, 0
		minSoFar := compute(red[pr], green[pg], blue[pb])
		//writer.Printf("%v %v %v\n", red, green, blue)
		for {
			//writer.Printf("%d %d %d\n", pr, pg, pb)
			currSum := compute(red[pr], green[pg], blue[pb])
			if currSum < minSoFar {
				minSoFar = currSum
			}
			nums := []int64{}
			if pr < len(red)-1 {
				nums = append(nums, red[pr])
			}
			if pg < len(green)-1 {
				nums = append(nums, green[pg])
			}
			if pb < len(blue)-1 {
				nums = append(nums, blue[pb])
			}
            if len(nums) == 0 {
                break
            }
			currMin := min(nums)
			if pr < len(red)-1 && red[pr] == currMin {
				pr++
				continue
			}
			if pg < len(green)-1 && green[pg] == currMin {
				pg++
				continue
			}
			if pb < len(blue)-1 && blue[pb] == currMin {
				pb++
				continue
			}
            // should not reach here
			break
		}

		writer.Printf("%d\n", minSoFar)
	}
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

func min(nums []int64) int64 {
	minSoFar := nums[0]
	for i := 1; i < len(nums); i++ {
		if nums[i] < minSoFar {
			minSoFar = nums[i]
		}
	}
	return minSoFar
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("red: %v\n", red)
		//writer.Printf("green: %v\n", green)
		//writer.Printf("blue: %v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) int64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		bRes := binarySearchAscLessThan(b, a[i])
		cRes := binarySearchAscGreaterThan(c, a[i])
		tmp := compute(a[i], bRes, cRes)
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func binarySearchAscLessThan(sl []int64, val int64) int64 {
    l := 0
    r := len(sl)-1
    curr := sl[l + ((r-l)/2)]
    for l <= r {
        m := l + ((r-l)/2)
        if sl[m] <= val {
            if sl[m] > curr {
                curr = sl[m]
            }
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return curr
}

func binarySearchAscGreaterThan(sl []int64, val int64) int64 {
    l := 0
    r := len(sl)-1
    curr := sl[l + ((r-l)/2)]
    for l <= r {
        m := l + ((r-l)/2)
        if sl[m] >= val {
            if sl[m] < curr {
                curr = sl[m]
            }
            r = m - 1
        } else {
            l = m + 1
        }
    }
    return curr
}

func compute(a, b, c int64) int64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) int64 {
    return a * a
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("red: %v\n", red)
		//writer.Printf("green: %v\n", green)
		//writer.Printf("blue: %v\n", blue)
		minSoFar := compute(red[0], green[0], blue[0])
		for i := int64(0); i < nr; i++ {
			gIdx := sort.Search(len(green), func(idx int) bool {
				return green[idx] > red[i]
			})
			bIdx := sort.Search(len(blue), func(idx int) bool {
				return blue[idx] > red[i]
			})
			//writer.Printf("%d %d %d\n", i, gIdx, bIdx)
			if gIdx == len(green) {
				gIdx--
			}
			if bIdx == len(blue) {
				bIdx--
			}
			tmp := compute(red[i], green[gIdx], blue[bIdx])
			if tmp < minSoFar {
				minSoFar = tmp
			}
			if gIdx < len(green)-1 {
				tmp = compute(red[i], green[gIdx+1], blue[bIdx])
				if tmp < minSoFar {
					minSoFar = tmp
				}
			}
			if bIdx < len(blue)-1 {
				tmp = compute(red[i], green[gIdx], blue[bIdx+1])
				if tmp < minSoFar {
					minSoFar = tmp
				}
			}
			if gIdx < len(green)-1 && bIdx < len(blue)-1 {
				tmp = compute(red[i], green[gIdx+1], blue[bIdx+1])
				if tmp < minSoFar {
					minSoFar = tmp
				}
			}
		}
		writer.Printf("%d\n", minSoFar)
	}
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
        //writer.Printf("red: %v\n", red)
        //writer.Printf("green: %v\n", green)
        //writer.Printf("blue: %v\n", blue)
		minSoFar := compute(red[0], green[0], blue[0])
		for i := int64(0); i < nr; i++ {
			gIdx := sort.Search(len(green), func(idx int) bool {
				return green[idx] > red[i]
			})
			bIdx := sort.Search(len(blue), func(idx int) bool {
				return blue[idx] > red[i]
			})
			if gIdx == len(green) {
				gIdx--
			}
			if bIdx == len(blue) {
				bIdx--
			}
            //writer.Printf("%d %d %d\n", i, gIdx, bIdx)
			tmp := compute(red[i], green[gIdx], blue[bIdx])
			if tmp < minSoFar {
				minSoFar = tmp
			}
            if gIdx < len(green)-1 {
                tmp = compute(red[i], green[gIdx+1], blue[bIdx])
                if tmp < minSoFar {
                    minSoFar = tmp
                }
            }
            if bIdx < len(blue)-1 {
                tmp = compute(red[i], green[gIdx], blue[bIdx+1])
                if tmp < minSoFar {
                    minSoFar = tmp
                }
            }
		}
		writer.Printf("%d\n", minSoFar)
	}
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
		//writer.Printf("red: %v\n", red)
		//writer.Printf("green: %v\n", green)
		//writer.Printf("blue: %v\n", blue)
        minSoFar := min(
            solve(red, green, blue),
            solve(red, blue, green),
            solve(green, red, blue),
            solve(green, blue, red),
            solve(blue, red, green),
            solve(blue, green, red),
        )
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a uint64, rest ...uint64) uint64 {
    for _, r := range rest {
        if r < a {
            a = r
        }
    }
    return a
}

func solve(a, b, c []int64) uint64 {
    minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		bi := sort.Search(len(b), func(idx int) bool {
			return b[idx] < a[i]
		})
		ci := sort.Search(len(c), func(idx int) bool {
			return c[idx] > a[i]
		})
        if bi == len(b) {
            bi--
        }
        if ci == len(c) {
            ci--
        }
		tmp := compute(a[i], b[bi], c[ci])
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
    return minSoFar
}

func compute(a, b, c int64) uint64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := make([]int64, nr)
		green := make([]int64, ng)
		blue := make([]int64, nb)
		for i := int64(0); i < nr; i++ {
			red[i] = reader.NextInt64()
		}
		for i := int64(0); i < ng; i++ {
			green[i] = reader.NextInt64()
		}
		for i := int64(0); i < nb; i++ {
			blue[i] = reader.NextInt64()
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})
        writer.Printf("%v\n", red)
        writer.Printf("%v\n", green)
        writer.Printf("%v\n", blue)
		minSoFar := min(
			solve(red, green, blue),
			solve(red, blue, green),
			solve(green, red, blue),
			solve(green, blue, red),
			solve(blue, red, green),
			solve(blue, green, red),
		)
		writer.Printf("%d\n", minSoFar)
	}
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func solve(a, b, c []int64) int64 {
	minSoFar := compute(a[0], b[0], c[0])
	for i := 0; i < len(a); i++ {
		aRes := a[i]
		bRes := binarySearchAscLessThan(b, aRes)
		cRes := binarySearchAscGreaterThan(c, aRes)
		tmp := compute(aRes, bRes, cRes)
        writer.Printf("%d %d %d %d\n", aRes, bRes, cRes, tmp)
		if tmp < minSoFar {
			minSoFar = tmp
		}
	}
	return minSoFar
}

func binarySearchAscLessThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
    curr := int64(0) // value here doesn't matter
    hasVal := false
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] < val {
            if !hasVal {
                curr = sl[m]
                hasVal = true
            } else if sl[m] > curr {
				curr = sl[m]
			}
			l = m + 1
		} else {
			r = m - 1
		}
	}
    if !hasVal {
        return sl[0]
    }
	return curr
}

func binarySearchAscGreaterThan(sl []int64, val int64) int64 {
	l := 0
	r := len(sl) - 1
	curr := int64(0) // value here doesn't matter
    hasVal := false
	for l <= r {
		m := l + ((r - l) / 2)
		if sl[m] == val {
			return sl[m]
		} else if sl[m] > val {
            if !hasVal {
                curr = sl[m]
                hasVal = true
            } else if sl[m] < curr {
				curr = sl[m]
			}
			r = m - 1
		} else {
			l = m + 1
		}
	}
    if !hasVal {
        return sl[len(sl)-1]
    }
	return curr
}

func compute(a, b, c int64) int64 {
	return sq(a-b) + sq(b-c) + sq(c-a)
}

func sq(a int64) int64 {
	return a * a
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		nr, ng, nb := reader.NextInt64(), reader.NextInt64(), reader.NextInt64()
		red := []int64{}
		for i := int64(0); i < nr; i++ {
			red = append(red, reader.NextInt64())
		}
		green := []int64{}
		for i := int64(0); i < ng; i++ {
			green = append(green, reader.NextInt64())
		}
		blue := []int64{}
		for i := int64(0); i < nb; i++ {
			blue = append(blue, reader.NextInt64())
		}
		sort.Slice(red, func(a, b int) bool {
			return red[a] < red[b]
		})
		sort.Slice(green, func(a, b int) bool {
			return green[a] < green[b]
		})
		sort.Slice(blue, func(a, b int) bool {
			return blue[a] < blue[b]
		})

		ptrs := [3]int{0, 0, 0}
        vals := [3][]int64{red, green, blue}
		minSoFar := compute(ptrs, vals)
		for {
			curr := compute(ptrs, vals)
			if curr < minSoFar {
				minSoFar = curr
			}
			mini, nmin := minIdx(ptrs, vals)
            //writer.Printf("mini: %v\n", mini)
            if nmin == 3 {
                // result is zero
                break
            } else if nmin == 2 {
                for i := 0; i < 3; i++ {
					if mini[i] && ptrs[i] < len(vals[i])-1 {
						var tmp [3]int
						for j, p := range ptrs {
							tmp[j] = p
						}
						tmp[i]++
						curr = compute(tmp, vals)
						if curr < minSoFar {
							minSoFar = curr
						}
					}
				}
				for i := 0; i < 3; i++ {
					if mini[i] && ptrs[i] < len(vals[i])-1 {
						ptrs[i]++
					}
				}
			} else if nmin == 1 {
                for i, b := range mini {
                    if b {
                        ptrs[i]++
                    }
                }
            } else {
                // reached the end
                break
            }
		}

		writer.Printf("%d\n", minSoFar)
	}
}

func compute(ptrs [3]int, vals [3][]int64) uint64 {
    v := [3]int64{}
    for i := 0; i < 3; i++ {
        v[i] = vals[i][ptrs[i]]
    }
	return sq(v[1]-v[0]) + sq(v[2]-v[1]) + sq(v[0]-v[2])
}

func sq(a int64) uint64 {
	if a < 0 {
		a *= -1
	}
	ret := uint64(a)
	return ret * ret
}

func minIdx(ptrs [3]int, vals [3][]int64) ([3]bool, int) {
	currMin := int64(math.MaxInt64)
    for i := 0; i < 3; i++ {
        if ptrs[i] < len(vals[i])-1 && vals[i][ptrs[i]] < currMin {
            currMin = vals[i][ptrs[i]]
        }
    }
	ret := [3]bool{
		currMin == vals[0][ptrs[0]],
		currMin == vals[1][ptrs[1]],
		currMin == vals[2][ptrs[2]],
	}
	retCount := 0
	for _, r := range ret {
		if r {
			retCount++
		}
	}
	return ret, retCount
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}