package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

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

func dis(p1, p2 *Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt() + 1
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt() + 1
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			D[id] = Node{
				aa: dis(&a[l], &a[l+1]),
				ab: dis(&a[l], &b[l+1]),
				ba: dis(&b[l], &a[l+1]),
				bb: dis(&b[l], &b[l+1]),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(&p1, &p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		da = dis(&p1, &a[l1])
		db = dis(&p1, &b[l1])
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(&p2, &a[l2-1]),
			db+dis(&p2, &b[l2-1]),
		)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

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

func dis(p1, p2 Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt() + 1
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt() + 1
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			a1, a2, b1, b2 := a[l], a[l+1], b[l], b[l+1]
			D[id] = Node{
				aa: dis(a1, a2),
				ab: dis(a1, b2),
				ba: dis(b1, a2),
				bb: dis(b1, b2),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(p1, p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		da = dis(p1, Point{a[l1].x, a[l1].y})
		db = dis(p1, Point{b[l1].x, b[l1].y})
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(p2, Point{a[l2-1].x, a[l2-1].y}),
			db+dis(p2, Point{b[l2-1].x, b[l2-1].y}),
		)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

const eof = 0
const inf int64 = 1 << 62

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	return x
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

type Node struct {
	aa, ab, ba, bb int64
}

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

func Concat(a, b *Node) (c Node) {
	c.aa = min(a.aa+b.aa, a.ab+b.ba)
	c.ab = min(a.aa+b.ab, a.ab+b.bb)
	c.ba = min(a.ba+b.aa, a.bb+b.ba)
	c.bb = min(a.ba+b.ab, a.bb+b.bb)
	return
}

type Point struct {
	x, y int
}

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

func (p *Point) level() int {
	return max(p.x, p.y)
}

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

func dis(p1, p2 Point) int64 {
	return (int64)(abs(p1.x-p2.x) + abs(p1.y-p2.y))
}

func sol() {
	n := myio.ReadInt()
	a := make([]Point, n)
	b := make([]Point, n)
	for i := 1; i < n; i++ {
		a[i].x = myio.ReadInt()
		a[i].y = myio.ReadInt()
		b[i].x = myio.ReadInt()
		b[i].y = myio.ReadInt()
	}

	// init tree
	L := make([]int, n*4)
	R := make([]int, n*4)
	D := make([]Node, n*4)

	var buildTree func(int, int, int)

	buildTree = func(id, l, r int) {
		if l >= r {
			return
		}
		L[id], R[id] = l, r
		if l+1 == r {
			a1, a2, b1, b2 := a[l], a[l+1], b[l], b[l+1]
			a1.x++
			a2.x++
			b1.y++
			b2.y++
			D[id] = Node{
				aa: dis(a1, a2),
				ab: dis(a1, b2),
				ba: dis(b1, a2),
				bb: dis(b1, b2),
			}
			return
		}
		m := l + (r-l+1)/2
		lc := id << 1
		rc := lc | 1
		buildTree(lc, l, m)
		buildTree(rc, m, r)
		D[id] = Concat(&D[lc], &D[rc])
	}

	buildTree(1, 1, n-1)

	var query func(int, int, int, *Node)
	query = func(id, l, r int, m *Node) {
		// fmt.Println("query", id, L[id], R[id], "->", l, r, *m)
		if l == r {
			return
		}
		if r <= L[id] || R[id] <= l {
			return
		}
		if L[id] >= l && R[id] <= r {
			*m = Concat(m, &D[id])
			return
		}
		query(id<<1, l, r, m)
		query((id<<1)|1, l, r, m)
	}

	q := myio.ReadInt()
	for ; q > 0; q-- {
		var p1, p2 Point
		p1.x = myio.ReadInt()
		p1.y = myio.ReadInt()
		p2.x = myio.ReadInt()
		p2.y = myio.ReadInt()
		l1, l2 := p1.level(), p2.level()
		if l1 == l2 {
			myio.Println(dis(p1, p2))
			continue
		}
		if l1 > l2 {
			p1, p2 = p2, p1
			l1, l2 = l2, l1
		}
		// l1->l2
		mat := Node{0, inf, inf, 0}
		query(1, l1, l2-1, &mat)
		var da, db int64
		// fmt.Println("l1=", l1, "l2=", l2, "mat=", mat, p1, p2)
		da = dis(p1, Point{a[l1].x + 1, a[l1].y})
		db = dis(p1, Point{b[l1].x, b[l1].y + 1})
		da, db = min(da+mat.aa, db+mat.ba), min(db+mat.bb, da+mat.ab)
		ans := min(
			da+dis(p2, Point{a[l2-1].x + 1, a[l2-1].y}),
			db+dis(p2, Point{b[l2-1].x, b[l2-1].y + 1}),
		)
		// myio.Println(mat)
		myio.Println(ans)
	}
}

func main() {
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	// t = myio.ReadInt()
	for ; t > 0; t-- {
		sol()
	}
}


package main

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

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 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
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := int64(1)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := int64(1)
			s2 := buf.String()
			for i := 1; i < len(s2); i++ {
				var match int
				for j := 0; j < len(s2); j++ {
					if s2[(i+j)%len(s2)] != s2[j] {
						break
					}
					match++
				}
				if match == len(s2) {
					break
				}
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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 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
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := int64(1)
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := int64(1)
			orig := buf.String()
			s2 := string(orig[1:]) + string(orig[0])
			for s2 != orig {
				s2 = string(s2[1:]) + string(s2[0])
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

var (
	p   [205]int
	vis [205]bool
	str []byte
)

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

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

func equal(a, b []byte) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func repeat(base []byte, nums int) (res []byte) {
	res = make([]byte, 0, len(base)*nums)
	for i := 1; i <= nums; i++ {
		res = append(res, base...)
	}
	return
}

func minReStr(str []byte) int {
	n := len(str)
	res := 1<<31 - 1
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			t := n / i
			if equal(repeat(str[:i], t), str) && res > i {
				res = i
			}
			if equal(repeat(str[:t], i), str) && res > t {
				res = t
			}
		}
	}
	return res
}

func search(x int) (res []byte) {
	res = append(res, str[x])
	vis[x] = true
	for i := p[x]; i != x; i = p[i] {
		res = append(res, str[i])
		vis[i] = true
	}
	return res
}

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str = rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
			vis[i] = false
		}
		res := int64(1)
		for i := 1; i <= n; i++ {
			if !vis[i] {
				res = lcm(res, int64(minReStr(search(i))))
			}
		}
		Fprintln(out, res)
	}
}

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

package main

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

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

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

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
		var s string
		fmt.Fscan(in, &n, &s)

		arr := make([]int, n)
		m := make([]int, n+1)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			m[arr[i]] = i
		}

		ans := 1
		vis := make([]bool, n)
		for i := 0; i < n; i++ {
			if vis[i] {
				continue
			}
			var buf bytes.Buffer
			z := arr[i]
			buf.WriteByte(s[z-1])
			vis[i] = true
			for z != i+1 {
				z = arr[z-1]
				buf.WriteByte(s[z-1])
				vis[m[z]] = true
			}
			c := 1
			orig := buf.String()
			s2 := string(orig[1:]) + string(orig[0])
			for s2 != orig {
				s2 = string(s2[1:]) + string(s2[0])
				c++
			}
			ans = lcm(ans, c)
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

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

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

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
		var s string
		fmt.Fscan(in, &n, &s)

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

		s2 := s
		b := make([]byte, n)
		g := make([]int, n)
		var c int
		x := 1
		for c < n {
			for i, v := range arr {
				b[i] = s2[v-1]
				if g[i] == 0 && b[i] == s[i] {
					c++
					g[i] = x
				}
			}
			s2 = string(b)
			x++
		}

		ans := 1
		for _, v := range g {
			ans = lcm(ans, v)
		}
		fmt.Println(ans)
	}
}

package main

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

var (
	p   [205]int
	vis [205]bool
	str []byte
)

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

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

func equal(a, b []byte) bool {
	for i := range a {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

func repeat(base []byte, nums int) (res []byte) {
	res = make([]byte, 0, len(base)*nums)
	for i := 1; i <= nums; i++ {
		res = append(res, base...)
	}
	return
}

func minReStr(str []byte) int {
	n := len(str)
	res := 1<<31 - 1
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			t := n / i
			if equal(repeat(str[:i], t), str) && res > i {
				res = i
			}
			if equal(repeat(str[:t], i), str) && res > t {
				res = t
			}
		}
	}
	return res
}

func search(x int) (res []byte) {
	res = append(res, str[x])
	vis[x] = true
	for i := p[x]; i != x; i = p[i] {
		res = append(res, str[i])
		vis[i] = true
	}
	return res
}

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str = rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
		}
		res := int64(1)
		for i := 1; i <= n; i++ {
			if !vis[i] {
				res = lcm(res, int64(minReStr(search(i))))
			}
		}
		Fprintln(out, res)
	}
}

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

package main

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

var (
	p [205]int
)

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

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

func run(_r io.Reader, _w io.Writer) {
	const eof = 0
	out := bufio.NewWriter(_w)
	defer out.Flush()
	_i, _n, buf := 0, 0, make([]byte, 1<<12)
	rc := func() byte {
		if _i == _n {
			_n, _ = _r.Read(buf)
			if _n == 0 {
				return eof
			}
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	rs := func(n int) []byte {
		b := rc()
		for ; b == '\n' || b == '\r'; b = rc() {
			if b == eof {
				return nil
			}
		}
		res := make([]byte, n+1)
		for i := 1; i <= n; i++ {
			res[i] = b
			b = rc()
		}
		return res
	}
	read := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
			if b == eof {
				return
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	for t := read(); t > 0; t-- {
		n := read()
		str := rs(n)
		for i := 1; i <= n; i++ {
			p[i] = read()
		}
		tmp := p[1]
		cnt := int64(1)
		for str[tmp] != str[1] {
			tmp = p[tmp]
			cnt++
		}
		res := cnt
		for i := 2; i <= n; i++ {
			tmp := p[i]
			cnt := int64(1)
			for str[tmp] != str[i] {
				tmp = p[tmp]
				cnt++
			}
			res = lcm(res, cnt)
		}
		Fprintln(out, res)
	}
}

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


package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	nmStrArr := strings.Split(scanner.Text(), " ")
	n, _ := strconv.Atoi(nmStrArr[0])
	m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	leftCoordIdx := make([][]int, n+1)
	rightCoordIdx := make([][]int, n+1)
	leftCnt := make([]int, n+1)
	rightCnt := make([]int, n+1)
	topCoordIdx := make([][]int, m+1)
	botCoordIdx := make([][]int, m+1)
	topCnt := make([]int, m+1)
	botCnt := make([]int, m+1)
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		leftCoordIdx[leftX] = append(leftCoordIdx[leftX], i)
		leftCnt[leftX] += 1
		rightCnt[rightX] += 1
		rightCoordIdx[rightX] = append(rightCoordIdx[rightX], i)
		topCoordIdx[topY] = append(topCoordIdx[topY], i)
		botCoordIdx[bottomY] = append(botCoordIdx[bottomY], i)
		topCnt[topY] += 1
		botCnt[bottomY] += 1
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	respIdx := map[int][]bool{}

	leftFound := false
	for i := 1; i <= n; i++ {
		leftCnt[i] += leftCnt[i-1]
		if leftCnt[i] > l {
			if leftCnt[i-1] == l {
				for _, j := range leftCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						leftFound = true
					}
				}
			}
			if leftCnt[i] == l+1 {
				for _, j := range leftCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						leftFound = true
					}
				}
			}
			break
		}
	}
	if !leftFound {
		fmt.Println(-1)
		return
	}
	//fmt.Println(respIdx)

	rightFound := false
	for i := n; i > 0; i-- {
		if i < n {
			rightCnt[i] += rightCnt[i+1]
		}
		if rightCnt[i] > r {
			if i == n || (i < n && rightCnt[i+1] == r) {
				for _, j := range rightCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						rightFound = true
					}
				}
			}
			if rightCnt[i] == r+1 {
				for _, j := range rightCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						rightFound = true
					}
				}
			}
			break
		}
	}
	if !rightFound {
		fmt.Println(-1)
		return
	}

	topFound := false
	for i := 1; i <= m; i++ {
		topCnt[i] += topCnt[i-1]
		if topCnt[i] > t {
			//fmt.Printf("i: %v, topCnt[i]: %v, topCnt[i-1]: %v, t: %v, topCoordIdx: %v\n", i, topCnt[i], topCnt[i-1], t, topCoordIdx)
			if topCnt[i-1] == t {
				for _, j := range topCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						topFound = true
					}
				}
			}
			if topCnt[i] == t+1 {
				for _, j := range topCoordIdx[i] {
					if sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						topFound = true
					}
				}
			}
			break
		}
	}
	if !topFound {
		fmt.Println(-1)
		return
	}

	botFound := false
	for i := m; i > 0; i-- {
		if i < m {
			botCnt[i] += botCnt[i+1]
		}
		if botCnt[i] > b {
			if i == m || (i < m && botCnt[i+1] == b) {
				for _, j := range botCoordIdx[i] {
					if !sofaCoords[j].standing {
						respIdx[j] = append(respIdx[j], true)
						botFound = true
					}
				}
			}
		}
		if botCnt[i] == b+1 {
			for _, j := range botCoordIdx[i] {
				if sofaCoords[j].standing {
					respIdx[j] = append(respIdx[j], true)
					botFound = true
				}
			}
		}
	}
	if !botFound {
		fmt.Println(-1)
		return
	}

	for idx := range respIdx {
		if len(respIdx[idx]) == 4 {
			fmt.Println(idx+1)
			return
		}
	}

	fmt.Println(-1)
	return

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX || (sortedCoords[i].leftX == sortedCoords[j].leftX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				if !sortedCoords[l].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}

	// sort by right
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].rightX > sortedCoords[j].rightX || (sortedCoords[i].rightX == sortedCoords[j].rightX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[r].idx][1] = true
	for i := r+1; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				if !sortedCoords[r].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}
	for i := r-1; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY || (sortedCoords[i].topY == sortedCoords[j].topY && sortedCoords[j].standing)
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				if sortedCoords[t].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}

	// sort by bottom
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].bottomY > sortedCoords[j].bottomY || (sortedCoords[i].bottomY == sortedCoords[j].bottomY && sortedCoords[j].standing)
	})
	respMap[sortedCoords[b].idx][3] = true
	for i := b+1; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				if sortedCoords[b].standing {
					fmt.Println(-1)
					return
				}
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}
	for i := b-1; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if !sortedCoords[i].standing && !sortedCoords[l].standing && sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}

	// sort by right
	respMap[sortedCoords[d-r-1].idx][1] = true
	for i := d-r; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}
	for i := d-r-2; i >= 0; i-- {
		if !sortedCoords[i].standing && !sortedCoords[d-r-1].standing && sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].standing && sortedCoords[t].standing && sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}

	// sort by bottom
	respMap[sortedCoords[d-b-1].idx][3] = true
	for i := d-b; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}
	for i := d-b-2; i >= 0; i-- {
		if sortedCoords[i].standing && sortedCoords[d-b-1].standing && sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY,i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			respMap[sortedCoords[i].idx][0] = true
		} else {
			break
		}
	}

	// sort by right
	respMap[sortedCoords[d-r-1].idx][1] = true
	for i := d-r; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}
	for i := d-r-2; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[d-r-1].rightX {
			respMap[sortedCoords[i].idx][1] = true
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			respMap[sortedCoords[i].idx][2] = true
		} else {
			break
		}
	}

	// sort by bottom
	respMap[sortedCoords[d-b-1].idx][3] = true
	for i := d-b; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}
	for i := d-b-2; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[d-b-1].bottomY {
			respMap[sortedCoords[i].idx][3] = true
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}

package main

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

type SofaCoord struct {
	leftX int
	topY int
	rightX int
	bottomY int
	standing bool
	idx int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer([]byte{}, int(math.Pow(10,8)))
	scanner.Scan()

	d, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	scanner.Text()
	//nmStrArr := strings.Split(scanner.Text(), " ")
	//n, _ := strconv.Atoi(nmStrArr[0])
	//m, _ := strconv.Atoi(nmStrArr[1])

	sofaCoords := []SofaCoord{}
	sortedCoords := []SofaCoord{}
	for i := 0; i < d; i++ {
		scanner.Scan()
		coordStrArr := strings.Split(scanner.Text(), " ")
		x1, _ := strconv.Atoi(coordStrArr[0])
		y1, _ := strconv.Atoi(coordStrArr[1])
		x2, _ := strconv.Atoi(coordStrArr[2])
		y2, _ := strconv.Atoi(coordStrArr[3])
		leftX := x1; rightX := x2;
		if x2 < x1 || (x1 == x2 && y1 > y2){
			leftX = x2; rightX = x1
		}
		topY := y1; bottomY := y2;
		if y2 < y1 || (y1 == y2 && x2 < x1) {
			topY = y2; bottomY = y1;
		}
		standing := leftX == rightX
		sofaCoords = append(sofaCoords, SofaCoord{leftX,topY,rightX,bottomY, standing, i})
		sortedCoords = append(sortedCoords, SofaCoord{leftX,topY,rightX,bottomY,standing, i})
	}

	scanner.Scan()
	cntStrArr := strings.Split(scanner.Text(), " ")
	l, _ := strconv.Atoi(cntStrArr[0])
	r, _ := strconv.Atoi(cntStrArr[1])
	t, _ := strconv.Atoi(cntStrArr[2])
	b, _ := strconv.Atoi(cntStrArr[3])

	// sort by left
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].leftX < sortedCoords[j].leftX || (sortedCoords[i].leftX == sortedCoords[j].leftX && !sortedCoords[j].standing)
	})

	respMap := make(map[int][]bool, d)
	for i := 0; i < d; i++ {
		respMap[i] = make([]bool, 4)
		for j := 0; j < 4; j++ {
			respMap[i][j] = false
		}
	}

	respMap[sortedCoords[l].idx][0] = true
	for i := l+1; i < d; i++ {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}
	for i := l-1; i >= 0; i-- {
		if sortedCoords[i].leftX == sortedCoords[l].leftX {
			if sortedCoords[i].standing == sortedCoords[l].standing {
				respMap[sortedCoords[i].idx][0] = true
			}
		} else {
			break
		}
	}

	// sort by right
	sort.Slice(sortedCoords, func (i, j int) bool {
		return sortedCoords[i].rightX > sortedCoords[j].rightX || (sortedCoords[i].rightX == sortedCoords[j].rightX && !sortedCoords[j].standing)
	})

	respMap[sortedCoords[r].idx][1] = true
	for i := r+1; i < d; i++ {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}
	for i := r-1; i >= 0; i-- {
		if sortedCoords[i].rightX == sortedCoords[r].rightX {
			if sortedCoords[i].standing == sortedCoords[r].standing {
				respMap[sortedCoords[i].idx][1] = true
			}
		} else {
			break
		}
	}

	//sort by top
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].topY < sortedCoords[j].topY || (sortedCoords[i].topY == sortedCoords[j].topY && sortedCoords[j].standing)
	})

	respMap[sortedCoords[t].idx][2] = true
	for i := t+1; i < d; i++ {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}
	for i := t-1; i >= 0; i-- {
		if sortedCoords[i].topY == sortedCoords[t].topY {
			if sortedCoords[i].standing == sortedCoords[t].standing {
				respMap[sortedCoords[i].idx][2] = true
			}
		} else {
			break
		}
	}

	// sort by bottom
	sort.Slice(sortedCoords, func(i, j int) bool {
		return sortedCoords[i].bottomY > sortedCoords[j].bottomY || (sortedCoords[i].bottomY == sortedCoords[j].bottomY && sortedCoords[j].standing)
	})
	respMap[sortedCoords[b].idx][3] = true
	for i := b+1; i < d; i++ {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}
	for i := b-1; i >= 0; i-- {
		if sortedCoords[i].bottomY == sortedCoords[b].bottomY {
			if sortedCoords[i].standing == sortedCoords[b].standing {
				respMap[sortedCoords[i].idx][3] = true
			}
		} else {
			break
		}
	}

	found := false
	for i := 0; i < d; i++ {
		if respMap[i][0] && respMap[i][1] && respMap[i][2] && respMap[i][3] {
			fmt.Println(i+1)
			found = true
			break
		}
	}
	if !found {
		fmt.Println(-1)
	}

}


package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: top + 1]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	stack[top] = 0
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

// Codeforces 117C XXX too slow, wrong approach
package main

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

// BitSet structure for efficiently saving array of nits
type BitSet struct {
    a []uint64
}

func (b *BitSet) setBit(i int) {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bb = bb | (1<<o)
    b.a[idx] = bb
}

func (b *BitSet) clearBit(i int) {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bb = bb & (^(1<<o))
    b.a[idx] = bb
}

func (b *BitSet) isSet(i int) bool {
    idx := i/64
    o := uint(i % 64)
    bb := b.a[idx]
    bSet := (bb & (1<<o)) != 0
    return bSet
}
func (b *BitSet) newBitSet(i int) {
    ln := i/64+1
    b.a = make([]uint64, ln)
}

var aa []BitSet
var u BitSet
// touched points
var tou BitSet
var curc []int
var n int

func findCycle(i int, lev int) int {
	//fmt.Println("findCycle, i,lev=",i,lev)
    curc[lev] = i
    u.setBit(i)
    tou.setBit(i)
    for j:=0; j<n; j++ {
        if aa[i].isSet(j) {
            if u.isSet(j) {
                curc[lev+1] = j
                curc[lev+2] = -1
	            //fmt.Println("foundCycle, j,lev=",j,lev)
                return (lev+1)
            }
            if tou.isSet(j) {
            	continue
            }
            ret := findCycle(j, lev+1)
            if ret>=0 {
                return ret
            }
        }
    }
    u.clearBit(i)
    return -1
}

func findThree() (int, int, int) {
    // find -1 and elem before this in curc
    last := -1
    ilast := -1
    bc := -1
    for i:=0; i<n+2; i++ {
        //fmt.Println("i,curc_i=",i,curc[i])
        if curc[i]==-1 {
            last = curc[i-1]
            ilast = i-1
            break
        }
    }
    //fmt.Println("last=", last)
    if last==-1 {
        panic("nor last")
    }
    for i:=ilast-1; i>=0; i-- {
        if curc[i]==last {
            bc = i
        }
    }
    //fmt.Println("last,bc=", last, bc)
    c := curc[bc]
    for i:=bc; i<n; i++ {
        a := curc[i]
        b := curc[i+1]
        if aa[b].isSet(c) {
            return a,b,c
        }
    }
    panic("cannot find a,b,c")
}

func main() {
	// reading n
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		return
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	n, err = strconv.Atoi(ss[0])
	if err != nil {
		fmt.Println("n atoi failure", err)
		return
	}
    // reading bit set matrix a
    aa = make([]BitSet, n)
    curc = make([]int, n+2)
    u.newBitSet(n)
    tou.newBitSet(n)
	for i:=0; i<n; i++ {
        s, err = in.ReadString('\n')
        if err != nil {
            fmt.Println("read failure", err)
            return
        }
        aa[i].newBitSet(n)
 		for j:=0; j<n; j++ {
            c := s[j]
            if c=='1' {
                aa[i].setBit(j)
            }
        }
	}
	//fmt.Println("Cycles read data passed")
    // looking for cycles
    for i:=0; i<n; i++ {
        if !tou.isSet(i) {
        	//fmt.Println("look for cycles from", i)
        	if findCycle(i,0) >= 0 {
        		a,b,c := findThree()
	            fmt.Printf("%d %d %d\n", a+1,b+1,c+1)
	            return
        	}
        }
    }

	// print result
	fmt.Println("-1")
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for i := 0;i < len(loop) - 1;i ++ {
			if a[loop[i]][loop[i + 1]] != '1' {
				fmt.Printf("crashed!\n")
			}
		}
		if a[loop[len(loop) - 1]][loop[0]] != '1' {
			fmt.Printf("crashed!\n")
		}
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[1]][loop[len(loop) - 1]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[len(loop) - 1] + 1)
					break
				} else {
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}

package main

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

var a [5000]string
var n int
var visit [5000]bool
var stackPos [5000]int
var stack [5000]int
var loop []int

func dfs(x, top int) bool {
	visit[x] = true
	stackPos[x] = top
	stack[top] = x
	for i := 0;i < n;i ++ {
		if a[x][i] == '1' && visit[i] && stackPos[i] != -1 {
			// find a loop
			loop = stack[stackPos[i]: (top - stackPos[i] + 1)]
			return true
		} else if a[x][i] == '1' && !visit[i] {
			if dfs(i, top + 1) {
				return true
			}
		}
	}
	stackPos[x] = -1
	stack[top] = 0
	return false
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0;i < n;i ++ {
		fmt.Fscanf(reader, "%s\n", &a[i])
		stackPos[i] = -1
	}
	for i := 0;i < n;i ++ {
		if !visit[i] {
			if dfs(i, 0) {
				break
			}
		}
	}
	if len(loop) == 0 {
		fmt.Printf("-1")
	} else {
		for i := 0;i < len(loop) - 1;i ++ {
			if a[loop[i]][loop[i + 1]] != '1' {
				fmt.Printf("crashed A!\n")
			}
		}
		if a[loop[len(loop) - 1]][loop[0]] != '1' {
			fmt.Printf("crashed B!\n")
		}
		for {
			if len(loop) == 3 {
				fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
				break
			} else {
				if a[loop[2]][loop[0]] == '1' {
					fmt.Printf("%d %d %d", loop[0] + 1, loop[1] + 1, loop[2] + 1)
					break
				} else {
					loop[1] = loop[0]
					loop = loop[1:]
				}
			}
		}
	}
}


package main

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

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)

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

		sort.Ints(arr)

		prev := 0
		cnt := 0
		for i := 0; i < n; i++ {
			if prev != arr[i] {
				cnt++
				prev = arr[i]
			}
		}
		fmt.Fprintln(out, cnt)
	}

}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"math"
	"os"
	"runtime"
	"runtime/pprof"
	"strconv"
	"strings"
)

func Memset(array []byte, value byte) {
	for i := 0; i < len(array); i++ {
		array[i] = value
	}
}

type Bitmap struct {
	size  int64
	array []byte
}

func NewBitmap(size int64) *Bitmap {
	size = int64(math.Ceil(float64(size) / 8.0))
	return &Bitmap{array: make([]byte, size), size: size}
}

func (b *Bitmap) Get(position int64) byte {
	x := position / 8
	y := 1 << (position % 8)
	return b.array[x] & byte(y)
}

func (b *Bitmap) Set(position int64) {
	x := position / 8
	y := 1 << (position % 8)
	b.array[x] |= byte(y)
}

func (b *Bitmap) Reset() {
	b.array = []byte{}
	runtime.GC()
	b.array = make([]byte, b.size)
}

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	//maxValue := int64(math.Pow10(9))
	var n, i, j int64
	var size int64
	var counter int64
	//bitmap := NewBitmap(maxValue)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		counter = 0
		dict := map[int64]struct{}{}
		//if i > 0 {
		//	bitmap.Rejset()
		//}
		str, _ := reader.ReadString('\n')
		size, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		for j = 0; j < size; j++ {
			delim := byte(' ')
			if j == size-1 {
				delim = byte('\n')
			}
			str1, _ := reader.ReadString(delim)
			item, err := strconv.ParseInt(strings.TrimSpace(str1), 10, 64)
			if err != nil {
				fmt.Printf("err2: %v", err.Error())
				os.Exit(1)
			}
			if _, ok := dict[item]; ok == true {
				continue
			}
			dict[item] = struct{}{}
			//bitmap.Set(item - 1)
			counter++
		}
		writer.WriteString(strconv.FormatInt(counter, 10))
		writer.WriteString("\n")
	}
	writer.Flush()
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    defer writer.Flush()

    scanner.Scan()
    t, _ := strconv.Atoi(scanner.Text())

    for i := 0; i < t; i++ {
        scanner.Scan()
        n, _ := strconv.Atoi(scanner.Text())
        ar := make([]int, n, n)
        for j := range ar {
            scanner.Scan()
            ar[j], _ = strconv.Atoi(scanner.Text())
        }

        sort.Ints(ar)

        result := 0
        for i := range ar {
            if i > 0 && ar[i] > ar[i-1] {
                result++
            }
        }
        fmt.Fprintf(writer, "%d\n", result+1)
    }

}

package main

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	i, _ := strconv.ParseInt(impl.NextString(), 10, 64)
	return i
}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	s.Buffer([]byte{}, math.MaxInt32)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	i, _ := strconv.ParseInt(impl.NextString(), 10, 64)
	return i
}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
        defer close(c)
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
        defer close(c)
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	i, _ := strconv.Atoi(impl.NextString())
	return i
}

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

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

func main() {
	reader := NewWordScanner(os.Stdin)
	writer := NewWriter(os.Stdout)
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		n := reader.NextInt()
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[reader.NextInt64()] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}

package main

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

func main() {
	var t, n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		set := make(map[int]bool, 0)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a)
			set[a] = true
		}
		fmt.Println(len(set))
	}
}

package main

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

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
}

func fillNNums(bs []byte, n int, res []int) {
	x := 0
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
}

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

	for tc > 0 {
		tc--
		n := readNum(reader)

		P := readNNums(reader, n)

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

func solve(n int, P []int) int {
	sort.Ints(P)

	var cnt int
	for i := 1; i <= n; i++ {
		if i == n || P[i] > P[i-1] {
			cnt++
		}
	}

	return cnt
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)
	T := NextInt()
	a := make([]int, 100000)
	for t := 0; t < T; t++ {
		n := NextInt()
		for i := 0; i < n; i++ {
			a[i] = NextInt()
		}
		sort.Ints(a[:n])
		newLen := unique(a[:n])
		fmt.Fprintln(out, newLen)
	}

}

package main

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

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

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

		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &e);
			_, ok := m[e]
			if ok == false {
				cnt = cnt + 1
				m[e] = true
			}
		}
		fmt.Fprint(w, cnt, "\n")
	}
}

package main

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

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

func main(){

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

		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &e);
			_, ok := m[e]
			if ok == false {
				cnt = cnt + 1
				m[e] = true
			}
		}
		print(cnt, "\n")
	}
	writer.Flush()
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

package main

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

var (
	in  = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func nextInt() int64 {
	in.Scan()
	n, _ := strconv.ParseInt(in.Text(), 10, 64)
	return n
}

func main() {
	in.Split(bufio.ScanWords)
	defer out.Flush()
	for t := nextInt(); t > 0; t-- {
		n := nextInt()
		set := map[int64]struct{}{}
		for i := 0; i < int(n); i++ {
			set[nextInt()] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		line = readLine(reader)
		ans := strings.Split(string(line), " ")
		m := make(map[int64]struct{})
		for i:=0;i<len(ans);i++ {
			x,_ := strconv.ParseInt(ans[i], 10, 64)
			m[x] = struct{}{}
		}
		fmt.Println(len(m))
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

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

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

	var ts int
	fmt.Fscanf(r, "%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		fmt.Fscanf(r, "%d\n", &n)

		mp := make(map[int]bool)
		cc := 0
		for i := 0; i < n; i++ {
			var x int
			fmt.Fscanf(r, "%d", &x)
			if !mp[x] {
				cc++
				mp[x] = true
			}
		}
		fmt.Fscanf(r, "\n")

		fmt.Fprintf(w, "%d\n", cc)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		c := map[int]bool{}
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &v)
			c[v] = true
		}
		Fprintln(out, len(c))
	}
}

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

package main

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

func main() {
	var t int
	fmt.Fscan(reader, &t)
	for t > 0 {
		var n int
		fmt.Fscan(reader, &n)
		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			var a int
			fmt.Fscan(reader, &a)
			m[a] = true
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	t := nextInt()
	for t > 0 {
		n := nextInt()
		m := make(map[int]int)
		for i := 0; i < n; i++ {
			m[nextInt()]++
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	t := nextInt()
	for t > 0 {
		n := nextInt()
		m := make(map[int]bool)
		for i := 0; i < n; i++ {
			m[nextInt()] = true
		}
		print(len(m), "\n")
		t--
	}
	writer.Flush()
}

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		m := make(map[int]int)
		for j := 0; j < n; j++ {
			var inp int
			fmt.Fscan(in, &inp)
			m[inp] = inp
		}
		fmt.Println(len(m))
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt() int {
	if sc.Scan() {
		t := sc.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(sc.Err())
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

var sc *bufio.Scanner = newScanner()

func solve() {
	n := scanInt()
	x := make(map[int]int)

	for i := 0; i < n; i++ {
		a := scanInt()
		x[a]++
	}

	res := 0
	for range x {
		res++
	}
	fmt.Println(res)
}

func main() {
	t := scanInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scanf(format string, a ...interface{})  { fmt.Fscanf(in, format, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }

func main() {
	defer out.Flush()
	var t int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		set := map[int64]struct{}{}
		for i := 0; i < n; i++ {
			var ai int64
			scanf("%d ", &ai)
			set[ai] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scanf(format string, a ...interface{})  { fmt.Fscanf(in, format, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }

func main() {
	defer out.Flush()
	var t int
	for scanf("%d\n", &t); t > 0; t-- {
		var n int
		scanf("%d\n", &n)
		set := map[int]struct{}{}
		for i := 0; i < n; i++ {
			var ai int
			scanf("%d ", &ai)
			set[ai] = struct{}{}
		}
		printf("%d\n", len(set))
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		m := make(map[int]int)
		for j := 0; j < n; j++ {
			var inp int
			fmt.Fscan(in, &inp)
			m[inp] = inp
		}
		fmt.Println(len(m))
	}
}

package main

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

func Memset(array []byte, value byte) {
	for i := 0; i < len(array); i++ {
		array[i] = value
	}
}

type Bitmap struct {
	array []byte
}

func NewBitmap(size int64) *Bitmap {
	return &Bitmap{array: make([]byte, int64(math.Ceil(float64(size) / 8.0)))}
}

func (b *Bitmap) Get(position int64) byte {
	x := position / 8
	y := 1 << (position % 8)
	return b.array[x] & byte(y)
}

func (b *Bitmap) Set(position int64) {
	x := position / 8
	y := 1 << (position % 8)
	b.array[x] |= byte(y)
}

func (b *Bitmap) Reset() {
	Memset(b.array, 0)
}

func main() {
	maxValue := int64(math.Pow10(9))
	var n, i, j int64
	var size int64
	var counter int64
	bitmap := NewBitmap(maxValue)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		if i > 0 {
			bitmap.Reset()
			counter = 0
		}
		str, _ := reader.ReadString('\n')
		size, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}
		for j = 0; j < size; j++ {
			delim := byte(' ')
			if j == size - 1 {
				delim = byte('\n')
			}
			str1, _ := reader.ReadString(delim)
			item, err := strconv.ParseInt(strings.TrimSpace(str1), 10, 64)
			if err != nil {
				fmt.Printf("err2: %v", err.Error())
				os.Exit(1)
			}
			if bitmap.Get(item - 1) != 0 {
				continue
			}
			bitmap.Set(item)
			counter++
		}
		writer.WriteString(strconv.FormatInt(counter, 10))
		writer.WriteString("\n")
	}
	writer.Flush()
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Scanf(format string, a ...interface{})
	Int() int
	Int64() int64
	String() string
	IntStream(size int) <-chan int
	Int64Stream(size int) <-chan int64
	StringStream(size int) <-chan string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

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

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	fmt.Fscan(impl.Reader, &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.Scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.Scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
	c := make(chan int)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
	c := make(chan int64)
	go func() {
		for i := 0; i < size-1; i++ {
			var v int64
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v int64
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
	c := make(chan string)
	go func() {
		for i := 0; i < size-1; i++ {
			var v string
			impl.Scanf("%d ", &v)
			c <- v
		}
		var v string
		impl.Scanf("%d\n", &v)
		c <- v
	}()
	return c
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%d ", &ret[i])
	}
	impl.Scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.Scanf("%s ", &ret[i])
	}
	impl.Scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

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

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

func main() {
	defer writer.Flush()
	t := reader.Int()
	for ; t > 0; t-- {
		n := reader.Int()
		c := reader.Int64Stream(n)
		tmp := map[int64]bool{}
		for i := 0; i < n; i++ {
			tmp[<-c] = true
		}
		writer.Printf("%d\n", len(tmp))
	}
}


package main

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

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

	solve := func() (ans int) {
		var n int64
		var m int
		Fscan(in, &n, &m)
		a := make([]int, m)
		sum := int64(0)
		cnts := map[int64]int{}
		for i := range a {
			Fscan(in, &a[i])
			sum += int64(a[i])
			cnts[int64(a[i])]++
		}
		if sum < n {
			return -1
		}
		//sort.Ints(a)

		n1 := n
		cnt := uint(0)
		for n1 > 0 {
			cur := int64(1) << cnt
			if n1&1 == 1 {
				if cnts[cur] > 0 {
					cnts[cur]--
				} else {
					i := cur << 1
					for ; cnts[i] == 0; i <<= 1 {
					}
					for ;i > cur;i>>=1 {
						cnts[i]--
						cnts[i>>1]+=2
						ans++
					}
					cnts[cur]-- // got it
				}
			}

			cnts[cur<<1] += cnts[cur] / 2
			cnts[cur] &= 1

			n1 >>= 1
			cnt++
		}

		return
	}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans int) {
		var n, v int64
		var m int
		Fscan(in, &n, &m)
		sum := int64(0)
		cnts := map[int64]int{}
		for i := 0; i < m; i++ {
			Fscan(in, &v)
			sum += v
			cnts[v]++
		}
		if sum < n {
			return -1
		}

		for i := int64(1); i <= n; i <<= 1 {
			if n&i > 0 {
				if cnts[i] == 0 {
					j := i << 1
					for ; cnts[j] == 0; j <<= 1 {
					}
					for ; j > i; j >>= 1 {
						cnts[j]--
						cnts[j>>1] += 2
						ans++
					}
				}
				cnts[i]--
			}
			cnts[i<<1] += cnts[i] >> 1
			cnts[i] &= 1
		}
		return
	}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, m := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([]int64, 63)
		weight := make([]int64, 63)
		weight[0] = 1
		for i := 1; i < 63; i++ {
			weight[i] = weight[i-1] * 2
		}
		//fmt.Println(weight)
		b := make([]int64, 0)
		sum := int64(0)
		cur := int64(0)
		for i := int64(0); i < m; i++ {
			tmp := int64(0)
			fmt.Fscanf(in, "%d", &tmp)
			a[getMi(tmp)]++
			sum += tmp
		}
		fmt.Fscanf(in, "\n")
		if sum < n {
			fmt.Fprintf(out, "%d\n", -1)
			continue
		}
		for n > 0 {
			b = append(b, n%2)
			n /= 2
		}
		ans := 0
		//fmt.Println(a)
		//fmt.Println(b)
		for i := 0; i < len(b); i++ {
			if b[i] == 1 {
				if cur >= weight[i] {
					cur -= weight[i]
				} else {
					for j := i; j < 63; j++ {
						if a[j] > 0 {
							ans += j - i
							a[j]--
							for k := i; k < j; k++ {
								a[k]++
							}
							break
						}
					}
				}
			}
			if i < 63 {
				cur += a[i] * weight[i]
				a[i] = 0
			}
		}
		//fmt.Println(a)
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func getMi(a int64) int64 {
	if a == 1 {
		return 0
	}
	return 1 + getMi(a/2)
}