package main

import (
	"fmt"
)

type digits []int

func compareTo(a, b digits) int {
	n := len(a)
	for i := 0; i < n; i++ {
		switch {
		case a[i] < b[i]:
			return -1
		case a[i] > b[i]:
			return 1
		}
	}
	return 0
}

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	var a [10]digits
	for i := 0; i < 10; i++ {
		a[i] = make(digits, n)
	}
	for i, r := range s {
		a[0][i] = int(r - '0')
	}
	for i := 1; i < 10; i++ {
		for j := 0; j < n; j++ {
			a[i][j] = (a[0][j] + i) % 10
		}
	}
	z := a[0]
	for i := 0; i < 10; i++ {
		x := a[i]
		for j := 0; j < n; j++ {
			if compareTo(x, z) < 0 {
				z = x
			}
			h := x[0]
			x = append(x[1:], h)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%c", z[i]+'0')
	}
	fmt.Println()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var ans []byte

func compare(s *[]byte, move int) {
    n := len(*s)
    isOk := false
    for i, c := range ans {
        ch := (*s)[(i+move)%n]
        if ch < c {
            isOk = true
            break
        } else if ch > c {
            break
        }
    }
    if isOk {
        for i := 0; i < n; i++ {
            ans[i] = (*s)[(i+move)%n]
        }
    }
}

func main() {
    scanner.Split(bufio.ScanWords)
    n := nextInt()
    str := next()
    num := make([]byte, n, n)
    ans = make([]byte, n, n)
    for i := 0; i < n; i++ {
        num[i] = byte(str[i] - '0')
        ans[i] = byte(str[i] - '0')
    }

    first := byte(0)
    for i := 0; i < 11; i++ {
        for j := 0; j < n; j++ {
            num[j] = (num[j] + first) % 10
        }
        for j := 0; j < n; j++ {
            compare(&num, j)
        }
        first = byte(1)
    }
    for _, s := range ans {
        fmt.Printf("%c", '0'+s)
    }
    fmt.Println()
}

func next() string {
    if !scanner.Scan() {
        panic("Scan error")
    }
    return scanner.Text()
}

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

package main

import (
	"bytes"
	"fmt"
)

var (
	n      int
	input  string
	result string
)

func in() {
	fmt.Scanln(&n)
	fmt.Scanln(&input)
}

func out() {
	fmt.Println(result)
}

func run() {
	var digits []byte = make([]byte, n)
	for i := 0; i < n; i++ {
		digits[i] = input[i] - byte('0')
	}

	var min []byte = nil
	for i := 0; i < n; i++ {
		curr := transform(digits, i)
		if isSmaller(curr, min) {
			min = curr
		}
	}

	result = toString(min)
}

func transform(digits []byte, pos int) []byte {
	var v byte = digits[pos]
	var trans []byte = make([]byte, n)
	for i := 0; i < n; i++ {
		trans[i] = (digits[(i+pos)%n] - v + 10) % 10
	}
	return trans
}

func isSmaller(curr, min []byte) bool {
	if min == nil {
		return true
	}

	for i := 0; i < len(curr); i++ {
		if curr[i] < min[i] {
			return true
		} else if curr[i] > min[i] {
			return false
		}
	}
	return false
}

func toString(value []byte) string {
	var buffer bytes.Buffer
	for _, v := range value {
		buffer.WriteByte(byte('0') + v)
	}
	return buffer.String()
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var init, res string

	fmt.Scan(&n)
	fmt.Scan(&init)

	for i := 0; i < n; i++ {
		res += "9"
	}

	for i := 0; i < n; i++ {
		var candidate string

		s := init[i:] + init[:i]
		diff := ('9' + 1 - s[0]) % 10

		for j := 0; j < n; j++ {
			candidate += string('0' + (s[j]+diff-'0')%10)
		}

		if candidate < res {
			res = candidate
		}
	}

	fmt.Println(res)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	s := next()
	min := []rune(s)

	for k := n; k > 0; k-- {
		s = s[1:] + s[:1]
		si := []rune(s)
		dif := si[0] - '0'

		// println(s, string(si), string(min))
		for i := 0; i < n; i++ {
			si[i] -= dif

			if si[i] < '0' {
				si[i] = '9' + 1 - '0' + si[i]
			}
		}

		for i := 0; i < n; i++ {
			if si[i] == min[i] {
				continue
			}

			if si[i] < min[i] {
				// println(string(si[i]), i ,string(min), string(min[i]))
				min = si
			}

			break
		}

		// println(s, string(si), string(min))
		// println()
	}

	println(string(min))
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

import (
	"bytes"
	"fmt"
)

var (
	n      int
	input  string
	result string
)

func in() {
	fmt.Scanln(&n)
	fmt.Scanln(&input)
}

func out() {
	fmt.Println(result)
}

func run() {
	var digits []byte = make([]byte, n)
	for i := 0; i < n; i++ {
		digits[i] = input[i] - byte('0')
	}

	var min []byte = nil
	for i := 0; i < n; i++ {
		curr := transform(digits, i)
		if isSmaller(curr, min) {
			min = curr
		}
	}

	result = toString(min)
}

func transform(digits []byte, pos int) []byte {
	var v byte = digits[pos]
	var trans []byte = make([]byte, n)
	for i := 0; i < n; i++ {
		trans[i] = digits[(i+pos)%n] - v
	}
	return trans
}

func isSmaller(curr, min []byte) bool {
	if min == nil {
		return true
	}

	for i := 0; i < len(curr); i++ {
		if curr[i] < min[i] {
			return true
		} else if curr[i] > min[i] {
			return false
		}
	}
	return false
}

func toString(value []byte) string {
	var buffer bytes.Buffer
	for _, v := range value {
		buffer.WriteByte(byte('0') + v)
	}
	return buffer.String()
}

func main() {
	in()
	run()
	out()
}


package main

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

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, res, cd, pd int
		var c rune
		var s []byte
		fmt.Fscanf(r, "\n%d %c\n%s", &n, &c, &s)

		for i, v := range s {
			if v == 'g' {
				pd = i
				break
			}
		}

		for j := n-1; j >= 0; j-- {
			if s[j] == 'g' {
				cd = 0
			} else {
				cd = pd + 1
			}

			if s[j] == byte(c) && cd > res {
				res = cd
			}
			pd = cd
		}

		fmt.Fprintln(w, res)
	}
}

package main

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

const (
	N = 2e5 + 10
)

var (
	ans, t, n int
	idx       []int
	c, s      string
)

func main() {
	defer flush()
	scan(&t)
	idx = make([]int, N)
	for ; t != 0; t-- {
		scan(&n, &c, &s)
		le := len(s)
		last := -1
		first := 0
		for i := le - 1; i >= 0; i-- {
			if s[i] == 'g' {
				last = i
				first = i
			}
			idx[i] = last
		}
		ans = 0
		for i := 0; i < le; i++ {
			if s[i] == c[0] {
				if idx[i] == -1 {
					ans = max(ans, le-i+first)
				} else {
					ans = max(ans, idx[i]-i)
				}
			}
		}
		println(ans)
	}
}

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

var (
	IOReader *bufio.Reader
	IOWriter *bufio.Writer
)

func init() {
	IOReader = bufio.NewReader(os.Stdin)
	IOWriter = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(IOReader, a...)
}

func println(a ...any) {
	fmt.Fprintln(IOWriter, a...)
}

func flush() {
	IOWriter.Flush()
}

package main

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

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

func main() {
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		var c string
		fmt.Fscan(in, &n, &c)
		var colors string
		fmt.Fscan(in, &colors)
		colors = colors + colors
		last := 0
		max := 0
		for j := len(colors) - 1; j >= 0; j-- {
			if colors[j] == 'g' {
				last = j
			}
			if colors[j] == c[0] {
				if last-j > max {
					max = last - j
				}
			}
		}
		fmt.Println(max)
	}
}

func countPow2(x int) int {
	temp := x
	count := 0
	for temp%2 == 0 {
		temp = temp / 2
		count++
	}
	return count
}

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	return a
}

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

type Ordered interface {
	int | float64 | ~string
}

package main

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

var reader = bufio.NewReader(os.Stdin)

var n, m int

func solve(typ, x int) {
	if x%2 == 0 {
		// will not change the odd even
		if typ == 0 { // even
			sum += even * x
		} else {
			sum += odd * x
		}
	} else { // will change the odd even, x is odd number
		if typ == 0 { // operating even number
			sum += even * x
			odd += even
			even = 0
		} else { // operating odd number
			sum += odd * x
			even += odd
			odd = 0
		}
	}
	fmt.Println(sum)
}

var odd, even, sum int

func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		var n int
		var c string
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &c)
		var s string
		fmt.Fscan(reader, &s)
		//0123456789
		//rggryrggry
		// 1    3
		//
		s = s + s
		res := 0
		for i := 0; i < n; i++ {
			if s[i] == c[0] {
				var j int
				for j = i; j < i+n; j++ {
					if s[j] == 'g' {
						res = max(res, j-i)
						break
					}
				}
				i = j
			}
		}
		fmt.Println(res)
	}
}

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

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

package main

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

func solution_1(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr int
		_, err := fmt.Fscanf(in, "%d\n", &narr)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")
		var s string
		_, err = fmt.Fscanf(in, "%s\n", &s)
		fmt.Fprintln(output, numberReplacement(arr, s))
	}
}

func solution_2(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr, q int
		_, err := fmt.Fscanf(in, "%d %d\n", &narr, &q)
		if err != nil {
			panic(err)
		}

		arr := make([]int, 0, narr)
		for j := 0; j < narr; j++ {
			var v int
			_, err := fmt.Fscanf(in, "%d", &v)
			if err != nil {
				panic(err)
			}
			arr = append(arr, v)
		}
		fmt.Fscanf(in, "\n")

		nOdd := 0
		nEven := 0
		sum := 0

		for _, n := range arr {
			sum += n
			if n%2 == 0 {
				nEven++
			} else {
				nOdd++
			}
		}
		for j := 0; j < q; j++ {
			var a, b int
			fmt.Fscanf(in, "%d %d\n", &a, &b)
			if a == 0 {
				sum += nEven * b
				if b%2 != 0 {
					nOdd += nEven
					nEven = 0
				}
			}

			if a == 1 {
				sum += nOdd * b
				if b%2 != 0 {
					nEven += nOdd
					nOdd = 0
				}
			}
			fmt.Fprintln(output, sum)
		}

	}
}

func numberReplacement(arr []int, s string) string {
	if len(arr) != len(s) {
		return "NO"
	}

	someMap := make(map[int]byte)
	for i, n := range arr {
		if v, ok := someMap[n]; !ok {
			someMap[n] = s[i]
		} else {
			if v != s[i] {
				return "NO"
			}
		}
	}

	return "YES"
}

func solution_3(input io.Reader, output io.Writer) {
	in := bufio.NewReader(input)
	var n int
	_, err := fmt.Fscanf(in, "%d\n", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		var narr int
		var colour string
		_, err := fmt.Fscanf(in, "%d %s\n", &narr, &colour)
		if err != nil {
			panic(err)
		}

		var s string
		_, err = fmt.Fscanf(in, "%s\n", &s)
		if err != nil {
			panic(err)
		}
		fmt.Fprintln(output, waitTime(s, colour))
	}
}

func waitTime(s string, c string) int {
	if c == "g" {
		return 0
	}
	maxRes := 0
	firstGreenIndex := -1
	i := len(s) - 1
	curDist := 1

	for {
		if s[i] == 'g' {
			firstGreenIndex = i
			break
		}
		i--
	}

	i--
	if i < 0 {
		i = len(s) - 1
	}
	distances := make([]int, len(s))

	for i != firstGreenIndex {
		if s[i] == 'g' {
			curDist = 0
		}
		distances[i] = curDist
		curDist++
		i--
		if i < 0 {
			i = len(s) - 1
		}
	}

	for i := 0; i < len(s); i++ {
		if s[i] == c[0] {
			curDist := distances[i]
			if curDist > maxRes {
				maxRes = curDist
			}
		}
	}

	return maxRes
}

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

package main

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return 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 c string
		var s string
		fmt.Fscan(in, &n, &c, &s)

		ch := c[0]
		if ch == 'g' {
			fmt.Fprintln(out, 0)
			continue
		}

		last := -1
		var mx int
		var crossed bool
		for i := 0; i < n; i++ {
			if s[i] == ch {
				if last < 0 || crossed {
					last = i
					crossed = false
				}
			} else if s[i] == 'g' && last >= 0 && !crossed {
				mx = max(mx, i-last)
				crossed = true
			}
		}
		if last > 0 && !crossed {
			var d int
			for i := range s {
				if s[i] == 'g' {
					d = i
					break
				}
			}
			mx = max(mx, n-last+d)
		}
		fmt.Fprintln(out, mx)
	}
}

package main

import "fmt"

func main() {
	var test, l int
	var s, si string

	fmt.Scanln(&test)
	for test > 0 {
		fmt.Scanln(&l, &si)
		fmt.Scanln(&s)
		fmt.Println(trafficLight(si, s))
		test--
	}
}

func trafficLight(si, s string) int {
	mp := map[byte][]int{}
	for i := range s {
		mp[s[i]] = append(mp[s[i]], i)
	}
	k := mp[si[0]]
	g := mp['g']
	g = append(g, g[0]+len(s))
	max := 0
	gi := 0
	for i := range k {
		if k[i] > g[gi] {
			for k[i] > g[gi] {
				gi++
			}
		}
		if max < g[gi]-k[i] {
			max = g[gi] - k[i]
		}
	}
	return max
}

package main

import "fmt"

func main() {
	var (
		t, n, max, cur int
		c, pattern     string
	)
	fmt.Scan(&t)
	for j := 0; j < t; j++ {
		fmt.Scan(&n, &c)
		fmt.Scan(&pattern)
		if c == "g" {
			fmt.Println(0)
			continue
		}
		max = 0
		for i := 0; i < 2*n; i++ {
			for ; pattern[i%n] != c[0]; i++ {
			}
			cur = 0
			for ; i < 2*n; i++ {
				if pattern[i%n] == "g"[0] {
					if cur > max {
						max = cur
					}
					break
				}
				cur += 1
			}
		}
		fmt.Println(max)
	}
}

package main

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

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

func max(i, j int) int {
    if i >= j {
        return i
    } else {
        return j
    }
}

func solve() {
    var n int
    var c, s string
    Fscan(in, &n, &c, &s)

    s = s + s
    ans := 0
    for i, j := 0, 0; i < 2 * n; i++ {
        if string(s[i]) != c {
            continue
        }

        for ; j < 2 * n && (j < i || string(s[j]) != "g"); j++ {

        }

        if j < 2 * n && j - i > ans {
            ans = j - i
        }
    }

    Fprintln(out, ans)
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

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

func solve() {
	_ = _readInt()
	start := rune(_readStr()[0])
	s := []rune(_readStr())
	if start == 'g' {
		_print(0)
		return
	}

	var fg int
	for s[fg] != 'g' {
		fg++
	}
	s = append(s, s[:fg+1]...)

	var res int
	for i := 0; i < len(s); i++ {
		if s[i] == start {
			var cnt int
			for s[i] != 'g' {
				cnt++
				i++
			}
			res = _max(res, cnt)
		}
	}
	_print(res)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr() (int, []int) {
	var n int
	fmt.Fscan(in, &n)
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func _min(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n, c := nextInt(), nextString()[0]
		s := nextString()
		idx := 0
		for i := 0; i < n; i++ {
			if s[i] == 'g' {
				idx = i
				break
			}
		}
		flag := false
		ans := 0
		for i, j := n-1, -1; i >= 0; i-- {
			if !flag && s[i] == 'g' {
				flag = true
			}
			if s[i] == 'g' {
				j = i
			}
			if s[i] != c {
				continue
			}
			if !flag {
				ans = max(ans, n-i+idx)
			} else {
				ans = max(ans, j-i)
			}
		}
		fmt.Println(ans)
	}
}

func max(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v > res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

package main

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

const cf = true

func solve() {
	var n int
	var c string
	fmt.Fscan(in, &n, &c)
	var str string
	fmt.Fscan(in, &str)
	worst := make(map[byte]int)
	curG := 0
	for str[curG] != byte('g') {
		curG++
	}
	curG += n
	for i := n - 1; i >= 0; i-- {
		if str[i] == byte('g') {
			curG = i
			continue
		}
		val, ok := worst[str[i]]
		if !ok {
			worst[str[i]] = curG - i
		} else {
			worst[str[i]] = max(val, curG-i)
		}
	}
	fmt.Fprintln(out, worst[c[0]])
}

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

func GCD(a, b int) int {
	for a != b {
		if a > b {
			a -= b
		} else {
			b -= a
		}
	}

	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"
	"os"
)

func max(a, b int) int {
	if a > b {
		return a
	}
	return 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 c string
		var s string
		fmt.Fscan(in, &n, &c, &s)

		ch := c[0]
		if ch == 'g' {
			fmt.Fprintln(out, 0)
			continue
		}

		last := -1
		var mx int
		var crossed bool
		for i := 0; i < n; i++ {
			if s[i] == ch {
				if last < 0 || crossed {
					last = i
					crossed = false
				}
			} else if s[i] == 'g' && last >= 0 {
				mx = max(mx, i-last)
				crossed = true
			}
		}
		if last > 0 && !crossed {
			var d int
			for i := range s {
				if s[i] == 'g' {
					d = i
					break
				}
			}
			mx = max(mx, n-last+d)
		}
		fmt.Fprintln(out, mx)
	}
}


package main

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

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

	ask := func(c int) int {
		fmt.Printf("+ %d\n", c)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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') && bs[x] != '-' {
			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 solve(n int, ask func(c int) int) int {

	l, r := 1, n
	var div int

	for r-l > 1 {
		mid := (l + r) / 2
		d := ask(n - mid)

		if d > div {
			l = mid
		} else {
			r = mid
		}
		l = (l + n - mid) % n
		r = (r + n - mid) % n
		if r == 0 {
			r = n
		}
		div = d
	}

	return div*n + l
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var (
		sum  = 0
		k    = 0
		l, r = 0, n
	)
	for r-l > 1 {
		m := l + (r-l)/2
		req := n - m
		if sum%n > 0 {
			if n-m-sum%n < 0 {
				req += n - sum%n
			} else {
				req -= sum % n
			}
		}
		resp := ask(req)
		if resp == k {
			r = m
		} else {
			l = m
		}
		sum += req
		k = resp
	}
	printf("! %v\n", sum+l)
	writer.Flush()
}

func ask(c int) (r int) {
	printf("+ %v\n", c)
	writer.Flush()
	scan(&r)
	return
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var (
		sum  = 0
		k    = 0
		l, r = 0, n
	)
	for r-l > 1 {
		m := l + (r-l)/2
		req := n - m
		if sum%n > 0 {
			if n-m-sum%n < 0 {
				req += n - sum%n
			} else {
				req -= sum % n
			}
		}
		if req >= n {
			panic("123")
		}
		// printf("--> %v %v [%v] n-m=%v sum%%n=%v k=%v\n", l, r, m, n-m, sum%n, k)
		// writer.Flush()
		resp := ask(req)
		writer.Flush()
		if resp == k {
			r = m
		} else {
			l = m
		}
		sum += req
		k = resp
	}
	printf("! %v\n", sum+l)
	writer.Flush()
}

func ask(c int) (r int) {
	printf("+ %v\n", c)
	writer.Flush()
	scan(&r)
	return
}

// generated by 1e9y at 10-01-2022
// template version: 2022-01

package main

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

// 1624.F
func solve() {
	// here goes solution
}

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

	n := ReadInt(in)
	left, right := 1, n
	prev, total := 0, 0
	var mid, curr int
	for left <= right {
		mid = left + (right-left)/2
		c := (prev+1)*n - (mid + total)
		total += c
		Fprintf(out, "+ %v\n", c)
		out.Flush()
		curr = ReadInt(in)
		if curr <= prev {
			right = mid - 1
		} else {
			left = mid + 1
		}
		prev = curr
		// here goes input reading
		// input := ReadIntSlice(in)
	}
	Fprintf(out, "! %v\n", right+total)
	out.Flush()
}

// helpers for convenient input reading

func ReadInt(in *bufio.Reader) int {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	n, _ := strconv.Atoi(line)
	return n
}

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

func ReadLineParts(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	parts := strings.Split(line, " ")
	return parts
}

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var (
		sum  = 0
		k    = 0
		l, r = 1, n
	)
	for r-l > 1 {
		m := l + (r-l)/2
		req := n - m
		if sum%n > 0 {
			if n-m-sum%n < 0 {
				req += n - sum%n
				k++
			} else {
				req -= sum % n
			}
		}
		if req >= n {
			panic("123")
		}
		resp := ask(req)
		if resp == k {
			r = m
		} else {
			l = m
		}
		sum += req
		k = resp
	}
	printf("! %v\n", sum+l)
	writer.Flush()
}

func ask(c int) (r int) {
	printf("+ %v\n", c)
	writer.Flush()
	scan(&r)
	return
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var (
		sum  = 0
		k    = 0
		l, r = 1, n
	)
	for r-l > 1 {
		m := l + (r-l)/2
		req := n - m
		if sum%n > 0 {
			if n-m-sum%n < 0 {
				req += n - sum%n
				k++
			} else {
				req -= sum % n
			}
		}
		if req >= n {
			panic("123")
		}
		resp := ask(req)
		if resp == k {
			r = m
		} else {
			l = m
		}
		sum += req
	}
	printf("! %v\n", l)
	writer.Flush()
}

func ask(c int) (r int) {
	printf("+ %v\n", c)
	writer.Flush()
	scan(&r)
	return
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	// defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	// scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var (
		sum  = 0
		k    = 0
		l, r = 1, n
	)
	for r-l > 1 {
		// printf("Request: %v %v %v\n", l, r, l+(r-l)/2)
		// writer.Flush()

		m := l + (r-l)/2
		req := n - m
		if sum%n > 0 {
			req += n - sum%n
			if sum/n < (sum+n-sum%n)/n {
				k++
			}
		}

		// printf("%v %v\n\n", req, k)
		// writer.Flush()

		resp := ask(req)
		if resp == k {
			r = m
		} else {
			l = m
		}
		sum += req
	}
	printf("! %v\n", l)
	writer.Flush()
}

func ask(c int) (r int) {
	printf("+ %v\n", c)
	writer.Flush()
	scan(&r)
	return
}

package main

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

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

	ask := func(c int) int {
		fmt.Printf("+ %d\n", c)
		return readNum(reader)
	}

	n := readNum(reader)

	res := solve(n, ask)

	fmt.Printf("! %d\n", res)
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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') && bs[x] != '-' {
			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 solve(n int, ask func(c int) int) int {

	l, r := 1, n

	i := 1
	var sum int
	for l < r {
		mid := (l + r) / 2

		tmp := i*n + mid - sum
		// x + n + mid
		ans := ask(tmp)

		// this time ask tmp
		// and we want x + tmp + tmp2 = x + i * n - mid
		// tmp2 = i * n - mid - tmp

		sum += tmp

		if ans == i {
			// x + mid < n
			// x <  n - mid
			// what now? in next round, we need to increase mid, to make it approch x
			l = mid + 1
		} else {
			// ans = expect + 1
			// x >= n - mid
			r = mid
		}
		i++
	}

	return sum + n - r
}

// generated by 1e9y at 10-01-2022
// template version: 2022-01

package main

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

// 1624.F
func solve() {
	// here goes solution
}

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

	n := ReadInt(in)
	left, right := 1, n
	prev, total := 0, 0
	var mid, curr int
	for left <= right {
		mid = left + (right-left)/2
		c := (prev+1)*n - (mid + total)
		Fprintf(out, "+ %v\n", c)
		out.Flush()
		curr = ReadInt(in)
		if curr <= prev {
			right = mid - 1
		} else {
			left = mid + 1
		}
		prev = curr
		// here goes input reading
		// input := ReadIntSlice(in)
	}
	Fprintf(out, "! %v\n", right+total)
	out.Flush()
}

// helpers for convenient input reading

func ReadInt(in *bufio.Reader) int {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	n, _ := strconv.Atoi(line)
	return n
}

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

func ReadLineParts(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	parts := strings.Split(line, " ")
	return parts
}

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}


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()
	primeDivisors := func(x int) (primes []int) {
		for i := 2; i*i <= x; i++ {
			if x%i == 0 {
				for x /= i; x%i == 0; x /= i {
				}
				primes = append(primes, i)
			}
		}
		if x > 1 {
			primes = append(primes, x)
		}
		return
	}

	var n int
	Fscan(in, &n)
	if n == 2 {
		Fprintln(out, 1)
		Fprintln(out, 1)
		return
	}
	ans := []int{}

	ps := primeDivisors(n)
	if ps[0] == n {
		for i := 1; i < n-1; i++ {
			ans = append(ans, i)
		}
		Fprintln(out, len(ans))
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		return
	}

	del := make([]bool, n)
	for _, p := range ps {
		for i := p; i < n; i += p {
			del[i] = true
		}
	}

	mul := int64(1)
	for i := 1; i < n-1; i++ {
		if !del[i] {
			ans = append(ans, i)
			mul = mul * int64(i) % int64(n)
		}
	}
	if mul != 1 {
		mul = mul*int64(n-1)%int64(n)
		ans = append(ans, n-1)
	}
	if mul != 1 {
		panic(n)
	}
	//Println(n,mul, len(ans))
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprint(out, v, " ")
	}
}

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

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)

	candi := []int64{}
	candiProd := int64(1)
	for i := 1; i < n; i++ {
		if gcd(i, n) != 1 {
			continue
		}
		candi = append(candi, int64(i))
		candiProd *= int64(i)
		candiProd %= int64(n)
	}
	if candiProd != 1 {
		for i, v := range candi {
			if v != candiProd {
				continue
			}
			candi = append(candi[:i], candi[i+1:]...)
			break
		}
	}
	fmt.Println(len(candi))
	for _, v := range candi {
		fmt.Print(v, " ")
	}
	fmt.Println()
}

package main

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

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

}
func exgcd(a, b int64) (gcd, x, y int64) {
	if b == 0 {
		return a, 1, 0
	}
	gcd, y, x = exgcd(b, a%b)
	y -= a / b * x
	return
}
func inv(a, b int64) int64 {
	_, x, _ := exgcd(a, b)
	x = (x%b + b) % b
	return x
}

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

	solve := func() {
		var n int64
		fmt.Fscan(in, &n)
		var prod int64 = 1

		for i := int64(1); i < n; i++ {
			if gcd(n, i) == 1 {
				prod = prod * i % n
			}
		}

		var j int64 = inv(prod, n)
		var ans []int64
		for i := int64(1); i < n; i++ {
			if gcd(n, i) == 1 {
				if i*j%n != 1 || prod == 1 {
					ans = append(ans, i)
				}
			}
		}
		fmt.Fprintln(out, len(ans))
		for i := 0; i < len(ans); i++ {
			fmt.Fprint(out, ans[i], " ")
		}
		fmt.Fprintln(out)
	}

	var T int = 1
	// fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func gcd(x, y int)int{
	for y>0{
		temp :=y
		y = x%y
		x = temp
	}
	return x
}
func max(x, y int)int{
	if x>y{
		return x
	}
	return y
}
func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n)
	ans := []int{}
	for i:=1;i<=n-1;i++{
		if gcd(n,i)==1{
			ans = append(ans,i)
		}
	}
	var cool int64
	cool = 1
	ma := 0
	for i:=0;i<len(ans);i++{
		cool = (cool%int64(n) * int64(ans[i]%n))%int64(n)
		if cool==1{
			ma = i
		}
	}
	cool = 1
	fmt.Fprintln(out,ma+1)
	for i:=0;i<=ma;i++{
		cool = (cool%int64(n) * int64(ans[i])%int64(n))%int64(n)
		fmt.Fprintf(out,"%d " ,ans[i])
	}
}

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()
	primeDivisors := func(x int) (primes []int) {
		for i := 2; i*i <= x; i++ {
			if x%i == 0 {
				for x /= i; x%i == 0; x /= i {
				}
				primes = append(primes, i)
			}
		}
		if x > 1 {
			primes = append(primes, x)
		}
		return
	}

	var n int
	Fscan(in, &n)
	ps := primeDivisors(n)

	del := make([]bool, n)
	for _, p := range ps {
		for i := p; i < n; i += p {
			del[i] = true
		}
	}

	mul := 1
	ans := []int{}
	for i := 1; i < n-1; i++ {
		if !del[i] {
			ans = append(ans, i)
			mul = mul * i % n
		}
	}
	if mul != 1 {
		ans = append(ans, n-1)
		mul = mul*(n-1)%n
	}
	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprint(out, v, " ")
	}
}

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

package main

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

func gcd(x, y int)int{
	for y>0{
		temp :=y
		y = x%y
		x = temp
	}
	return x
}
func max(x, y int)int{
	if x>y{
		return x
	}
	return y
}
func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n)
	ans := []int{}
	for i:=1;i<=n-1;i++{
		if gcd(n,i)==1{
			ans = append(ans,i)
		}
	}
	cool := 1
	ma := 0
	for i:=0;i<len(ans);i++{
		cool = (cool%n * ans[i]%n)%n
		if cool==1{
			ma = i
		}
	}
	cool = 1
	fmt.Fprintln(out,ma+1)
	for i:=0;i<=ma;i++{
		cool = (cool%n * ans[i]%n)%n
		fmt.Fprintf(out,"%d " ,ans[i])
	}
}

package main

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

func gcd(x, y int)int{
	for y>0{
		temp :=y
		y = x%y
		x = temp
	}
	return x
}
func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n)
	ans := []int{}
	for i:=1;i<=n-1;i++{
		if gcd(n,i)==1{
			ans = append(ans,i)
		}
	}
	if n%2==1{
		ans = ans[:len(ans)-1]
	}
	fmt.Fprintln(out,len(ans))
	for i:=0;i<len(ans);i++{
		fmt.Fprintf(out,"%d ",ans[i])
	}
}

package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)

	candi := []int64{}
	candiProd := int64(1)
	for i := 1; i < n; i++ {
		if gcd(i, n) != 1 {
			continue
		}
		candi = append(candi, int64(i))
		candiProd *= int64(i)
		candiProd %= int64(n)
	}
	if candiProd != 1 {
		for i, v := range candi {
			if v != candiProd {
				continue
			}
			candi = append(candi[:i], candi[i+1:]...)
			break
		}
	}
	for _, v := range candi {
		fmt.Print(v, " ")
	}
	fmt.Println()
}

package main

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

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

}
func exgcd(a, b int64) (gcd, x, y int64) {
	if b == 0 {
		return a, 1, 0
	}
	gcd, y, x = exgcd(b, a%b)
	y -= a / b * x
	return
}
func inv(a, b int64) int64 {
	_, x, _ := exgcd(a, b)
	x = (x%b + b) % b
	return x
}

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

	solve := func() {
		var n int64
		fmt.Fscan(in, &n)
		var prod int64 = 1

		for i := int64(1); i < n; i++ {
			if gcd(n, i) == 1 {
				prod = prod * i % n
			}
		}

		var j int64 = inv(prod, n)

		for i := int64(1); i < n; i++ {
			if gcd(n, i) == 1 {
				if i*j%n != 1 || prod == 1 {
					fmt.Fprint(out, i, " ")
				}
			}
		}
		fmt.Fprintln(out)
	}

	var T int = 1
	// fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1350B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	const mx int = 1e5
	ds := [mx + 1][]int{}
	for i := 1; i <= mx; i++ {
		for j := 2 * i; j <= mx; j += i {
			ds[j] = append(ds[j], i)
		}
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		dp := make([]int, n)
		ans := 0
		for i := range a {
			Fscan(in, &a[i])
			dp[i] = 1
			for _, d := range ds[i+1] {
				if a[d-1] < a[i] {
					dp[i] = max(dp[i], dp[d-1]+1)
				}
			}
			ans = max(ans, dp[i])
		}
		Fprintln(out, ans)
	}
}

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

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						if count[i]+1 > count[j] {
							count[j] = count[i] + 1
						}
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}
		fmt.Println(max)

	}
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int
	n int
	S []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		S = ReadIntSlice(n)
		solve(n, S)
	}
}

func solve(n int, tmp []int) {
	S := []int{-1}
	S = append(S, tmp...)

	G := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		cid := i

		for j := 2; i*j <= n; j++ {
			nid := i * j

			if S[cid] < S[nid] {
				G[cid] = append(G[cid], nid)
			}
		}
	}

	_, sorted := tsort(n+1, G)
	ans := longestPath(sorted, G) + 1
	fmt.Println(ans)
}

// O(|E| + |V|)
// ノードIDは0-based
// ok, ans := tsort(v, edges[:])
// https://onlinejudge.u-aizu.ac.jp/problems/GRL_4_B
func tsort(nn int, edges [][]int) (bool, []int) {
	res := []int{}

	degin := make([]int, nn)
	for s := 0; s < nn; s++ {
		for _, t := range edges[s] {
			degin[t]++
		}
	}

	st := []int{}
	for nid := 0; nid < nn; nid++ {
		if degin[nid] == 0 {
			st = append(st, nid)
		}
	}

	for len(st) > 0 {
		cid := st[len(st)-1]
		res = append(res, cid)
		st = st[:len(st)-1]

		for _, nid := range edges[cid] {
			degin[nid]--
			if degin[nid] == 0 {
				st = append(st, nid)
			}
		}
	}

	if len(res) != nn {
		return false, nil
	}

	return true, res
}

// トポロジカルソート済みリストから最長経路の長さを計算する
// l := longestPath(res, edges[:])
// https://atcoder.jp/contests/abc139/tasks/abc139_e
func longestPath(tsortedNodes []int, edges [][]int) int {
	dp := make([]int, len(tsortedNodes)+1)

	for i := 0; i < len(tsortedNodes); i++ {
		cid := tsortedNodes[i]
		for _, nid := range edges[cid] {
			ChMax(&dp[nid], dp[cid]+1)
		}
	}

	res := 0
	for i := 0; i < len(tsortedNodes); i++ {
		ChMax(&res, dp[i])
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var dp = make([]int, 100004)

func main() {
	for t := ScanInt(); t > 0; t-- {
		for i := 0; i < 100004; i++ {
			dp[i] = 1
		}
		n := ScanInt()
		s := ScanIntSlice(n)
		s = append([]int{0}, s...)

		maxL := 1
		for i := 1; i <= n; i++ {
			if dp[i] > 1 {
				maxL = max(maxL, dp[i])
			} else {
				maxL = max(maxL, 1+f(i, n, s))
				dp[i] = maxL
			}
		}

		P(maxL)
	}

	close(O)
	oWg.Wait()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func f(ind, n int, s []int) int {

	if ind > n {
		return 0
	}
	count := 0
	for i := ind; i <= n; i += ind {
		if s[i] > s[ind] {
			count = max(count, 1+f(i, n, s))
			dp[ind] = count
		}
	}

	return count
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		s := make([]int, n+1)
		dp := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&s[i])
			dp[i] = 1
		}

		max := 0
		for i := 1; i <= n; i++ {
			for j := i * 2; j <= n; j += i {
				if s[j] > s[i] && dp[j] < dp[i]+1 {
					dp[j] = dp[i] + 1
				}
			}
			if max < dp[i] {
				max = dp[i]
			}
		}
		fmt.Println(max)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

const (
	INF = math.MaxInt64
	MOD = 1e9 + 7
	LIM = 100000
)

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

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

func sol(ss []int64) int64 {
	dp := make([]int64, len(ss))
	dp[0] = 1
	maxSoFar := int64(1)
	for i := int64(0); i < int64(len(dp)); i++ {
		for j := int64(2); j < int64(len(dp)); j++ {
			nxtIdx := (i+1)*j-1
			if nxtIdx >= int64(len(dp)) {
				break
			}
			if (nxtIdx + 1) % (i + 1) == 0 && ss[nxtIdx] > ss[i] {
				dp[nxtIdx] = max(dp[nxtIdx], dp[i]+1)
				maxSoFar = max(maxSoFar, dp[nxtIdx])
			} else {
				dp[nxtIdx] = max(dp[nxtIdx], 1)
			}
		}
	}
	return maxSoFar
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scan(&a[i])
	}

	dp := make([]float64, n+1)
	for i := 1; i <= n; i++ {
		dp[i] = 1
	}

	for i := 1; i <= n; i++ {
		for j := i + i; j <= n; j += i {
			if a[i] < a[j] {
				dp[j] = math.Max(dp[j], dp[i]+1)
			}
		}
	}
	ans := 0.0
	for i := 1; i <= n; i++ {
		ans = math.Max(ans, dp[i])
	}
	fmt.Println(ans)
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

// https://codeforces.com/contest/1350/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1

	}

	ans := 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
				ans = max(ans,dp[k])
			}
		}
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
	}

	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
		}
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k <= sqr(i) + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

func sqr(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2
		}
	}

	if n == 1 {
		return 1
	}

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++

		}
	}

	if n == 1 {
		return 1
	}
	ans := 2

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])

	}
	dp[0] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2

		}
	}
	//fmt.Println(dp)
	if n == 1 {
		return 1
	}

	for z := 2; z <= n; z++ {
		for k := 2; k*k <= z; k++ {
			if z % k == 0 && s[z - 1] > s[z / k - 1] {
				dp[z - 1] = max(dp[z - 1], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[z - 1])
	}

	return ans
}

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

// https://codeforces.com/contest/1350/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
	}

	dp[1] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
	}

	ans := 1
	for i := 1; i <= n; i++ {
		ans = max(ans,dp[i])
	}

	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n + 1)
	dp := make([]int, n + 1)
	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[1] = 1
	for i := 1; i <= n; i++ {
		for k := 2*i; k <= n; k += i {
			if s[k] > s[i] {
				dp[k] = max(dp[k], dp[i] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}
	dp := make([]int, n)
	ans := 1
	dp[0] = 1
	for z := 2; z <= n; z++ {
		for k := 2; z / k > 0; k++ {
			if z % k == 0 && s[z - 1] > s[z / k - 1] {
				dp[z - 1] = max(dp[z - 1], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[z - 1])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
			if s[z - 1] > s[0] {
				dp[i]++
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}
		z := i + 1
		//println("check z", z)
		for k := 2; k <= sqrt(z) + 1; k++ {
		//	println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}
		z := i + 1
		//println("check z", z)
		for k := 2; k <= sqrt(z); k++ {
		//	println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						if count[i]+1 > count[j] {
							count[j] = count[i] + 1
						}
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}

		fmt.Println(count)

		fmt.Println(max)

	}
}

package main

import "fmt"

func main() {
	var t int

	fmt.Scan(&t)

	for t > 0 {
		t--
		var n int

		fmt.Scan(&n)

		arr := make([]int, n)
		count := make([]int, n)

		for i := range arr {
			fmt.Scan(&arr[i])
			count[i]++
		}

		for i := 0; i <= n/2; i++ {
			for j := 2*i + 1; j < n; j += i + 1 {
				if (j+1)%(i+1) == 0 {
					if arr[j] > arr[i] {
						count[j]++
					}
				}
			}
		}

		max := 1

		for _, i := range count {
			if i > max {
				max = i
			}
		}
		fmt.Println(max)

	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)
		s := make([]int, n+1)
		dp := make([]int, n+1)
		for i := 1; i <= n; i++ {
			fmt.Scan(&s[i])
		}

		max := 0
		for i := 1; i <= n; i++ {
			if s[i] > s[i/2] {
				dp[i] = dp[i/2] + 1
			} else {
				dp[i] = 1
			}

			if max < dp[i] {
				max = dp[i]
			}
		}
		fmt.Println(max)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

type WordScanner interface {
	NextInt64() int64
	NextUInt64() uint64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

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

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

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

func sol(ss []int64) int64 {
	dp := make([]int64, len(ss))
	dp[0] = 1
	maxSoFar := int64(1)
	for i := 1; i < len(dp); i++ {
		for j := i-1; j >= 0; j-- {
			if (i+1) % (j+1) == 0 && ss[i] > ss[j] {
				dp[i] = max(dp[i], dp[j] + 1)
				maxSoFar = max(maxSoFar, dp[i])
			}
		}
	}
	return maxSoFar
}

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	dp[0] = 1
	for i := 1; i < n; i++ {
		z := i + 1
		dp[i] = 1
		if s[i] > s[0] {
			dp[i]++
		}

		for k := 2; k*k <= z; k++ {
			//println("iter", k, s[i] > s[z / k - 1], i , z / k - 1)
			if z % k == 0 && s[i] > s[z / k - 1] {
				dp[i] = max(dp[i], dp[z / k - 1] + 1)
			}
		}
		ans = max(ans,dp[i])
	}
	//fmt.Println(dp)
	return ans
}

func sqrt(a int) int {
	return int(math.Sqrt(float64(a)))
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
		}
	}

	if n == 1 {
		return 1
	}

	ans := 1
	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var (
	input io.Reader
)

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
	}

	ans := 1
	for i := 2; 2*i <= n; i++ {
		tmp := 1
		for k := 2; k * i <= n; k++ {
			if s[k*i - i - 2] < s[k*i - 1] {
				tmp++
			}
		}
		ans = max(ans, tmp)
	}

	fmt.Println(ans)
}

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

// https://codeforces.com/contest/1352/problem/B
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() int {
	var n int
	fmt.Fscan(input, &n)
	s := make([]int, n)
	dp := make([]int, n)
	ans := 1
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &s[i])
		dp[i] = 1
		if i > 0 && s[i] > s[0] {
			dp[i]++
			ans = 2

		}
	}
	//fmt.Println(dp)
	if n == 1 {
		return 1
	}

	for i := 1; i < n; i++ {
		for k := 2; k*k <= i + 1; k++ {
			z := i + 1
			for z % k == 0 {
				if s[z - 1] > s[z / k - 1] {
					dp[i] = max(dp[i], dp[z / k - 1] + 1)
				}
				z /= k
			}
		}
		ans = max(ans,dp[i])
	}

	return ans
}

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