// Author: sighduck
// URL: https://codeforces.com/problemset/problem/715/A

package main

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

func Solve(n int64) []int64 {
	ans := make([]int64, n)
	x := int64(2)
	for i := int64(1); i <= n; i++ {
		ans[i-1] = i*(i+1)*(i+1) - x/i
		x = i * (i + 1)
	}
	return ans
}

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

	var n int64
	fmt.Fscanf(reader, "%d\n", &n)

	for _, elem := range Solve(n) {
		fmt.Fprintf(writer, "%d\n", elem)
	}
}

package main

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

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

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

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

	var n int64
	fmt.Scan(&n)

	var x int64 = 2
	var k int64 = 1
	for k <= n {
		lcm := lcm(k, k+1)
		ans := (lcm/k)*lcm - (x / k)
		writer.WriteString(strconv.FormatInt(ans, 10))
		writer.WriteByte('\n')
		x = lcm
		k++
	}
}

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n, a, x, k int64
	fmt.Fscanf(bufin, "%d\n", &n)

	a = 2
	for k = 1; k <= n; k++ {
		x = k*(k+1)*(k+1) - a/k
		a = k * (k + 1)
		fmt.Fprintf(bufout, "%d\n", x)
	}
}

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

var p []int64
var np int

func sqr(x int64) int64 {
	return x * x
}

func multiple(k int64) (int64, int64) {
	ret := int64(1)
	m := int64(1)

	for i := 0; i < np && sqr(p[i]) <= k; i++ {
		cnt := 0
		for k%p[i] == 0 {
			cnt++
			k /= p[i]
		}
		if (cnt > 0) && (cnt%2 == 1) {
			ret *= p[i]
			cnt++
		}
		cnt /= 2
		for j := 0; j < cnt; j++ {
			m *= p[i]
		}
	}

	if k > 1 {
		ret *= k
		m *= k
	}

	return ret, m
}

func find(a int64, k int64) (int64, int64) {
	_, m := multiple(k)
	b := m * (k + 1)
	x := m*m/k*(k+1)*(k+1) - a/k
	return x, b
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	n := 100002
	prime := make([]bool, n+1)
	for i := 0; i <= n; i++ {
		prime[i] = true
	}
	prime[0] = false
	prime[1] = false
	for i := 2; i*i <= n; i++ {
		if prime[i] {
			for j := i * i; j <= n; j += i {
				prime[j] = false
			}
		}
	}

	for i := 2; i < n; i++ {
		if prime[i] {
			p = append(p, int64(i))
		}
	}
	np = len(p)

	res := make([]int64, n+1)
	var k, a, x int64

	a = 2
	for k = 1; k <= int64(n); k++ {
		x, a = find(a, k)
		res[k] = x
	}

	fmt.Fscanf(bufin, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, "%d\n", res[i])
	}
}

package main

import "fmt"

func main() {
    var n, m, y, k int64
    fmt.Scan(&n)
    m = 2
    for k = 1; k <= n; k++ {
        y = (k+1)*(k+1)*k - m
        m = k
        fmt.Println(y)
    }
}

package main

import "fmt"
import "bufio"
import "os"

var bufin *bufio.Reader
var bufout *bufio.Writer

var p []int64
var np int

func sqr(x int64) int64 {
	return x * x
}

func multiple(k int64) (int64, int64) {
	ret := int64(1)
	m := int64(1)

	for i := 0; i < np && sqr(p[i]) <= k; i++ {
		cnt := 0
		for k%p[i] == 0 {
			cnt++
			k /= p[i]
		}
		if (cnt > 0) && (cnt%2 == 1) {
			ret *= p[i]
			cnt++
		}
		cnt /= 2
		for j := 0; j < cnt; j++ {
			m *= p[i]
		}
	}

	if k > 1 {
		ret *= k
		m *= k
	}

	return ret, m
}

func find(a int64, k int64) (int64, int64) {
	_, m := multiple(k)
	b := m * (k + 1)
	x := b/k*b - a/k
	return x, b
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	n := 100002
	prime := make([]bool, n+1)
	for i := 0; i <= n; i++ {
		prime[i] = true
	}
	prime[0] = false
	prime[1] = false
	for i := 2; i*i <= n; i++ {
		if prime[i] {
			for j := i * i; j <= n; j += i {
				prime[j] = false
			}
		}
	}

	for i := 2; i < n; i++ {
		if prime[i] {
			p = append(p, int64(i))
		}
	}
	np = len(p)

	res := make([]int64, n+1)
	var k, a, x int64

	a = 2
	for k = 1; k <= int64(n); k++ {
		x, a = find(a, k)
		res[k] = x
	}

	fmt.Fscanf(bufin, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fprintf(bufout, "%d\n", res[i])
	}
}


package main

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

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

	arr := make([]int, n)
	for i := range arr {
		Fscan(in, &arr[i])
	}
	ans := 0
	for i := 0; i < n; i++ {
		sum, cnt := 0, 1
		for j := i; j < n; j++ {
			sum += arr[j]
			if sum > 100*cnt {
				if cnt > ans {
					ans = cnt
				}
			}
			cnt++
		}
	}
	Print(ans)
}

// Brute force. Too slow
package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func read_int_array(array_length int) []int {
    input_array := make([]int, array_length)
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
    return input_array
}

func main() {
    var n int
    fmt.Fscanln(reader, &n)

    input_array := read_int_array(n)
    res := 0
    for i:=0; i < n; i++ {
        sum := 0
        num_elems := 1
        for j := i; j < n; j++ {
            sum += input_array[j]
            if sum > 100 * num_elems {
                if num_elems > res {
                    res = num_elems
                }
            }
            num_elems++
        }
    }
    fmt.Println(res)
}


package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

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

func sol(n int, a []int) int {
	g := a[0]
	for i := range a {
		g = gcd(g, a[i])
	}
	if g == 1 {
		return 0
	}
	ret := 3
	for i := range a {
		// printf("g=%d\n", g)
		if gcd(g, i+1) == 1 {
			// printf("%d\n", i+1)
			ret = min(ret, n-(i+1)+1)
		}
	}
	return ret
}

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

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	if a < 0 {
		a *= -1
	}
	return a
}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			if i == 0 { cgcd = a[i] }
			fmt.Fscan(r, &a[i])
			cgcd = gcd(cgcd, a[i])
		}

		sa_cost := int(1e14)
		for i, v := range a {
			if gcd(cgcd, gcd(v, i+1)) == 1 {
				sa_cost = min(sa_cost, n-i)
			}
		}

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd && a[i] != i+1 {
				cost += n-i
				a[i] = gcd(i+1, a[i])
				cgcd = gcd(cgcd, gcd(a[i], i+1))
			}
		}
		fmt.Fprintln(w, min(sa_cost, cost))
	}

}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		iost.Writer.Flush()
	}()
	solve()
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}
func testcase() {
	n := iost.GetNextInt()
	aa := make([]int, n)
	g := 0
	for i := 0; i < n; i++ {
		aa[i] = iost.GetNextInt()
		g = gcd(g, aa[i])
	}
	if g == 1 {
		iost.Println(0)
		return
	}
	ans := 3
	for i := 0; i < n; i++ {
		g = 0
		for j := 0; j < n; j++ {
			if i == j {
				g = gcd(g, gcd(aa[j], j+1))
				continue
			}
			g = gcd(g, aa[j])
		}
		if g == 1 {
			ans = min(ans, n-i)
		}
	}
	iost.Println(ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

func gcd(m, n int) int {
	if n == 0 {
		return m
	}
	return gcd(n, m%n)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer func(w *bufio.Writer) {
		err := w.Flush()
		if err != nil {
			log.Fatal(err)
		}
	}(w)

	var n, t, g, g1 int
	_, err := fmt.Fscan(r, &t)
	if err != nil {
		return
	}
	for i := 1; i <= t; i++ {

		_, err = fmt.Fscan(r, &n)
		if err != nil {
			return
		}

		x := make([]int, n+1)
		for j := 1; j <= n; j++ {
			_, err = fmt.Fscan(r, &x[j])
			if err != nil {
				return
			}
		}
		g = 0
		for j := 1; j <= n; j++ {
			g = gcd(x[j], g)
		}

		if g == 1 {
			_, err = fmt.Fprintln(w, "0")
			if err != nil {
				return
			}
			continue
		}

		if n == 1 {
			_, err = fmt.Fprintln(w, "1")
			if err != nil {
				return
			}
			continue
		}
		g1 = gcd(x[n], n)
		if gcd(g1, g) == 1 {
			_, err = fmt.Fprintln(w, 1)
			if err != nil {
				return
			}
			continue
		}
		g1 = gcd(x[n-1], n-1)
		if gcd(g1, g) == 1 {
			_, err = fmt.Fprintln(w, 2)
			if err != nil {
				return
			}
			continue
		}

		_, err = fmt.Fprintln(w, "3")
		if err != nil {
			return
		}

	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt64(reader)

		var g = a[0]
		for i := 1; i < n; i++ {
			g = gcd(a[i], g)
		}

		if g == 1 {
			fmt.Fprintln(writer, 0)
		} else {
			var (
				gi  int64
				sum int
				gg  = g
			)
			for i := n - 1; i >= 0; i-- {
				gi = gcd(a[i], int64(i+1))
				if gcd(gg, gi) == 1 {
					sum = n - i
					break
				} else {
					sum += n - i
					g = gcd(g, gi)
					if g == 1 {
						break
					}
				}
			}
			fmt.Fprintln(writer, sum)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}

package main

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

const cf = true

type pair struct {
	begin int
	end   int
}

type val struct {
	ind      int
	val      int
	haveZero bool
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	gcd := -1
	for i := range arr {
		fmt.Fscan(in, &arr[i])
		if gcd == -1 {
			gcd = arr[i]
		} else {
			gcd = GCD(gcd, arr[i])
		}
	}
	if gcd == 1 {
		fmt.Fprintln(out, 0)
		return
	}
	for i := n; i >= max(1, n-1); i-- {
		if GCD(gcd, i) == 1 {
			fmt.Fprintln(out, n-i+1)
			return
		}
	}
	fmt.Fprintln(out, 3)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	f := func(a []int) int {
		g := 0
		for _, v := range a {
			g = gcd(g, v)
		}
		return g
	}

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		if f(a) == 1 {
			Fprintln(out, 0)
			return
		}
		ans := int(1e9)
		for i := 1; i <= n; i++ {
			b := append([]int{}, a...)
			b[i] = gcd(b[i], i)
			if f(b) == 1 {
				ans = min(ans, n-i+1)
			}
		}
		for i := 1; i < n; i++ {
			b := append([]int{}, a...)
			b[i] = gcd(b[i], i)
			b[i+1] = gcd(b[i+1], i+1)
			if f(b) == 1 {
				ans = min(ans, n-i+1 + n-(i+1)+1)
			}
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

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

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

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

func gcd_arr(a []int) int {
	var cgcd int
	for i, v := range a {
		if i == 0 { cgcd = v }
		cgcd = gcd(cgcd, v)
	}
	return cgcd
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
		}
		cgcd = gcd_arr(a)

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd && a[i] != i+1 {
				cost += n-i
				a[i] = gcd(i+1, a[i])
				cgcd = gcd_arr(a)
			}
		}
		fmt.Fprintln(w, cost)
	}

}

package main

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

func gcd(a, b int) int {
	if b == 0 { return a }
	return gcd(b, a%b)
}

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, cgcd, cost int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			if i == 0 { cgcd = a[i] }
			fmt.Fscan(r, &a[i])
			cgcd = gcd(cgcd, a[i])
		}

		for i := n-1; i >= 0 && cgcd != 1; i-- {
			if gcd(i+1, a[i]) != cgcd {
				cost += n-i
				cgcd = gcd(cgcd, gcd(i+1, a[i]))
			}
		}
		fmt.Fprintln(w, cost)
	}

}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt64(reader)

		var g = a[0]
		for i := 1; i < n; i++ {
			g = gcd(a[i], g)
		}

		if g == 1 {
			fmt.Fprintln(writer, 0)
		} else {
			var (
				gi  int64
				sum int
			)
			for i := n - 1; i >= 0; i-- {
				gi = gcd(a[i], int64(i+1))
				if g == gi {
					continue
				}

				sum += n - i
				g = gcd(g, gi)
				if g == 1 {
					break
				}
			}
			fmt.Fprintln(writer, sum)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

func gcd(x, y int64) int64 {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x * y / gcd(x, y)
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}
func solve() {
	arr := []int{}
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	var ans int64
	for _, v := range arr {
		if v == 1 {
			ans++
		}
	}
	for _, v := range arr {
		if v == 0 {
			ans = ans * 2
		}
	}
	fmt.Println(ans)
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var z, o int64
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 0 {
				z++
			} else if v == 1 {
				o++
			}
		}

		if z > 0 && o > 0 {
			fmt.Fprintln(out, 2<<(z-1)*o)
		} else {
			fmt.Fprintln(out, o)
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int64) int64 {
	var (
		sum, p int64
		q      int
	)
	for _, x := range a {
		sum += x
		if x == 1 {
			p++
		}
		if x == 0 {
			q++
		}
	}
	return p << q
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

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

/*
14
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
1
1
2
1 1
3
1 1 1
4
3 2 1 1
3
1 0 0
3
2 1 1
4
2 1 1 1
5
2 1 1 1 0
6
2 1 1 1 0 0
---
1
0
2
4
4
1
2
3
2
4
2
3
6
12
======
1
60
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

---

*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

		zeroCnt := 0
		oneCnt := 0

		for i := 0; i < n; i++ {
			var a int
			scanf("%d", &a)

			if a == 0 {
				zeroCnt++
			}

			if a == 1 {
				oneCnt++
			}
		}
		scanf("\n")

		var ans uint64

		if oneCnt > 0 {
			ans = uint64(oneCnt)
			if zeroCnt > 0 {
				ans = uint64(oneCnt) * uint64(math.Pow(2, float64(zeroCnt)))
			}
		}

		fmt.Fprintf(&bld, "%d\n", ans)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst, snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int64 {
	var s int
	for i := 0; i < n; i++ {
		s += a[i]
	}

	var c int64
	var z int

	for i := 0; i < n; i++ {
		if a[i] == 1 {
			c++
		}
		if a[i] == 0 {
			z++
		}
	}

	return c * int64(1 << uint(z))
}

// https://codeforces.com/problemset/problem/1582/B

// 1582B - Luntik and Subsequences

// Luntik came out for a morning stroll and found an array a of length n. He calculated the sum s of the elements of the array (s=∑ni=1ai). Luntik calls a subsequence of the array a nearly full if the sum of the numbers in that subsequence is equal to s−1.
// Luntik really wants to know the number of nearly full subsequences of the array a. But he needs to come home so he asks you to solve that problem!
// A sequence x is a subsequence of a sequence y if x can be obtained from y by deletion of several (possibly, zero or all) elements.

// Input
// The first line contains a single integer t (1≤t≤1000) — the number of test cases. The next 2⋅t lines contain descriptions of test cases. The description of each test case consists of two lines.
// The first line of each test case contains a single integer n (1≤n≤60) — the length of the array.
// The second line contains n integers a1,a2,…,an (0≤ai≤109) — the elements of the array a.

// Output
// For each test case print the number of nearly full subsequences of the array.

// Example
// input
// 5
// 5
// 1 2 3 4 5
// 2
// 1000 1000
// 2
// 1 0
// 5
// 3 0 2 1 1
// 5
// 2 1 0 3 0
// output
// 1
// 0
// 2
// 4
// 4

// Note

// In the first test case, s=1+2+3+4+5=15, only (2,3,4,5) is a nearly full subsequence among all subsequences, the sum in it is equal to 2+3+4+5=14=15−1.
// In the second test case, there are no nearly full subsequences.
// In the third test case, s=1+0=1, the nearly full subsequences are (0) and () (the sum of an empty subsequence is 0).

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c int
	var t, n, a uint
	var cnt_0, cnt_1 uint64

	for c, _ = fmt.Fscan(reader, &t); c == 1; c, _ = fmt.Fscan(reader, &t) {
		for ; t > 0; t-- {
			cnt_0, cnt_1 = 0, 0

			for fmt.Fscan(reader, &n); n > 0; n-- {
				fmt.Fscan(reader, &a)

				if a == 0 {
					cnt_0++
				} else if a == 1 {
					cnt_1++
				}
			}

			fmt.Fprintln(writer, (1<<cnt_0)*cnt_1)
		}
	}

	writer.Flush()
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, curr int
		fmt.Fscan(reader, &n)
		zeros := 0
		ones := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			if curr == 0 {
				zeros++
			}
			if curr == 1 {
				ones++
			}
		}
		ans := int64(ones)
		for zeros > 0 {
			ans = ans * 2
			zeros--
		}
		fmt.Println(ans)

	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		ARR := make([]int, n)
		var zero int64 = 1
		ones := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARR[i])
			if ARR[i] == 0 {
				zero = zero * 2
			}
			if ARR[i] == 1 {
				ones++
			}
		}
		q := int64(ones) * zero
		fmt.Println(q)

	}

}

package main

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

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

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(0), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}
		fmt.Fprintln(w, (1<<a)*b)
	}
}

package main

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

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

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(1), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a *= 2
			} else if val == 1 {
				b++
			}
		}

		fmt.Fprintln(w, a*b)

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for j:=0; j<t; j++{
		var n, k, s int64
		fmt.Scan(&n)
		for i := 0; i < int(n); i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = 1 << s
			k = s * k
		}

		fmt.Println(k)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int64
		fmt.Scan(&n)
		for i := 0; i < int(n); i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = 1 << s
			k = s * k
		}

		fmt.Println(k)
	}
}

package main

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

func Pow(x, n int) int64 {
	return int64(math.Pow(float64(x), float64(n)))
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, Pow(2, z)*int64(o))
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		ans := int64(cnt1)*int64(math.Pow(2, float64(cnt0)))
		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

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

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := int64(0), int64(0)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}
		fmt.Fprintln(w, a*b)
	}
}

package main

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

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

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := 1, 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a *= 2
			} else if val == 1 {
				b++
			}
		}

		if b == 0 {
			fmt.Fprintln(w, 0)
		} else {
			fmt.Fprintln(w, a*b)
		}

	}
}

package main

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

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

func CF1582B(in io.Reader, out io.Writer) {
	r := bufio.NewReader(in)
	w := bufio.NewWriter(out)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, val int64
		fmt.Fscan(r, &n)
		a, b := 0, 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(r, &val)
			if val == 0 {
				a++
			} else if val == 1 {
				b++
			}
		}

		if b == 0 {
			fmt.Fprintln(w, 0)
		} else {
			fmt.Fprintln(w, a*b*b)
		}

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			s = (1 + s) * s / 2
			k += s * k
		}

		fmt.Println(k)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n, k, s int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			var x int64
			fmt.Scan(&x)
			if x == 1 {
				k++
			}

			if x == 0 {
				s++
			}

		}

		if s > 0 {
			k += s * k
		}

		fmt.Println(k)
	}
}

package main

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

func Pow(x, n int) int {
	return int(math.Pow(float64(x), float64(n)))
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, Pow(2, z)*o)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		z, o := 0, 0
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			if p == 1 {
				o++
			}
			if p == 0 {
				z++
			}
		}
		if z == 0 {
			fmt.Fprintln(w, o)
		} else {
			fmt.Fprintln(w, 2*z*o)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		ans := cnt1*(1 + (1+cnt0)*cnt0/2)
		fmt.Fprintln(writer, ans)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		readInt(reader)
		a := readArrayInt64(reader)

		cnt0 := 0
		cnt1 := 0
		for _, v := range a {
			if v == 0 {
				cnt0++
			} else if v == 1 {
				cnt1++
			}
		}

		if cnt0 == 0 && cnt1 > 0 {
			fmt.Fprintln(writer, cnt1)
		} else {
			fmt.Fprintln(writer, 2*cnt1*cnt0)
		}

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		var z, o int64
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v == 0 {
				z++
			} else if v == 1 {
				o++
			}
		}

		if z > 0 && o > 0 {
			fmt.Fprintln(out, 2<<(z-1)*o)
		} else if z > 0 {
			fmt.Fprintln(out, 2<<(z-1))
		} else {
			fmt.Fprintln(out, o)
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(n int, a []int64) int64 {
	var (
		sum, p int64
		q      int
	)
	for _, x := range a {
		sum += x
		if x == 1 {
			p++
		}
		if x == 0 {
			q++
		}
	}
	if sum == 1 {
		return p<<q + 1
	}
	return p << q
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

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

/*
14
5
1 2 3 4 5
2
1000 1000
2
1 0
5
3 0 2 1 1
5
2 1 0 3 0
1
1
2
1 1
3
1 1 1
4
3 2 1 1
3
1 0 0
3
2 1 1
4
2 1 1 1
5
2 1 1 1 0
6
2 1 1 1 0 0
---
1
0
2
4
4
1
2
3
2
4
2
3
6
12
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var n int
		scanf("%d\n", &n)

		zeroCnt := 0
		oneCnt := 0

		for i := 0; i < n; i++ {
			var a int
			scanf("%d", &a)

			if a == 0 {
				zeroCnt++
			}

			if a == 1 {
				oneCnt++
			}
		}
		scanf("\n")

		ans := 0

		if oneCnt > 0 {
			ans = oneCnt
			if zeroCnt > 0 {
				ans = oneCnt * int(math.Pow(2, float64(zeroCnt)))
			}
		}

		fmt.Fprintf(&bld, "%d\n", ans)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst, snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

var n int

var a []int

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		ans := solve()

		fmt.Println(ans)
	}
}

func solve() int {
	var s int
	for i := 0; i < n; i++ {
		s += a[i]
	}

	var c int
	var z int

	for i := 0; i < n; i++ {
		if a[i] == 1 {
			c++
		}
		if a[i] == 0 {
			z++
		}
	}

	return c * (1 << uint(z))
}