package main

import "fmt"

var dotASC = "."[0]

func main() {
	l, w, cs := 0, 0, "byte(0)"
	fmt.Scan(&l, &w, &cs)
	c := cs[0]
	o := make([]string, l)
	for i := 0; i < l; i++ {
		str := ""
		fmt.Scan(&str)
		o[i] = str
	}

	px, py := -1, -1
	for i := 0; i < l; i++ {
		for j := 0; j < w; j++ {
			if o[i][j] == c {
				py, px = i, j
				break
			}
		}
		if (px != -1) || (py != -1) {
			break
		}
	}

	pw, ph := 1, 1
	for i := px + 1; i < w; i++ {
		if o[py][i] == c {
			pw = i - px + 1
		}
	}

	for i := py + 1; i < l; i++ {
		if o[i][px] == c {
			ph = i - py + 1
		}
	}

	ex, ey, ansMap := px+pw-1, py+ph-1, map[byte]bool{}
	if px >= 1 {
		for i := py; i <= ey; i++ {
			ansMap[o[i][px-1]] = true
		}
	}
	if py >= 1 {
		for i := px; i <= ex; i++ {
			ansMap[o[py-1][i]] = true
		}
	}

	if ex < w-1 {
		for i := py; i <= ey; i++ {
			ansMap[o[i][ex+1]] = true
		}
	}
	if ey < l-1 {
		for i := px; i <= ex; i++ {
			ansMap[o[ey+1][i]] = true
		}
	}

	if ansMap[dotASC] {
		fmt.Println(len(ansMap) - 1)
	} else {
		fmt.Println(len(ansMap))
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"strings"
)

var cs map[int]int = make(map[int]int)

func Init() {}
func Solve(io *FastIO) {
	n, m, c := io.NextInt(), io.NextInt(), byte(io.NextChar())
	var s, so string
	var char byte
	d := make(map[byte]bool)
	so = strings.Repeat(".", m)
	for i := 0; i < n; i++ {
		s = io.NextString()
		var sb byte = '.'
		for j := range s {
			char = s[j]
			if char == c {
				if sb != c && sb != '.' {
					d[sb] = true
				}
				if so[j] != c && so[j] != '.' {
					d[so[j]] = true
				}
			} else if char != c && char != '.' && (sb == c || so[j] == c) {
				d[char] = true
			}
			sb = char
		}
		so = s
	}
	o := 0
	for _ = range d {
		o++
	}
	io.Println(o)
}

type FastIO struct {
	//by megaspazz
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}
func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = res*10 + int(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = int64(-1)
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = res*10 + int64(c-'0')
		c = io.NextChar()
	}
	return res * sgn
}
func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}
func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}
func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}
func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}
func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}
func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}
func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}
func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}
func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}
func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}
func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	color := map[byte]bool{}

	var n, m int
	var c byte
	room := [100][100]byte{}

	fmt.Fscanf(reader, "%d %d %c\n", &n, &m, &c)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%c", &room[i][j])
			if room[i][j] == c && i != 0 && room[i-1][j] != c && room[i-1][j] != '.' {
				color[room[i-1][j]] = true
			}
			if room[i][j] == c && j != 0 && room[i][j-1] != c && room[i][j-1] != '.' {
				color[room[i][j-1]] = true
			}
			if room[i][j] != c && i != 0 && room[i-1][j] == c && room[i][j] != '.' {
				color[room[i][j]] = true
			}
			if room[i][j] != c && j != 0 && room[i][j-1] == c && room[i][j] != '.' {
				color[room[i][j]] = true
			}
		}
		fmt.Fscanf(reader, "\n")
	}
	fmt.Printf("%d", len(color))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, m int
	s, _ := reader.ReadBytes('\n')
	pos := readInt(s, 0, &n)
	pos = readInt(s, pos+1, &m)
	P := s[pos+1]

	R := make([]string, n)

	for i := 0; i < n; i++ {
		R[i], _ = reader.ReadString('\n')
	}

	fmt.Println(solve(n, m, P, R))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, P byte, R []string) int {
	mem := make(map[byte]bool)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] == P {
				for k := 0; k < 4; k++ {
					u, v := i+dd[k], j+dd[k+1]
					if u >= 0 && u < n && v >= 0 && v < m && R[u][v] != P && R[u][v] != '.' {
						mem[R[u][v]] = true
					}
				}
			}
		}
	}

	return len(mem)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {

	// creates scanner from standard input
	stdin := bufio.NewReader(os.Stdin)
	scanner := bufio.NewScanner(stdin)

	// scans first line to read height, weight, and president color
	scanner.Scan()
	firstLine := scanner.Text()
	reader := strings.NewReader(firstLine)

	// reads initial data from first line
	var width, height int
	var presidentColorString string
	_, _ = fmt.Fscan(reader, &height)
	_, _ = fmt.Fscan(reader, &width)
	_, _ = fmt.Fscan(reader, &presidentColorString)

	// some variables
	paddedHeight := height + 2
	paddedWidth := width + 2
	presidentColor := presidentColorString[0]
	empty := byte('.')
	null := byte(0)

	// add padding around room
	room := make([][]byte, paddedHeight)
	for idx := 0; idx < paddedHeight; idx++ {
		room[idx] = make([]byte, paddedWidth)
	}

	// iterate total input rows
	for rowIdx := 0; rowIdx < height; rowIdx++ {
		if !scanner.Scan() {
			break
		}

		// slice of row without padding
		row := room[rowIdx+1][1 : width+1]

		// read input into slice
		line := scanner.Bytes()
		for col, ch := range line {
			row[col] = ch
		}
	}

	adjacentToPresident := make(map[byte]interface{})
	for row := 1; row < height+1; row++ {
		for col := 1; col < width+1; col++ {
			if room[row][col] == empty || room[row][col] == null || room[row][col] == presidentColor {
				continue
			}

			if room[row-1][col] == presidentColor || room[row+1][col] == presidentColor ||
				room[row][col+1] == presidentColor || room[row][col-1] == presidentColor {
				adjacentToPresident[room[row][col]] = struct{}{}
			}
		}
	}

	fmt.Println(len(adjacentToPresident))

	// for _, row := range room {
	// 	fmt.Println(row)
	// }
	// fmt.Println(">", presidentColor)
}

package main

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

func solve() {
	n := readInt()
	_ = readInt()
	c := readString()[0]

	a := make([]string, n)
	seen := make(map[byte]bool)
	for i, _ := range a {
		a[i] = readString()
	}

	// We have seen the empty space and the president's desk
	seen['.'] = true
	seen[c] = true

	for i, ai := range a {
		for j, cur := range ai {
			if byte(cur) != c {
				continue
			}

			// This is a part of the president's desk.
			// See if anyone else is nearby.
			if i > 0 { // above
				seen[a[i-1][j]] = true
			}
			if i < len(a)-1 { // below
				seen[a[i+1][j]] = true
			}
			if j > 0 { // left
				seen[ai[j-1]] = true
			}
			if j < len(ai)-1 { // right
				seen[ai[j+1]] = true
			}
		}
	}
	fmt.Println(len(seen) - 2)
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

package main

import "fmt"

func mark(table [][]byte, c byte) {
	var n = len(table)
	var m = len(table[0])
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if table[i][j] == c {
				table[i][j] = '.'
			}
		}
	}
}

func main() {
	var n, m int
	var c byte
	_, _ = fmt.Scanf("%d %d %c\n", &n, &m, &c)
	var table = make([][]byte, n)
	for i := 0; i < n; i++ {
		table[i] = make([]byte, m)
		_, _ = fmt.Scanf("%s\n", &table[i])
	}
	var ans = 0

	//for i := 0; i < n; i++ {
	//    for j := 0; j < m; j++ {
	//        fmt.Printf("%c", table[i][j])
	//    }
	//    fmt.Println()
	//}
	//fmt.Println()

	var dr = []int{-1, 0, 1, 0}
	var dc = []int{0, 1, 0, -1}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if table[i][j] == c ||
				table[i][j] == '.' {
				continue
			}
			for k := 0; k < 4; k++ {
				var row = i + dr[k]
				var col = j + dc[k]
				if row >= 0 && row < n && col >= 0 && col < m {
					if table[row][col] == c {
						ans++
						mark(table, table[i][j])
					}
				}
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
	"strconv"
	"errors"
)

type p2 struct {
	x, y int
}

func check(x, y int, pc rune, r *[][]rune, c *map[rune]bool) {
	if x < 0 || y < 0 || x >= len((*r)[0]) || y >= len(*r) {
		return
	}
	if (*r)[y][x] != '.' && (*r)[y][x] != pc {
		(*c)[(*r)[y][x]] = true
	}
}
func checkAround(p *p2, r *[][]rune, c *map[rune]bool) {
	check(p.x - 1, p.y, (*r)[p.y][p.x], r, c)
	check(p.x + 1, p.y, (*r)[p.y][p.x], r, c)
	check(p.x, p.y - 1, (*r)[p.y][p.x], r, c)
	check(p.x, p.y + 1, (*r)[p.y][p.x], r, c)
}
func main() {
	l, w, p := nextInt(), nextInt(), ([]rune(nextWord()))[0]
	r := make([][]rune, l)
	pt := make([]*p2, 0)
	for y := 0; y < l; y++ {
		r[y] = []rune(nextWord())
		for x := 0; x < w; x++ {
			if r[y][x] == p {
				pt = append(pt, &p2{x, y})
			}
		}
	}
	colors := make(map[rune]bool)
	for _, pp := range pt {
		checkAround(pp, &r, &colors)
	}
	printf("%d\n", len(colors))
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

func nextInt() int {
	res, err := strconv.Atoi(nextWord())
	if err != nil {
		panic(err)
	}
	return res
}

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/6/B

package main

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

type Cell struct {
	I int
	J int
}

func hasNeighbor(n int, m int, i int, j int, room []string, c string) bool {
	neighbors := []Cell{
		{I: i - 1, J: j},
		{I: i, J: j - 1},
		{I: i, J: j + 1},
		{I: i + 1, J: j},
	}
	for _, cell := range neighbors {
		if 0 <= cell.I && cell.I < n && 0 <= cell.J && cell.J < m && string(room[cell.I][cell.J]) == c {
			return true
		}
	}
	return false
}

func Solve(n int, m int, c string, room []string) int {
	deputies := make(map[string]bool)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if string(room[i][j]) != c && string(room[i][j]) != "." && !deputies[string(room[i][j])] && hasNeighbor(n, m, i, j, room, c) {
				deputies[string(room[i][j])] = true
			}
		}
	}
	return len(deputies)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	var m int
	var c string
	fmt.Fscanf(reader, "%d %d %s\n", &n, &m, &c)
	room := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &room[i])
	}
	fmt.Fprintf(writer, "%d\n", Solve(n, m, c, room))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n, m int
	s, _ := reader.ReadBytes('\n')
	pos := readInt(s, 0, &n)
	pos = readInt(s, pos+1, &m)
	P := s[pos+1]

	R := make([]string, n)

	for i := 0; i < n; i++ {
		R[i], _ = reader.ReadString('\n')
	}

	fmt.Println(solve(n, m, P, R))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, P byte, R []string) int {
	mem := make(map[byte]bool)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] == P {
				for k := 0; k < 4; k++ {
					u, v := i+dd[k], j+dd[k+1]
					if u >= 0 && u < n && v >= 0 && v < n && R[u][v] != P && R[u][v] != '.' {
						mem[R[u][v]] = true
					}
				}
			}
		}
	}

	return len(mem)
}

package main

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

func main() {

	var width, height int
	var presidentColorString string

	_, _ = fmt.Scan(&height)
	_, _ = fmt.Scan(&width)
	_, _ = fmt.Scan(&presidentColorString)

	paddedHeight := height + 2
	paddedWidth := width + 2
	presidentColor := presidentColorString[0]
	empty := byte('.')
	null := byte(0)

	// add padding around room
	room := make([][]byte, paddedHeight)
	for idx := 0; idx < paddedHeight; idx++ {
		room[idx] = make([]byte, paddedWidth)
	}

	scanner := bufio.NewScanner(os.Stdin)

	// iterate total input rows
	for rowIdx := 0; rowIdx < height; rowIdx++ {
		if !scanner.Scan() {
			break
		}

		// slice of row without padding
		row := room[rowIdx+1][1 : width+1]

		// read input into slice
		line := scanner.Bytes()
		for col, ch := range line {
			row[col] = ch
		}
	}

	adjacentToPresident := make(map[byte]interface{})
	for row := 1; row < height+1; row++ {
		for col := 1; col < width+1; col++ {
			if room[row][col] == empty || room[row][col] == null || room[row][col] == presidentColor {
				continue
			}

			if room[row-1][col] == presidentColor || room[row+1][col] == presidentColor ||
				room[row][col+1] == presidentColor || room[row][col-1] == presidentColor {
				adjacentToPresident[room[row][col]] = struct{}{}
			}
		}
	}

	fmt.Println(len(adjacentToPresident))

	for _, row := range room {
		fmt.Println(row)
	}

	fmt.Println(">", presidentColor)

}

package main

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

func main() {

	var width, height int
	var presidentColorString string

	_, _ = fmt.Scan(&height)
	_, _ = fmt.Scan(&width)
	_, _ = fmt.Scan(&presidentColorString)

	paddedHeight := height + 2
	paddedWidth := width + 2
	presidentColor := presidentColorString[0]
	empty := byte('.')

	// add padding around room
	room := make([][]byte, paddedHeight)
	for idx := 0; idx < paddedHeight; idx++ {
		room[idx] = make([]byte, paddedWidth)
	}

	scanner := bufio.NewScanner(os.Stdin)

	for row := 1; row < height+1; row++ {
		if !scanner.Scan() {
			break
		}

		line := scanner.Bytes()
		for col, ch := range line {
			room[row][col+1] = ch
		}
	}

	adjacentToPresident := make(map[byte]interface{})
	for row := 1; row < height+1; row++ {
		for col := 1; col < width+1; col++ {
			if room[row][col] == empty || room[row][col] == presidentColor {
				continue
			}

			if room[row-1][col] == presidentColor || room[row+1][col] == presidentColor ||
				room[row][col+1] == presidentColor || room[row][col-1] == presidentColor {
				adjacentToPresident[room[row][col]] = struct{}{}
			}
		}
	}

	fmt.Println(len(adjacentToPresident))

	// for _, row := range room {
	// 	fmt.Println(row)
	// }
	// fmt.Println(">", presidentColor)

}

package main

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

func main() {

	var width, height int
	var presidentColorString string

	_, _ = fmt.Scan(&height)
	_, _ = fmt.Scan(&width)
	_, _ = fmt.Scan(&presidentColorString)

	paddedHeight := height + 2
	paddedWidth := width + 2
	presidentColor := presidentColorString[0]
	empty := byte('.')
	null := byte(0)

	// add padding around room
	room := make([][]byte, paddedHeight)
	for idx := 0; idx < paddedHeight; idx++ {
		room[idx] = make([]byte, paddedWidth)
	}

	scanner := bufio.NewScanner(os.Stdin)

	for row := 1; row < height+1; row++ {
		if !scanner.Scan() {
			break
		}

		line := scanner.Bytes()
		for col, ch := range line {
			room[row][col+1] = ch
		}
	}

	adjacentToPresident := make(map[byte]interface{})
	for row := 1; row < height+1; row++ {
		for col := 1; col < width+1; col++ {
			if room[row][col] == empty || room[row][col] == null || room[row][col] == presidentColor {
				continue
			}

			if room[row-1][col] == presidentColor || room[row+1][col] == presidentColor ||
				room[row][col+1] == presidentColor || room[row][col-1] == presidentColor {
				adjacentToPresident[room[row][col]] = struct{}{}
			}
		}
	}

	fmt.Println(len(adjacentToPresident))

	// for _, row := range room {
	// 	fmt.Println(row)
	// }
	// fmt.Println(">", presidentColor)

}

package main

import "fmt"

func mark(table [][]byte, c byte) {
	var n = len(table)
	var m = len(table[0])
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if table[i][j] == c {
				table[i][j] = '.'
			}
		}
	}
}

func main() {
	var n, m int
	var c byte
	_, _ = fmt.Scanf("%d %d %c\n", &n, &m, &c)
	var table = make([][]byte, n)
	for i := 0; i < n; i++ {
		table[i] = make([]byte, m)
		_, _ = fmt.Scanf("%s", &table[i])
	}
	var ans = 0

	var dr = []int{-1, 0, 1, 0}
	var dc = []int{0, 1, 0, -1}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if table[i][j] == c ||
				table[i][j] == '.' {
				continue
			}
			for k := 0; k < 4; k++ {
				var row = i + dr[k]
				var col = j + dc[k]
				if row >= 0 && row < n && col >= 0 && col < m {
					if table[row][col] == c {
						ans++
						mark(table, table[i][j])
					}
				}
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = (1 << uint(n+1)) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}


package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

const mod = 998244353

func Bin(a int64, n int) int64 {
	var ans int64
	ans = 1
	for ; n > 0; n /= 2 {
		if n % 2 == 1 {
			ans = ans * a
			ans %= mod
		}
		a = a * a
		a %= mod
	}
	return ans
}

func inv(a int64) int64 {
	return Bin(a, mod - 2)
}

func solve() {
	var n int
	scanf("%d\n", &n)
	v := make([]int, 2 * n)
	for i := 0; i < 2 * n; i++ {
		scanf("%d ",&v[i])
	}
	sort.Ints(v)
	var res int64
	res = 0
	for i := 0; i < n; i++ {
		res += int64(v[n + i] - v[i])
		res %= mod
	}
	var n1 int64
	n1 = 1
	for i := 1; i <= n; i++ {
		n1 *= int64(i)
		n1 %= mod
	}
	var n2 int64
	n2 = 1
	for i := 1; i <= 2 * n; i++ {
		n2 *= int64(i)
		n2 %= mod
	}
	var ans int64
	ans = n2 * inv(n1) % mod * inv(n1) % mod
	ans = ans * res
	ans %= mod
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	solve()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1444B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mod int64 = 998244353
	pow := func(x, n int64) (res int64) {
		res = 1
		for ; n > 0; n >>= 1 {
			if n&1 == 1 {
				res = res * x % mod
			}
			x = x * x % mod
		}
		return res
	}

	var n int64
	Fscan(in, &n)
	a := make([]int, 2*n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	s := int64(0)
	for _, v := range a[:n] {
		s -= int64(v)
	}
	for _, v := range a[n:] {
		s += int64(v)
	}
	f := int64(1)
	for i := int64(2); i <= n; i++ {
		f = f * i % mod
	}
	inv := pow(f, mod-2)
	for i := n + 1; i <= 2*n; i++ {
		f = f * i % mod
	}
	Fprint(out, s%mod*f%mod*inv%mod*inv%mod)
}

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

package main

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

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

	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Sort(sort.IntSlice(a))

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &b[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(b)))

	sum := uint64(0)
	k := uint64(1)

	for i := 0; i < n; i++ {
		sum += uint64(abs(a[i] - b[i]))
		k = k * divide(uint64(2*n-i), uint64(n-i)) % mod

	}

	sum %= 998244353

	fmt.Fprint(out, (sum*k)%mod, "\n")
}

const mod = 998244353

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func bin_pow(base, p uint64) uint64 {
	if p == 1 {
		return base
	}

	if p%2 == 0 {
		t := bin_pow(base, p/2)
		return t * t % mod
	} else {
		return bin_pow(base, p-1) * base % mod
	}
}

func inverse_element(x uint64) uint64 {
	return bin_pow(x, mod-2)
}

func divide(a, b uint64) uint64 {
	return a * inverse_element(b) % mod
}

package main

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

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

	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Sort(sort.IntSlice(a))

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &b[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(b)))

	sum := 0
	k := 1

	for i := 0; i < n; i++ {
		sum += abs(a[i] - b[i])
		k = k * divide(2*n-i, n-i) % mod

	}

	sum %= 998244353

	fmt.Fprint(out, (sum*k)%mod, "\n")
}

const mod = 998244353

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func bin_pow(base, p int) int {
	if p == 1 {
		return base
	}

	if p%2 == 0 {
		t := bin_pow(base, p/2)
		return t * t % mod
	} else {
		return bin_pow(base, p-1) * base % mod
	}
}

func inverse_element(x int) int {
	return bin_pow(x, mod-2)
}

func divide(a, b int) int {
	return a * inverse_element(b) % mod
}

package main

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

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

	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Sort(sort.IntSlice(a))

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &b[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(b)))

	sum := 0
	k := 1
	kk := 1

	for i := 0; i < n; i++ {
		sum += abs(a[i] - b[i])
		k = (k * (2*n - i)) % 998244353
		kk = (kk * (n - i)) % 998244353

		if k%kk == 0 {
			k /= kk
			kk = 1
		}
	}

	sum %= 998244353

	fmt.Fprint(out, sum*((k/kk)%998244353)%998244353, "\n")
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

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

	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(in, &n)

	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}

	sort.Sort(sort.IntSlice(a))

	for i := 0; i < n; i++ {
		fmt.Fscan(in, &b[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(b)))

	sum := 0
	k := 1
	kk := 1

	for i := 0; i < n; i++ {
		sum += abs(a[i] - b[i])
		k = (k * (2*n - i))

		if k%(n-i) == 0 {
			k /= n - i
		} else {
			kk = (kk * (n - i))
		}

		if k%kk == 0 {
			k /= kk
			kk = 1
		}
	}

	sum %= 998244353

	fmt.Fprint(out, (sum*((k/kk)%998244353))%998244353, "\n")
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

const mod = 998244353

func Bin(a int64, n int) int64 {
	var ans int64
	ans = 1
	for ; n > 0; n /= 2 {
		if n % 2 == 1 {
			ans = ans * a
			ans %= mod
		}
		a = a * a
		a %= mod
	}
	return ans
}

func inv(a int64) int64 {
	return Bin(a, mod - 2)
}

func solve() {
	var n int
	scanf("%d\n", &n)
	v := make([]int, 2 * n)
	for i := 0; i < 2 * n; i++ {
		scanf("%d ",&v[i])
	}
	sort.Ints(v)
	var res int64
	res = 0
	for i := 0; i < n; i++ {
		res += int64(v[n + i] - v[i])
	}
	var n1 int64
	n1 = 1
	for i := 1; i <= n; i++ {
		n1 *= int64(i)
		n1 %= mod
	}
	var n2 int64
	n2 = 1
	for i := 1; i <= 2 * n; i++ {
		n2 *= int64(i)
		n2 %= mod
	}
	var ans int64
	ans = n2 * inv(n1) % mod * inv(n1) % mod
	ans = ans * res
	ans %= mod
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	solve()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

const mod = 998244353

func Bin(a int64, n int) int64 {
	var ans int64
	ans = 1
	for ; n > 0; n /= 2 {
		if n % 2 == 1 {
			ans = ans * a
			ans %= mod
		}
		a = a * a
		a %= mod
	}
	return ans
}

func inv(a int64) int64 {
	return Bin(a, mod - 2)
}

func solve() {
	var n int
	scanf("%d\n", &n)
	v := make([]int, 2 * n)
	for i := 0; i < 2 * n; i++ {
		scanf("%d ",&v[i])
	}
	sort.Ints(v)
	var res int64
	res = 0
	for i := 0; i < n; i++ {
		res += int64(v[n + i] - v[i])
	}
	var n1 int64
	n1 = 1
	for i := 1; i <= n; i++ {
		n1 *= int64(i)
		n1 %= mod
	}
	var n2 int64
	n2 = 1
	for i := 1; i <= 2 * n; i++ {
		n2 *= int64(i)
		n2 %= mod
	}
	var ans int64
	ans = n2 * inv(n1) % mod * inv(n1)
	ans = ans * res
	ans %= mod
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	solve()
}


package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int64
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int64
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		var sum int64 = math.MinInt64
		sort.Slice(positive, func(i, j int) bool {
			return positive[i] < positive[j]
		})
		sort.Slice(negative, func(i, j int) bool {
			return negative[i] < negative[j]
		})

		for pnums := 0; pnums <= 5; pnums++ {
			if len(negative) < 5-pnums || len(positive) < pnums {
				continue
			}

			if (5-pnums)%2 != 0 {
				var tmpSum int64 = 1
				for i := 0; i < pnums; i++ {
					tmpSum = tmpSum * positive[i]
				}

				for j := len(negative) - 1; j > len(negative)-6+pnums; j-- {
					tmpSum = tmpSum * negative[j]
				}

				sum = MPMax(sum, tmpSum)
			} else {
				var tmpSum int64 = 1
				for i := 0; i < pnums; i++ {
					tmpSum = tmpSum * positive[len(positive)-i-1]
				}

				for j := 0; j < 5-pnums; j++ {
					tmpSum = tmpSum * negative[j]
				}

				sum = MPMax(sum, tmpSum)
			}

		}

		if zeroFlag {
			sum = MPMax(sum, 0)
		}

		Fprintln(out, sum)
	}
}

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

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

/*
URL:
https://codeforces.com/contest/1406/problem/B
*/

package main

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

var (
	t int

	n int
	A []int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()
		A = readlls(n)

		solve()
	}
}

func solve() {
	P, N := []int64{}, []int64{}
	O := []int64{}

	pos, neg, zero := 0, 0, 0
	for _, a := range A {
		if a > 0 {
			P = append(P, a)
			O = append(O, a)
			pos++
		} else if a < 0 {
			N = append(N, -a)
			O = append(O, -a)
			neg++
		} else {
			zero++
			O = append(O, a)
		}
	}

	sort.Slice(P, func(i, j int) bool {
		return P[i] > P[j]
	})
	sort.Slice(N, func(i, j int) bool {
		return N[i] > N[j]
	})
	// Oは絶対値の小さい順
	sort.Slice(O, func(i, j int) bool {
		return O[i] < O[j]
	})

	var ans int64
	ans = -INF_B60

	if zero > 0 {
		ans = 0
	}

	if pos >= 5 {
		tmp := int64(1)
		for i := 0; i < 5; i++ {
			tmp *= P[i]
		}
		ChMax(&ans, tmp)
	}

	if neg >= 2 && pos >= 3 {
		tmp := int64(1)
		for i := 0; i < 2; i++ {
			tmp *= N[i]
		}
		for i := 0; i < 3; i++ {
			tmp *= P[i]
		}
		ChMax(&ans, tmp)
	}

	if neg >= 4 && pos >= 1 {
		tmp := int64(1)
		for i := 0; i < 4; i++ {
			tmp *= N[i]
		}
		for i := 0; i < 1; i++ {
			tmp *= P[i]
		}
		ChMax(&ans, tmp)
	}

	// 負のパターン
	tmp := int64(1)
	for i := 0; i < 5; i++ {
		tmp *= O[i]
	}
	ChMax(&ans, -tmp)

	fmt.Println(ans)
}

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

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
)

// modi can calculate a right residual whether value is positive or negative.
func modi(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

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

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  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()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// 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)
}

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

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

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

// 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
}

package main

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

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}

func main() {
	io := newFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	t := io.nextInt()
	for i := 0; i < t; i++ {
		n := io.nextInt()
		var a []int64
		for j := 0; j < n; j++ {
			g := int64(io.nextInt())
			a = append(a, g)
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		best := a[n-1] * a[n-2] * a[n-3] * a[n-4] * a[n-5]
		cur := a[0] * a[1] * a[n-1] * a[n-2] * a[n-3]
		if cur > best {
			best = cur
		}
		cur = a[0] * a[1] * a[2] * a[3] * a[n-1]
		if cur > best {
			best = cur
		}
		sort.Slice(a, func(i, j int) bool { return abs(a[i]) < abs(a[j]) })
		cur = a[0] * a[1] * a[2] * a[3] * a[4]
		if cur > best {
			best = cur
		}
		fmt.Printf("%d\n", best)
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p [1]byte
}

func newFastIO(r io.Reader, w io.Writer) *fastIO {
	return &fastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	neg := false
	if f.p[0] == '-' {
		neg = true
		f.Read(f.p[:])
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p[:])
	}
	if neg {
		return -n
	}
	return n
}

func (f *fastIO) nextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.nextInt()
	}
	return a
}

func (f *fastIO) next() string {
	f.Read(f.p[:])
	for f.p[0] <= ' ' {
		f.Read(f.p[:])
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p[:])
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *fastIO) printInts(a ...int) {
	if len(a) > 0 {
		f.print(a[0])
		for _, x := range a[1:] {
			f.print(" ", x)
		}
	}
}

func (f *fastIO) printlnInts(a ...int) {
	f.printInts(a...)
	f.println()
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	n := rw.NextInt()
	a := rw.NextInt64s(n)
	sort.Slice(a[:], func(i, j int) bool { return a[i] < a[j] })
	var ans int64
	for i := 0; i <= 5; i++ {
		cur := int64(1)
		for j := 0; j < i; j++ {
			cur *= a[j]
		}
		for j := 0; j < 5-i; j++ {
			cur *= a[n-1-j]
		}
		if i == 0 || cur > ans {
			ans = cur
		}
	}
	rw.Println(ans)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

type Int64 []int64

func (a Int64) Less(i, j int) bool {
	return a[i] < a[j]
}

func (a Int64) Len() int {
	return len(a)
}

func (a Int64) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func maxProduct(a []int64, n int) int64 {
	sort.Sort(Int64(a))
	var ans, tempAns int64
	ans = a[n-1] * a[n-2] * a[n-3] * a[n-4] * a[n-5]
	tempAns = a[0] * a[1] * a[2] * a[3] * a[n-1]
	if tempAns > ans {
		ans = tempAns
	}
	tempAns = a[0] * a[1] * a[n-1] * a[n-2] * a[n-3]
	if tempAns > ans {
		ans = tempAns
	}
	return ans
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t, n int
	var ans int64
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscanln(reader, &n)
		a := make([]int64, n)
		for j := 0; j < n-1; j++ {
			fmt.Fscanf(reader, "%d ", &a[j])
		}
		fmt.Fscanf(reader, "%d\n", &a[n-1])
		ans = maxProduct(a, n)
		fmt.Fprintln(writer, ans)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.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 suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		a := make([]int64, n)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(a))
	}
}

func prod(a []int64) int64 {
	ret := int64(1)
	for _, ai := range a {
		ret *= ai
	}
	return ret
}

func sol(a []int64) int64 {
	sort.Slice(a, func(il, ir int) bool {
		return a[il] < a[ir]
	})
	return max(
		prod([]int64{a[len(a)-5], a[len(a)-4], a[len(a)-3], a[len(a)-2], a[len(a)-1]}),
		prod([]int64{a[0], a[len(a)-4], a[len(a)-3], a[len(a)-2], a[len(a)-1]}),
		prod([]int64{a[0], a[1], a[len(a)-3], a[len(a)-2], a[len(a)-1]}),
		prod([]int64{a[0], a[1], a[2], a[len(a)-2], a[len(a)-1]}),
		prod([]int64{a[0], a[1], a[2], a[3], a[len(a)-1]}),
		prod([]int64{a[0], a[1], a[2], a[3], a[4]}),
	)
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		a := io.NextInts(n)

		mx, mn := make([]int64, n+1), make([]int64, n+1)
		for i := range mx {
			mx[i], mn[i] = 1, 1
		}
		for i := 0; i < 5; i++ {
			nmx, nmn := make([]int64, n+1), make([]int64, n+1)
			nmx[i], nmn[i] = math.MinInt64, math.MaxInt64
			for j := i + 1; j <= n; j++ {
				x := int64(a[j-1])
				a, b := x*mx[j-1], x*mn[j-1]
				nmx[j], nmn[j] = max(nmx[j-1], max(a, b)), min(nmn[j-1], min(a, b))
			}
			mx, mn = nmx, nmn
		}
		io.Println(mx[n])
	}
}

func min(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func max(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func ifPositiveLessThenTwo(arr []int) int64 {
	return int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[len(arr)-1])
}

func maxMultiplication(arr []int) int64 {
	N := len(arr)
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	cases := [][]int{
		{0, 1, 2, 3, N-1},
		{0, 1, N-1, N-2, N-3},
		{N - 5,  N - 4, N-3, N-2, N-1},
	}

	maxMul := int64(math.MinInt64)
	for _, c := range cases {
		mul := int64(1)
		for _, el := range c {
			mul *= int64(arr[el])
		}

		if maxMul < mul {
			maxMul = mul
		}
	}

	return maxMul
}

func main() {
	defer writer.Flush()
	var N int
	scanf("%d\n", &N)

	var M int
	for i := 0; i < N; i++ {
		scanf("%d\n", &M)
		arr := make([]int, M)
		for j := 0; j < M; j++ {
			scanf("%d", &arr[j])
		}
		scanf("\n")

		printf("%d\n", maxMultiplication(arr))
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		var ans int64

		if mx < 0 {
			ans = int64(arr[n-1]) * int64(arr[n-2]) * int64(arr[n-3]) * int64(arr[n-4]) * int64(arr[n-5])
			printf("%v\n", ans)
		} else {
			ans = int64(arr[0]) * int64(arr[1]) * int64(arr[2]) * int64(arr[3]) * int64(arr[4])
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					var temp int64
					temp = int64(arr[i])
					for k := 0; k < 5; k++ {
						if k != j {
							temp *= int64(arr[k])
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%v\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func ifPositiveLessThenTwo(arr []int) int64 {
	return int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[len(arr)-1])
}

func maxMultiplication(arr []int) int64 {
	N := len(arr)
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	if arr[N-3] <= 0 {
		return ifPositiveLessThenTwo(arr)
	}

	mul := int64(1)
	left := 0
	right := len(arr) - 1

	if arr[left]*arr[left+1] >= arr[right]*arr[right-1] {
		mul *= int64(arr[left] * arr[left+1])
		left += 2
	} else {
		mul *= int64(arr[right] * arr[right-1])
		right -= 2
	}

	if arr[left]*arr[left+1] >= arr[right]*arr[right-1] {
		mul *= int64(arr[left] * arr[left+1])
		left += 2
	} else {
		mul *= int64(arr[right] * arr[right-1])
		right -= 2
	}

	if arr[left] > arr[right] {
		mul *= int64(arr[left])
	} else {
		mul *= int64(arr[right])
	}

	return mul
}

func main() {
	defer writer.Flush()
	var N int
	scanf("%d\n", &N)

	var M int
	for i := 0; i < N; i++ {
		scanf("%d\n", &M)
		arr := make([]int, M)
		for j := 0; j < M; j++ {
			scanf("%d", &arr[j])
		}
		scanf("\n")

		printf("%d", maxMultiplication(arr))
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func ifPositiveLessThenTwo(arr []int) int64 {
	return int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[len(arr)-1])
}

func maxMultiplication(arr []int) int64 {
	N := len(arr)
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	if arr[N-3] <= 0 {
		return ifPositiveLessThenTwo(arr)
	}

	mul := int64(1)
	left := 0
	right := len(arr) - 1

	if arr[left]*arr[left+1] >= arr[right]*arr[right-1] {
		mul *= int64(arr[left] * arr[left+1])
		left += 2
	} else {
		mul *= int64(arr[right] * arr[right-1])
		right -= 2
	}

	if arr[left]*arr[left+1] >= arr[right]*arr[right-1] {
		mul *= int64(arr[left] * arr[left+1])
		left += 2
	} else {
		mul *= int64(arr[right] * arr[right-1])
		right -= 2
	}

	if arr[left] > arr[right] {
		mul *= int64(arr[left])
	} else {
		mul *= int64(arr[right])
	}

	return mul
}

func main() {
	defer writer.Flush()
	var N int
	scanf("%d\n", &N)

	var M int
	for i := 0; i < N; i++ {
		scanf("%d\n", &M)
		arr := make([]int, M)
		for j := 0; j < M; j++ {
			scanf("%d", &arr[j])
		}
		scanf("\n")

		printf("%d\n", maxMultiplication(arr))
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		if mx < 0 {
			printf("%d\n", arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5])
		} else {
			ans := 0
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					temp := arr[i]
					for k := 0; k < 5; k++ {
						if k != j {
							temp = temp * arr[k]
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		scanf("\n")

		var m int
		m = 1
		for i := 0; i < 5; i++ {
			m = m * arr[i]
		}

		ans := m
		for i := 5; i < n; i++ {
			m := m * arr[i]
			for j := i - 5; j < i; j++ {
				if arr[j] != 0 && ans < m/arr[j] {
					ans = m / arr[j]
				}
			}
			if arr[i-5] != 0 {
				m = m / arr[i-5]
			}
		}
		printf("%d\n", ans)
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		var ans int64

		if mx < 0 {
			ans = int64(arr[n-1] * arr[n-2] * arr[n-3] * arr[n-4] * arr[n-5])
			printf("%d\n", ans)
		} else {
			ans = int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[4])
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					var temp int64
					temp = int64(arr[i])
					for k := 0; k < 5; k++ {
						if k != j {
							temp *= int64(arr[k])
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		var ans int64

		if mx < 0 {
			printf("%d\n", int64(arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5]))
		} else {
			ans = int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[4])
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					var temp int64
					temp = int64(arr[i])
					for k := 0; k < 5; k++ {
						if k != j {
							temp *= int64(arr[k])
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		if mx < 0 {
			printf("%d\n", arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5])
		} else {
			ans := arr[0] * arr[1] * arr[2] * arr[3] * arr[4]
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					temp := arr[i]
					for k := 0; k < 5; k++ {
						if k != j {
							temp = temp * arr[k]
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		var ans int64

		if mx < 0 {
			ans = int64(arr[n-1] * arr[n-2] * arr[n-3] * arr[n-4] * arr[n-5])
			printf("%v\n", ans)
		} else {
			ans = int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[4])
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					var temp int64
					temp = int64(arr[i])
					for k := 0; k < 5; k++ {
						if k != j {
							temp *= int64(arr[k])
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%v\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(i)) < math.Abs(float64(j))
		})
		// printf("%d\n", arr)
		if mx < 0 {
			printf("%d\n", arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5])
		} else {
			ans := 0
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					temp := arr[i]
					for k := 0; k < 5; k++ {
						if k != j {
							temp = temp * arr[k]
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
		}
		scanf("\n")

		var m int
		m = 1
		for i := 0; i < 5; i++ {
			m = m * arr[i]
		}

		ans := m
		for i := 5; i < n; i++ {
			m := m * arr[i]
			for j := i - 5; j < i; j++ {
				if arr[j] == 0 {
					arr[j] = 1
					if ans < 0 {
						ans = 0
					}
				}
				if ans < m/arr[j] {
					ans = m / arr[j]
				}
			}
			m = m / arr[i-5]
		}
		printf("%d\n", ans)
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		// printf("%d\n", arr)
		if mx < 0 {
			printf("%d\n", arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5])
		} else {
			var ans int64
			ans = int64(arr[0] * arr[1] * arr[2] * arr[3] * arr[4])
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					var temp int64
					temp = int64(arr[i])
					for k := 0; k < 5; k++ {
						if k != j {
							temp *= int64(arr[k])
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for t > 0 {

		var n int
		scanf("%d\n", &n)
		var arr []int
		arr = make([]int, n)
		mx := math.MinInt16
		for i := 0; i < n; i++ {
			scanf("%d", &arr[i])
			if mx < arr[i] {
				mx = arr[i]
			}
		}
		scanf("\n")
		sort.SliceStable(arr, func(i, j int) bool {
			return math.Abs(float64(arr[i])) > math.Abs(float64(arr[j]))
		})
		printf("%d\n", arr)
		if mx < 0 {
			printf("%d\n", arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5])
		} else {
			ans := 0
			for i := 5; i < n; i++ {
				for j := 0; j < 5; j++ {
					temp := arr[i]
					for k := 0; k < 5; k++ {
						if k != j {
							temp = temp * arr[k]
						}
					}
					if ans < temp {
						ans = temp
					}
				}
			}
			printf("%d\n", ans)
		}
		t--
	}
}

package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			switch total {
			case 0:
				// 正大于2，负数大于2
				if nend+1 < len(negative) && pend-1 >= 0 {
					if negative[nend]*negative[nend+1] >= positive[pend]*positive[pend-1] || pend-2 < 0 {
						sum = sum * negative[nend] * negative[nend+1]
						nend += 2
						total += 2
					} else {
						sum = sum * positive[pend] * positive[pend-1]
						pend -= 2
						total += 2
					}
				} else if nend+1 < len(negative) {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			case 2:
				var tmpmax int = math.MinInt32
				// 0正数
				if nend+2 < len(negative) {
					tmpmax = negative[nend] * negative[nend+1] * negative[nend+2]
				}

				// 1个正数
				if pend >= 0 && nend+1 < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*negative[nend+1]*positive[pend])

					// 能不能拿3个
					if pend >= 3 {
						if positive[pend]*positive[pend-1]*positive[pend-2] < negative[nend]*negative[nend+1]*positive[pend] {

						} else {
							tmpmax = positive[pend] * positive[pend-1] * positive[pend-2]
						}
					}
				}

				//2正数
				if pend >= 1 && nend < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*positive[pend-1]*positive[pend])
				}

				//3正数
				if pend >= 2 {
					tmpmax = MPMax(tmpmax, positive[pend]*positive[pend-1]*positive[pend-2])
				}

				sum = sum * tmpmax
				total += 3

			}
		}

		if zeroFlag {
			sum = MPMax(0, sum)
		}

		Fprintln(out, sum)
	}
}

func MPMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	MaxProduct(os.Stdin, os.Stdout)
}

package main

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

/*
4
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		Println(positive, negative)

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {

			if total == 4 {
				if pend >= 0 {
					sum = sum * positive[pend]
					pend--
					total++
				} else {
					sum = sum * negative[len(negative)-1]
					total++
				}
				continue
			}

			if nend+1 < len(negative) && pend-1 >= 0 {
				if negative[nend]*negative[nend+1] > positive[pend]*positive[pend-1] || pend-2 < 0 {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			} else if nend+1 < len(negative) {
				sum = sum * negative[nend] * negative[nend+1]
				nend += 2
				total += 2
			} else {
				sum = sum * positive[pend] * positive[pend-1]
				pend -= 2
				total += 2
			}
		}

		Fprintln(out, sum)
	}
}

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

package main

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

/*
4
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {

			if total == 4 {
				if pend >= 0 {
					sum = sum * positive[pend]
					pend--
					total++
				} else {
					sum = sum * negative[len(negative)-1]
					total++
				}
				continue
			}

			if nend+1 < len(negative) && pend-1 >= 0 {
				if negative[nend]*negative[nend+1] > positive[pend]*positive[pend-1] || pend-2 < 0 {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			} else if nend+1 < len(negative) {
				sum = sum * negative[nend] * negative[nend+1]
				nend += 2
				total += 2
			} else {
				sum = sum * positive[pend] * positive[pend-1]
				pend -= 2
				total += 2
			}
		}

		Fprintln(out, sum)
	}
}

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

package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := math.MinInt32

		sort.Ints(positive)
		sort.Ints(negative)

		for pnums := 0; pnums <= 5; pnums++ {
			if len(negative) < 5-pnums || len(positive) < pnums {
				continue
			}

			if (5-pnums)%2 != 0 {
				tmpSum := 1
				for i := 0; i < pnums; i++ {
					tmpSum = tmpSum * positive[i]
				}

				for j := len(negative) - 1; j > len(negative)-6+pnums; j-- {
					tmpSum = tmpSum * negative[j]
				}

				sum = MPMax(sum, tmpSum)
			} else {
				tmpSum := 1
				for i := 0; i < pnums; i++ {
					tmpSum = tmpSum * positive[len(positive)-i-1]
				}

				for j := 0; j < 5-pnums; j++ {
					tmpSum = tmpSum * negative[j]
				}

				sum = MPMax(sum, tmpSum)
			}

		}

		if zeroFlag {
			sum = MPMax(sum, 0)
		}

		Fprintln(out, sum)
	}
}

func MaxProduct1(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			switch total {
			case 0:
				// 正大于2，负数大于2
				if nend+1 < len(negative) && pend-1 >= 0 {
					if negative[nend]*negative[nend+1] >= positive[pend]*positive[pend-1] || pend-2 < 0 {
						sum = sum * negative[nend] * negative[nend+1]
						nend += 2
						total += 2
					} else {
						sum = sum * positive[pend] * positive[pend-1]
						pend -= 2
						total += 2
					}
				} else if nend+1 < len(negative) {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			case 2:
				var tmpmax int = math.MinInt32
				// 0正数
				if nend+2 < len(negative) {
					tmpmax = negative[nend] * negative[nend+1] * negative[nend+2]
				}

				// 1个正数
				if pend >= 0 && nend+1 < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*negative[nend+1]*positive[pend])

					// 能不能拿3个
					if pend >= 3 {
						if positive[pend]*positive[pend-1]*positive[pend-2] < negative[nend]*negative[nend+1]*positive[pend] {

						} else {
							tmpmax = positive[pend] * positive[pend-1] * positive[pend-2]
						}
					}
				}

				//2正数
				if pend >= 1 && nend < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*positive[pend-1]*positive[pend])
				}

				//3正数
				if pend >= 2 {
					tmpmax = MPMax(tmpmax, positive[pend]*positive[pend-1]*positive[pend-2])
				}

				sum = sum * tmpmax
				total += 3

			}
		}

		if zeroFlag {
			sum = MPMax(0, sum)
		}

		Fprintln(out, sum)
	}
}

func MPMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	MaxProduct(os.Stdin, os.Stdout)
}

package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			switch total {
			case 0:
				// 正大于2，负数大于2
				if nend+1 < len(negative) && pend-1 >= 0 {
					if negative[nend]*negative[nend+1] >= positive[pend]*positive[pend-1] || pend-2 < 0 {
						sum = sum * negative[nend] * negative[nend+1]
						nend += 2
						total += 2
					} else {
						sum = sum * positive[pend] * positive[pend-1]
						pend -= 2
						total += 2
					}
				} else if nend+1 < len(negative) {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			case 2:
				var tmpmax int = math.MinInt32
				// 0正数
				if nend+2 < len(negative) {
					tmpmax = negative[nend] * negative[nend+1] * negative[nend+2]
				}

				// 1个正数
				if pend >= 0 && nend+1 < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*negative[nend+1]*positive[pend])

					// 能不能拿3个
					if pend >= 3 {
						if positive[pend]*positive[pend-1]*positive[pend-2] < negative[nend]*negative[nend+1]*positive[pend] {

						} else {
							tmpmax = positive[pend] * positive[pend-1] * positive[pend-2]
						}
					}
				}

				//2正数
				if pend >= 1 && nend < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*positive[pend-1]*positive[pend])
				}

				//3正数
				if pend >= 2 {
					tmpmax = MPMax(tmpmax, positive[pend]*positive[pend-1]*positive[pend-2])
				}

				sum = sum * tmpmax
				total += 3

			}

		}

		Fprintln(out, sum)
	}
}

func MPMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	MaxProduct(os.Stdin, os.Stdout)
}

package main

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

/*
4
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := -1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			if total == 4 {
				if pend >= 0 {
					sum = sum * positive[pend]
					pend--
					total++
				} else {
					sum = sum * negative[len(negative)-1]
					total++
				}
				continue
			}

			if nend+1 < len(negative) && pend-1 >= 0 {
				if negative[nend]*negative[nend+1] > positive[pend]*positive[pend-1] {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			} else if nend+1 < len(negative) {
				sum = sum * negative[nend] * negative[nend+1]
				nend += 2
				total += 2
			} else {
				sum = sum * positive[pend] * positive[pend-1]
				pend -= 2
				total += 2
			}
		}

		Fprintln(out, sum)
	}
}

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

package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			switch total {
			case 0:
				// 正大于2，负数大于2
				if nend+1 < len(negative) && pend-1 >= 0 {
					if negative[nend]*negative[nend+1] > positive[pend]*positive[pend-1] || pend-2 < 0 {
						sum = sum * negative[nend] * negative[nend+1]
						nend += 2
						total += 2
					} else {
						sum = sum * positive[pend] * positive[pend-1]
						pend -= 2
						total += 2
					}
				} else if nend+1 < len(negative) {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			case 2:
				var tmpmax int = math.MinInt32
				// 0正数
				if nend+2 < len(negative) {
					tmpmax = negative[nend] * negative[nend+1] * negative[nend+2]
				}

				// 1个正数
				if pend >= 0 && nend+1 < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*negative[nend+1]*positive[pend])

					// 能不能拿3个
					if pend >= 3 {
						if positive[pend]*positive[pend-1]*positive[pend-2] < negative[nend]*negative[nend+1]*positive[pend] {

						} else {
							tmpmax = positive[pend] * positive[pend-1] * positive[pend-2]
						}
					}
				}

				//2正数
				if pend >= 1 && nend < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*positive[pend-1]*positive[pend])
				}

				//3正数
				if pend >= 2 {
					tmpmax = MPMax(tmpmax, positive[pend]*positive[pend-1]*positive[pend-2])
				}

				sum = sum * tmpmax
				total += 3

			}

		}

		Fprintln(out, sum)
	}
}

func MPMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	MaxProduct(os.Stdin, os.Stdout)
}

package main

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

/*
5
5
-1 -2 -3 -4 -5
6
-1 -2 -3 1 2 -1
6
-1 0 0 0 -1 -1
6
-9 -7 -5 -3 -2 1
10
1 1 -4 -5 -3 -1 4 5 -3 -1

*/

func MaxProduct(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		var positive, negative []int
		Fscan(in, &N)

		zeroFlag := false

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			if S > 0 {
				positive = append(positive, S)
			} else if S < 0 {
				negative = append(negative, S)
			} else {
				zeroFlag = true
			}
		}

		if (len(negative)+len(positive) < 5) || (len(positive) == 0 && zeroFlag) {
			Fprintln(out, 0)
			continue
		}

		sum := 1
		total := 0

		sort.Ints(positive)
		sort.Ints(negative)

		pend := len(positive) - 1
		nend := 0
		for total < 5 {
			switch total {
			case 0:
				// 正大于2，负数大于2
				if nend+1 < len(negative) && pend-1 >= 0 {
					if negative[nend]*negative[nend+1] > positive[pend]*positive[pend-1] || pend-2 < 0 {
						sum = sum * negative[nend] * negative[nend+1]
						nend += 2
						total += 2
					} else {
						sum = sum * positive[pend] * positive[pend-1]
						pend -= 2
						total += 2
					}
				} else if nend+1 < len(negative) {
					sum = sum * negative[nend] * negative[nend+1]
					nend += 2
					total += 2
				} else {
					sum = sum * positive[pend] * positive[pend-1]
					pend -= 2
					total += 2
				}
			case 2:
				var tmpmax int
				// 0正数
				if nend+2 < len(negative) {
					tmpmax = negative[nend] * negative[nend+1] * negative[nend+2]
				}

				// 1个正数
				if pend >= 0 && nend+1 < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*negative[nend+1]*positive[pend])

					// 能不能拿3个
					if pend >= 3 {
						if positive[pend]*positive[pend-1]*positive[pend-2] < negative[nend]*negative[nend+1]*positive[pend] {

						} else {
							tmpmax = positive[pend] * positive[pend-1] * positive[pend-2]
						}
					}
				}

				//2正数
				if pend >= 1 && nend < len(negative) {
					tmpmax = MPMax(tmpmax, negative[nend]*positive[pend-1]*positive[pend])
				}

				//3正数
				if pend >= 2 {
					tmpmax = MPMax(tmpmax, positive[pend]*positive[pend-1]*positive[pend-2])
				}

				sum = sum * tmpmax
				total += 3

			}

		}

		Fprintln(out, sum)
	}
}

func MPMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func main() {
	MaxProduct(os.Stdin, os.Stdout)
}

package main

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

type Int64 []int64

func (a Int64) Less(i, j int) bool {
	return a[i] < a[j]
}

func (a Int64) Len() int {
	return len(a)
}

func (a Int64) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func maxProduct(a []int64, n int) int64 {
	sort.Sort(Int64(a))
	var ans, tempAns int64
	ans = a[n-1] * a[n-2] * a[n-3] * a[n-4] * a[n-5]
	tempAns = a[0] * a[1] * a[2] * a[3] * a[n-1]
	if tempAns > ans {
		ans = tempAns
	}
	tempAns = a[0] * a[1] * a[n-3] * a[n-4] * a[n-5]
	if tempAns > ans {
		ans = tempAns
	}
	return ans
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t, n int
	var ans int64
	fmt.Fscanln(reader, &t)
	for i := 0; i < t; i++ {
		fmt.Fscanln(reader, &n)
		a := make([]int64, n)
		for j := 0; j < n-1; j++ {
			fmt.Fscanf(reader, "%d ", &a[j])
		}
		fmt.Fscanf(reader, "%d\n", &a[n-1])
		ans = maxProduct(a, n)
		fmt.Fprintln(writer, ans)
	}
}