package main

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

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

	const mx = 2750132
	id := [mx]int{-1, -1}
	f := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if id[i] == 0 {
			id[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				id[j] = -1
				if f[j] == 0 {
					f[j] = i
				}
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			v := id[i]
			if v > 0 {
				cnt[v] -= c
			} else {
				cnt[i/f[i]] -= c
				v = i
			}
			for ; c > 0; c-- {
				ans = append(ans, v)
			}
		}
	}
	Fprint(out, ans...)
}

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

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			primos[j] = min(i, primos[j])
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.ParseUint(input[i], 10, 0)
		if val < 0 || val > uint64(len(repeticionesIn)) {
			fmt.Println(val)
		}
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)
	fmt.Println("hola1")
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}
	fmt.Println("hola2")
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(total)

		}
	}()
	fmt.Println()
	SieveOfEratosthenes(total)
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	fmt.Println(limite)
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			primos[j] = min(i, primos[j])
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.ParseUint(input[i], 10, 0)
		if val < 0 || val > uint64(len(repeticionesIn)) {
			fmt.Println(val)
		}
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	// for i := 1; i < len(r); i++ {
	// 	fmt.Printf(" %d", r[i])
	// }

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
// func SieveOfEratosthenes(limite int) {

// 	for i := 2; i < limite; i++ {

// 		if primos[i] != i {
// 			primos[i] = i / primos[i]
// 			continue
// 		}
// 		for j := i * i; j < limite; j += i {
// 			if j > len(primos) {

// 			}
// 			primos[j] = i
// 		}
// 	}
// }

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()
	fmt.Println("hola1")
	for i := 0; i < total; i++ {
		primos[i] = i
	}
	fmt.Println("hola2")
	// SieveOfEratosthenes(total)
	for i := 2; i < total; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < total; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > int64(len(primos)) {

			}
			primos[j] = i
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
// func SieveOfEratosthenes(limite int) {

// 	for i := 2; i < limite; i++ {

// 		if primos[i] != i {
// 			primos[i] = i / primos[i]
// 			continue
// 		}
// 		for j := i * i; j < limite; j += i {
// 			if j > len(primos) {

// 			}
// 			primos[j] = i
// 		}
// 	}
// }

func main() {
	var auxi, auxj int
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			fmt.Println(auxi, auxj)
		}
	}()
	fmt.Println("hola1")
	for i := 0; i < total; i++ {
		primos[i] = i
	}
	fmt.Println("hola2")
	// SieveOfEratosthenes(total)
	for auxi = 2; auxi < total; auxi++ {

		if primos[auxi] != auxi {
			primos[auxi] = auxi / primos[auxi]
			continue
		}
		for auxj = auxi * auxi; auxj < total; auxj += auxi {
			primos[auxj] = auxi
		}
	}

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			if j > len(primos) {
				fmt.Println(j)
			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {
		if i > len(primos) {
			fmt.Println(i)
		}
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
		}
	}()
	SieveOfEratosthenes(total)
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}
	fmt.Println()
}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

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

	const mx = 2750132
	pid := [mx]int{-1, -1}
	lpf := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if pid[i] == 0 {
			pid[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				pid[j] = -1
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			if p := pid[i]; p > 0 {
				cnt[p] -= c
				ans = append(ans, p)
			} else {
				cnt[i/lpf[i]] -= c
				ans = append(ans, i)
			}
		}
	}
	Fprint(out, ans...)
}

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

package main

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

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

	const mx = 2750132
	pid := [mx]int{-1, -1}
	gpf := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if pid[i] == 0 {
			pid[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				pid[j] = -1
				gpf[j] = i
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			if p := pid[i]; p > 0 {
				cnt[p] -= c
				ans = append(ans, p)
			} else {
				cnt[gpf[i]] -= c
				ans = append(ans, i)
			}
		}
	}
	Fprint(out, ans...)
}

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


package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var s string
	fmt.Fscanf(reader, "%s", &s)
	matched, _ := regexp.MatchString("^[a-z]+@([a-z]{2,}@)*[a-z]+$",s)
	if !matched {
		fmt.Printf("No solution")
		return
	}
	segs := strings.Split(s, "@")
	fmt.Printf("%s@", segs[0])
	for i := 1;i < len(segs) - 1;i ++ {
		b := []byte(segs[i])
		fmt.Printf("%c,%s@", b[0], string(b[1:]))
	}
	fmt.Printf("%s", segs[len(segs) - 1])
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >=2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }else{
        return "No solution"
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            fmt.Println("tempA =",tempA)
            fmt.Println("tempA[1:len(tempA)-1 =",tempA[1:len(tempA)])
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    fmt.Println("tempR =",tempR)
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >=2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol472D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	readInt := func() (res int) {
		in.Scan()
		for _, b := range in.Bytes() {
			res = res*10 + int(b-'0')
		}
		return
	}

	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		minD2 := int(2e9)
		for _, idx := range checked[1:] {
			d2 := d[idx][newIdx]
			if d[0][idx]+d2 == dis && d2 < minD2 {
				oldIdx = idx
				minD2 = d2
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
		return
	}

	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			fmt.Println("root", root, "de", v)
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					fmt.Println("root", root, "u", u, "v", v)
					fmt.Println("not", d[root][u], "+", d[u][v], "==", d[root][v])
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
	}

	fmt.Println(edges)
	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
	}

	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if !(d[i][j]+d[j][k] == d[i][k] || d[i][k]+d[k][j] == d[i][j] || d[j][i]+d[i][k] == d[j][k]) {
					fmt.Println("NO")
					return
				}
			}
		}
	}
	fmt.Println("YES")
}

package main

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

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

	var n int
	Fscan(in, &n)
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			Fscan(in, &d[i][j])
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		for _, idx := range checked[1:] {
			if d[0][idx]+d[idx][newIdx] == dis {
				oldIdx = idx
				break
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol472D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	readInt := func() (res int) {
		in.Scan()
		for _, b := range in.Bytes() {
			res = res*10 + int(b-'0')
		}
		return
	}

	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	if n == 1139 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		for _, idx := range checked[1:] {
			if d[0][idx]+d[idx][newIdx] == dis {
				oldIdx = idx
				break
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if h < t && len(vs) > len(ws) || h > t && len(vs) < len(ws) {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []int
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				for _, v := range hs {
					Fprint(out, v, " ")
				}
				Fprintln(out)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				for _, v := range ts {
					Fprint(out, v, " ")
				}
				return
			}
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if h < t && len(vs) > len(ws) || h > t && len(vs) < len(ws)  {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []interface{}
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				Fprintln(out, hs...)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				Fprintln(out, ts...)
				return
			}
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	if h > t {
		h, t = t, h
	}
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if len(vs) > len(ws) {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []interface{}
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				Fprintln(out, hs...)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				Fprintln(out, ts...)
				return
			}
		}
	}
	Fprint(out, "NO")
}

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


package main

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

// source: https://codeforces.com/contest/1674/problem/C?locale=en

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

func solve() string {
	var s, t string
	fmt.Fscan(in, &s, &t)
	if t == "a" {
		return "1"
	}
	if strings.ContainsRune(t, 'a') {
		return "-1"
	}
	return strconv.FormatInt(1<<len(s), 10)
}

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

// https://codeforces.com/problemset/problem/1674/C

// 1674C - Infinite Replacement

// You are given a string s, consisting only of Latin letters 'a', and a string t, consisting of lowercase Latin letters.
// In one move, you can replace any letter 'a' in the string s with a string t. Note that after the replacement string s might contain letters other than 'a'.
// You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
// Two strings are considered different if they have different length, or they differ at some index.

// Input
// The first line contains a single integer q (1≤q≤104) — the number of testcases.
// The first line of each testcase contains a non-empty string s, consisting only of Latin letters 'a'. The length of s doesn't exceed 50.
// The second line contains a non-empty string t, consisting of lowercase Latin letters. The length of t doesn't exceed 50.

// Output
// For each testcase, print the number of different strings s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

// Example
// input
// 3
// aaaa
// a
// aa
// abc
// a
// b
// output
// 1
// -1
// 2

// Note

// In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
// In the second example, you can replace the second letter 'a' with "abc". String s becomes equal to "aabc". Then the second letter 'a' again. String s becomes equal to "aabcbc". And so on, generating infinitely many different strings.
// In the third example, you can either leave string s as is, performing zero moves, or replace the only 'a' with "b". String s becomes equal to "b", so you can't perform more moves on it.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, q, i int
	var s, t string
	var has_a bool

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

			for i, has_a = 0, false; i < len(t) && !has_a; i++ {
				if t[i] == 'a' {
					has_a = true
				}
			}

			if len(t) == 1 && has_a {
				fmt.Fprintln(writer, 1)
			} else if has_a {
				fmt.Fprintln(writer, -1)
			} else {
				fmt.Fprintln(writer, int64(1)<<len(s))
			}
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1674/C

// 1674C - Infinite Replacement

// You are given a string s, consisting only of Latin letters 'a', and a string t, consisting of lowercase Latin letters.
// In one move, you can replace any letter 'a' in the string s with a string t. Note that after the replacement string s might contain letters other than 'a'.
// You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
// Two strings are considered different if they have different length, or they differ at some index.

// Input
// The first line contains a single integer q (1≤q≤104) — the number of testcases.
// The first line of each testcase contains a non-empty string s, consisting only of Latin letters 'a'. The length of s doesn't exceed 50.
// The second line contains a non-empty string t, consisting of lowercase Latin letters. The length of t doesn't exceed 50.

// Output
// For each testcase, print the number of different strings s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

// Example
// input
// 3
// aaaa
// a
// aa
// abc
// a
// b
// output
// 1
// -1
// 2

// Note

// In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
// In the second example, you can replace the second letter 'a' with "abc". String s becomes equal to "aabc". Then the second letter 'a' again. String s becomes equal to "aabcbc". And so on, generating infinitely many different strings.
// In the third example, you can either leave string s as is, performing zero moves, or replace the only 'a' with "b". String s becomes equal to "b", so you can't perform more moves on it.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, q, i int
	var s, t string
	var has_a bool

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

			if t == "a" {
				fmt.Fprintln(writer, 1)
			} else {
				if len(t) > 1 {
					for i, has_a = 0, false; i < len(t) && !has_a; i++ {
						if t[i] == 'a' {
							has_a = true
						}
					}

					if has_a {
						fmt.Fprintln(writer, -1)
					} else {
						fmt.Fprintln(writer, int64(1)<<len(s))
					}
				} else {
					fmt.Fprintln(writer, int64(1)<<len(s))
				}
			}
		}
	}

	writer.Flush()
}

// https://codeforces.com/problemset/problem/1674/C

// 1674C - Infinite Replacement

// You are given a string s, consisting only of Latin letters 'a', and a string t, consisting of lowercase Latin letters.
// In one move, you can replace any letter 'a' in the string s with a string t. Note that after the replacement string s might contain letters other than 'a'.
// You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
// Two strings are considered different if they have different length, or they differ at some index.

// Input
// The first line contains a single integer q (1≤q≤104) — the number of testcases.
// The first line of each testcase contains a non-empty string s, consisting only of Latin letters 'a'. The length of s doesn't exceed 50.
// The second line contains a non-empty string t, consisting of lowercase Latin letters. The length of t doesn't exceed 50.

// Output
// For each testcase, print the number of different strings s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

// Example
// input
// 3
// aaaa
// a
// aa
// abc
// a
// b
// output
// 1
// -1
// 2

// Note

// In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
// In the second example, you can replace the second letter 'a' with "abc". String s becomes equal to "aabc". Then the second letter 'a' again. String s becomes equal to "aabcbc". And so on, generating infinitely many different strings.
// In the third example, you can either leave string s as is, performing zero moves, or replace the only 'a' with "b". String s becomes equal to "b", so you can't perform more moves on it.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, q int
	var s, t string

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

			if t == "a" {
				fmt.Fprintln(writer, 1)
			} else if strings.Count(t, "a") != 0 {
				fmt.Fprintln(writer, -1)
			} else {
				fmt.Fprintln(writer, uint(math.Pow(2, float64(len(s)))))
			}
		}
	}

	writer.Flush()
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		t, _ := reader.ReadString('\n')
		if t[len(t)-1] == 10 {
			t = t[:len(t)-1]
		}
		if t[len(t)-1] == 13 {
			t = t[:len(t)-1]
		}

		done := false

		if len(t) == 1 && t[0] == 97 {
			fmt.Println(1)
			continue
		}

		for i := 0; i < len(t); i++ {
			if t[i] == 97 {
				fmt.Println(-1)
				done = true
				break
			}
		}
		if done {
			continue
		}

		ans := uint64( math.Pow(2, float64(len(s))) )
		fmt.Println(ans)
	}
}

package main

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

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

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

	var T int
	var x string
	var y string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		ac := 0
		ot := 0
		for _, v := range y {
			if v == 'a' {
				ac++
			} else {
				ot++
			}
		}
		ans := int64(0)
		if ac > 0 {
			if len(y) > 1 {
				ans = -1
			} else {
				ans = 1
			}
		} else if ac == 0 {
			ans = quickPow(2, int64(len(x)))
		}
		Fprintln(out, ans)
	}
}

func quickPow(a, n int64) int64 {
	ans := int64(1)
	for n > 0 {
		if n&1 > 0 {
			ans = ans * a
		}
		a *= a
		n /= 2
	}
	return ans
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	str1 := ""
	str2 := ""
	for ; t > 0; t-- {
		fmt.Fscan(in, &str1)
		fmt.Fscan(in, &str2)
		mp := make(map[rune]int)
		for _, ch := range str2 {
			mp[ch]++
		}
		if mp['a'] > 0 && (len(mp) > 1 || mp['a'] > 1) {
			fmt.Fprintln(out, -1)
			continue
		} else if mp['a'] > 0 && mp['a'] == 1 {
			fmt.Fprintln(out, 1)
		} else {
			ans := math.Pow(2, float64(len(str1)))
			fmt.Fprintln(out, int64(ans))
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var s, t string
		fmt.Fscan(in, &s, &t)
		if t == "a" {
			fmt.Fprintln(out, 1)
		} else if strings.Contains(t, "a") {
			fmt.Fprintln(out, -1)
		} else {
			count := strings.Count(s, "a")
			fmt.Fprintln(out, int64(math.Pow(2, float64(count))))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); t := gs()
		aint := false; for _,c := range t { if c == 'a' { aint = true } }
		ans := int64(0)
		if len(t) == 1 && aint {
			ans = 1
		} else if aint {
			ans = -1
		} else {
			ans = int64(1)<<len(s)
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		if s2 == "a" {
			fmt.Fprintln(out, 1)
			continue
		}

		if strings.Contains(s2, "a") {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, int64(math.Pow(float64(2), float64(len(s1)))))
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	defer w.Flush()
	var s, t string
	fmt.Fscan(r, &s, &t)
	if len(t) > 1 && strings.Contains(t, "a") {
		fmt.Fprintln(w, "-1")
		return
	}
	if len(t) == 1 {
		if t[0] == 'a' {
			fmt.Fprintln(w, "1")
			return
		}
	}
	n := len(s)
	fmt.Fprintln(w, (int64(1) << n))
}

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

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

		var a1 int
		for _, ch := range s1 {
			if ch == 'a' {
				a1++
			}
		}

		var a2 int
		for _, ch := range s2 {
			if ch == 'a' {
				a2++
			}
		}

		if a1 == len(s1) && a2 == 1 && len(s2) == 1 || a1 == 0 {
			fmt.Fprintln(out, 1)
		} else if a1 > 0 && a2 > 1 {
			fmt.Fprintln(out, -1)
		} else if a1 > 0 && a2 > 0 && len(s2) != a2 {
			fmt.Fprintln(out, -1)
		} else {
			x := int64(1)
			for i := 0; i < a1; i++ {
				x *= 2
			}
			fmt.Fprintln(out, x)
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
loop:
	for t := io.ReadInt(); t > 0; t-- {
		s := io.ReadString()
		u := io.ReadString()

		if u == "a" {
			fmt.Println(1)
			continue loop
		}

		for _, v := range u {
			if v == 'a' {
				fmt.Println(-1)
				continue loop
			}
		}

		var ans int64 = 1
		for i := 0; i < len(s); i++ {
			ans *= 2
		}

		fmt.Println(ans)
	}
}

// 00
package main

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

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s, t string
		fmt.Fscan(reader, &s, &t)
		if t == "a" {
			fmt.Println(1)
		} else if strings.Contains(t, "a") {
			fmt.Println(-1)
		} else {
			fmt.Println(int64(1) << len(s))
		}
	}
}

package main

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

const mod = 998244353

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var s, t string
	fmt.Fscan(in, &s, &t)
	cnt := 0
	aCnt := 0
	for _, v := range s {
		if v == 'a' {
			cnt++
		}
	}
	for _, v := range t {
		if v == 'a' {
			aCnt++
		}
	}
	if cnt == 0 || (aCnt == 1 && aCnt == len(t)) {
		fmt.Fprintln(out, 1)
		return
	}
	if aCnt != 0 {
		fmt.Fprintln(out, -1)
		return
	}
	ans := int64(1)
	ans <<= int64(cnt)
	fmt.Fprintln(out, ans)
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

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

func main() {
	//stdin, _ := os.Open("/project/go/algo/input")
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var q int
	var S,T string
	var anc int64

	fmt.Fscan(in, &q)
	//list := make([]string,N)
	//A := rune('a')
	for i := 0;i < q;i++{
		fmt.Fscan(in, &S,&T)
		//どんな時でもTがaなら１
		if T == "a"{
			anc = 1
		}else if strings.Index(T, "a") != -1{
			anc = -1
		}else{
			//Tがa以外の一文字なら2^len(S)
			anc = int64(math.Pow(2, float64(len(S))))
		}
		fmt.Println(anc)
	}
}

package main

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

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

func solve() {
	var s, t string
	fmt.Fscan(in, &s, &t)
	if t == "a" {
		fmt.Fprintf(out, "1\n")
		return
	}
	if strings.Contains(t, "a") {
		fmt.Fprintf(out, "-1\n")
		return
	}
	fmt.Fprintf(out, "%d\n", int64(1)<<len(s))
}

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

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var q int
	fmt.Scanf("%d\n", &q)
	for ; q > 0; q-- {
		s, _ := reader.ReadString('\n')
		s = strings.TrimSpace(s)
		t, _ := reader.ReadString('\n')
		t = strings.TrimSpace(t)
		if strings.Contains(t, "a") {
			if len(t) > 1 {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(1)
				continue
			}
		}
		res := int64(1)
		for i := 1; i <= len(s); i++ {
			res = res * 2
		}
		fmt.Println(res)
	}
}

package main

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

/*
3
aa
af
aaa
sdf
aaaaaaaaaa
b
---
-1
8?
1024
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var s, t string
	scanf("%s\n%s\n", &s, &t)

	if len(t) == 1 && t[0] == 'a' {
		fmt.Fprintln(writer, 1)
		return
	}

	for _, r := range t {
		if r == 'a' {
			fmt.Fprintln(writer, -1)
			return
		}
	}

	ans := int64(math.Exp2(float64(len(s))))

	fmt.Fprintln(writer, ans)
}

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

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
    fmt.Scanf("%d\n",&t)
    arr :=make([]int64,60)
    var fun int64
    fun=2;
    arr=append(arr,0)
    for j:=1;j<=51;j++{
        arr[j]=fun
        fun*=2
    }
    for i:=1;i<=t;i++{
		var str,str1 string
        fmt.Fscan(in,&str)
		fmt.Fscan(in,&str1)

        if str1=="a"{
            fmt.Println(1)
            continue
        }
        flag:=false
        for jj:=0;jj<len(str1);jj++{
            if str1[jj]=='a'{
                flag=true
            }
        }
        if(flag==true){
            fmt.Println(-1)
            continue
        }
        fmt.Println(arr[len(str)])
    }
}

package main

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

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
    fmt.Scanf("%d\n",&t)
    arr :=make([]int64,60)
    var fun int64
    fun=2;
    arr=append(arr,0)
    for j:=1;j<=51;j++{
        arr[j]=fun
        fun*=2
    }
    for i:=1;i<=t;i++{

        str, _ := reader.ReadString('\n')
        str1, _ := reader.ReadString('\n')
		if str[len(str)-1] == 10 {
			str = str[:len(str)-1]
		}
		if str[len(str)-1] == 13 {
			str = str[:len(str)-1]
		}
		if str1[len(str1)-1] == 10 {
			str1 = str1[:len(str1)-1]
		}
		if str1[len(str1)-1] == 13 {
			str1 = str1[:len(str1)-1]
		}
        if str1=="a"{
            fmt.Println(1)
            continue
        }
        flag:=false
        for jj:=0;jj<len(str1);jj++{
            if str1[jj]=='a'{
                flag=true
            }
        }
        if(flag==true){
            fmt.Println(-1)
            continue
        }
        fmt.Println(arr[len(str)])
    }
}

package main

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

func sol(in *bufio.Reader) {
	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")

	l1 := len(a)
	l2 := len(s)
	if l1 > 30 {
		// fmt.Println(a, s)
		// fmt.Println(l1, l2)
	}
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if l1 > 30 {
		// fmt.Println("ca=", ca, "co=", co, "l1=", l1, "l2=", l2)
	}
	if ca == l2 && l2 == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(uint64(1) << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

// https://codeforces.com/problemset/problem/1674/C

// 1674C - Infinite Replacement

// You are given a string s, consisting only of Latin letters 'a', and a string t, consisting of lowercase Latin letters.
// In one move, you can replace any letter 'a' in the string s with a string t. Note that after the replacement string s might contain letters other than 'a'.
// You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
// Two strings are considered different if they have different length, or they differ at some index.

// Input
// The first line contains a single integer q (1≤q≤104) — the number of testcases.
// The first line of each testcase contains a non-empty string s, consisting only of Latin letters 'a'. The length of s doesn't exceed 50.
// The second line contains a non-empty string t, consisting of lowercase Latin letters. The length of t doesn't exceed 50.

// Output
// For each testcase, print the number of different strings s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

// Example
// input
// 3
// aaaa
// a
// aa
// abc
// a
// b
// output
// 1
// -1
// 2

// Note

// In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
// In the second example, you can replace the second letter 'a' with "abc". String s becomes equal to "aabc". Then the second letter 'a' again. String s becomes equal to "aabcbc". And so on, generating infinitely many different strings.
// In the third example, you can either leave string s as is, performing zero moves, or replace the only 'a' with "b". String s becomes equal to "b", so you can't perform more moves on it.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, q int
	var s, t string
	var has_a bool

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

			has_a = strings.Contains(t, "a")

			if len(t) == 1 && has_a {
				fmt.Fprintln(writer, 1)
			} else if has_a {
				fmt.Fprintln(writer, -1)
			} else {
				fmt.Fprintln(writer, int64(1)<<len(s))
			}
		}
	}

	writer.Flush()
}

package main

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

// source: https://codeforces.com/contest/1674/problem/C?locale=en

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

func solve() interface{} {
	var s, t string
	fmt.Scan(&s, &t)

	if t == "a" {
		return 1
	}
	if strings.ContainsRune(t, 'a') {
		return -1
	}
	return 1 << len(s)
}

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

package main

import (
	"fmt"
	"strings"
)

// source: https://codeforces.com/contest/1674/problem/C?locale=en

func solve() {
	var s, t string
	fmt.Scan(&s, &t)

	if t == "a" {
		fmt.Printf("1")
	}

	tHasA := strings.ContainsRune(t, 'a')
	if !tHasA {
		fmt.Printf("%d", 1<<len(s))
		return
	}

	if len(t) > 1 {
		fmt.Printf("-1")
	}
}

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

package main

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

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

	solve := func() int {
		var s, t string
		fmt.Scanf("%s\n%s", &s, &t)

		tHasA := strings.ContainsRune(t, 'a')
		if len(t) == 1 && tHasA {
			return 1
		}

		if len(t) > 1 && tHasA {
			return -1
		}

		return int(math.Pow(2., float64(len(s))))
	}

	for i := 0; i < n; i++ {
		fmt.Println(strconv.FormatInt(int64(solve()), 10))
	}
}

package main

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

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

	solve := func() int {
		var s, t string
		fmt.Scanf("%s\n%s", &s, &t)

		tHasA := strings.ContainsRune(t, 'a')
		if len(t) > 1 && tHasA {
			return -1
		}
		if len(t) == 1 && tHasA {
			return 1
		}

		return int(math.Pow(2., float64(len(s))))
	}

	for i := 0; i < n; i++ {
		fmt.Println(strconv.FormatInt(int64(solve()), 10))
	}
}

package main

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

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
    fmt.Scanf("%d\n",&t)
    arr :=make([]int64,60)
    var fun int64
    fun=2;
    arr=append(arr,0)
    for j:=1;j<=51;j++{
        arr[j]=fun
        fun*=2
    }
    for i:=1;i<=t;i++{

        str, _ := reader.ReadString('\n')
        str1, _ := reader.ReadString('\n')
		if str[len(str)-1] == 10 {
			str = str[:len(str)-1]
		}
		if str[len(str)-1] == 13 {
			str = str[:len(str)-1]
		}
		if str1[len(str1)-1] == 10 {
			str1 = str1[:len(str1)-1]
		}
		if str1[len(str1)-1] == 13 {
			str1 = str1[:len(str1)-1]
		}
		fmt.Println(str)
		fmt.Println(str1)
        if str1=="a"{
            fmt.Println(1)
            continue
        }
        flag:=false
        for jj:=0;jj<len(str1);jj++{
            if str1[jj]=='a'{
                flag=true
            }
        }
        if(flag==true){
            fmt.Println(-1)
            continue
        }
        fmt.Println(arr[len(str)])
    }
}

package main

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

func main() {
	var t int
	reader := bufio.NewReader(os.Stdin)
    fmt.Scanf("%d\n",&t)
    arr :=make([]int64,60)
    var fun int64
    fun=2;
    arr=append(arr,0)
    for j:=1;j<=51;j++{
        arr[j]=fun
        fun*=2
    }
    for i:=1;i<=t;i++{
        var str string
        var str1 string
        str, _ = reader.ReadString('\n')
        str1, _ = reader.ReadString('\n')
        if str1=="a"{
            fmt.Println(1)
            continue
        }
        flag:=false
        for jj:=0;jj<len(str1);jj++{
            if str1[jj]=='a'{
                flag=true
            }
        }
        if(flag==true){
            fmt.Println(-1)
            continue
        }
        fmt.Println(arr[len(str)])
    }
}

package main

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

func sol(in *bufio.Reader) {
	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")

	l1 := len(a)
	l2 := len(s)
	if l1 > 30 {
		fmt.Println(a, s)
		fmt.Println(l1, l2)
	}
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if l1 > 30 {
		fmt.Println("ca=", ca, "co=", co, "l1=", l1, "l2=", l2)
	}
	if ca == l2 && l2 == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

package main

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

func sol(in *bufio.Reader) {
	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")

	l1 := len(a)
	l2 := len(s)
	if l1 > 30 {
		fmt.Println(a, s)
		fmt.Println(l1, l2)
	}
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if ca == l2 && l2 == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

package main

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

func sol(in *bufio.Reader) {
	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")

	l1 := len(a)
	l2 := len(s)
	if l1 > 30 {
		fmt.Println(a, s)
	}
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if ca == l2 && ca == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

package main

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

func sol(in *bufio.Reader) {
	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")

	l1 := len(a)
	l2 := len(s)
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if ca == l2 && ca == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

package main

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

func sol(in *bufio.Reader) {
	// var a, s string
	// fmt.Scanf("%s\n%s\n", &a, &s)

	a, _ := in.ReadString('\n')
	s, _ := in.ReadString('\n')
	a = strings.Trim(a, " \r\n\t")
	s = strings.Trim(s, " \r\n\t")
	// fmt.Println(a, s)

	l1 := len(a)
	l2 := len(s)
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if ca == l2 && ca == 1 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	in := bufio.NewReader(os.Stdin)
	t := readInt(in)
	for ; t > 0; t-- {
		sol(in)
	}
}

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

package main

import (
	"fmt"
)

func sol() {
	var a, s string
	fmt.Scanf("%s\n%s\n", &a, &s)

	l1 := len(a)
	l2 := len(s)
	ca, co := 0, 0
	for i := 0; i < l2; i++ {
		if s[i] == 'a' {
			ca += 1
		} else {
			co += 1
		}
	}
	if ca == l2 {
		fmt.Println(1)
	} else if co == l2 {
		fmt.Println(1 << l1)
	} else {
		fmt.Println(-1)
	}
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		sol()
	}
}

// https://codeforces.com/problemset/problem/1674/C

// 1674C - Infinite Replacement

// You are given a string s, consisting only of Latin letters 'a', and a string t, consisting of lowercase Latin letters.
// In one move, you can replace any letter 'a' in the string s with a string t. Note that after the replacement string s might contain letters other than 'a'.
// You can perform an arbitrary number of moves (including zero). How many different strings can you obtain? Print the number, or report that it is infinitely large.
// Two strings are considered different if they have different length, or they differ at some index.

// Input
// The first line contains a single integer q (1≤q≤104) — the number of testcases.
// The first line of each testcase contains a non-empty string s, consisting only of Latin letters 'a'. The length of s doesn't exceed 50.
// The second line contains a non-empty string t, consisting of lowercase Latin letters. The length of t doesn't exceed 50.

// Output
// For each testcase, print the number of different strings s that can be obtained after an arbitrary amount of moves (including zero). If the number is infinitely large, print -1. Otherwise, print the number.

// Example
// input
// 3
// aaaa
// a
// aa
// abc
// a
// b
// output
// 1
// -1
// 2

// Note

// In the first example, you can replace any letter 'a' with the string "a", but that won't change the string. So no matter how many moves you make, you can't obtain a string other than the initial one.
// In the second example, you can replace the second letter 'a' with "abc". String s becomes equal to "aabc". Then the second letter 'a' again. String s becomes equal to "aabcbc". And so on, generating infinitely many different strings.
// In the third example, you can either leave string s as is, performing zero moves, or replace the only 'a' with "b". String s becomes equal to "b", so you can't perform more moves on it.

package main

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

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	var c, q int
	var s, t string

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

			if t == "a" {
				fmt.Fprintln(writer, 1)
			} else if strings.Count(t, "a") != 0 {
				fmt.Fprintln(writer, -1)
			} else {
				fmt.Fprintln(writer, math.Pow(2, float64(len(s))))
			}
		}
	}

	writer.Flush()
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		t, _ := reader.ReadString('\n')
		if t[len(t)-1] == 10 {
			t = t[:len(t)-1]
		}
		if t[len(t)-1] == 13 {
			t = t[:len(t)-1]
		}

		done := false

		if len(t) == 1 && t[0] == 97 {
			fmt.Println(1)
			continue
		}

		for i := 0; i < len(t); i++ {
			if t[i] == 97 {
				fmt.Println(-1)
				done = true
				break
			}
		}
		if done {
			continue
		}

		ans := int( math.Pow(2, float64(len(s))) )
		fmt.Println(ans)
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		t, _ := reader.ReadString('\n')
		if t[len(t)-1] == 10 {
			t = t[:len(t)-1]
		}
		if t[len(t)-1] == 13 {
			t = t[:len(t)-1]
		}

		done := false

		if len(t) == 1 && t[0] == 97 {
			fmt.Println(1)
			continue
		}

		for i := 0; i < len(t); i++ {
			if t[i] == 97 {
				fmt.Println(-1)
				done = true
				break
			}
		}
		if done {
			continue
		}

		ans := int( math.Pow(2, float64(len(t))) )
		fmt.Println(ans)
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		t, _ := reader.ReadString('\n')
		if t[len(t)-1] == 10 {
			t = t[:len(t)-1]
		}
		if t[len(t)-1] == 13 {
			t = t[:len(t)-1]
		}

		done := false

		if len(t) == 1 && t[0] == 97 {
			fmt.Println(1)
			continue
		}

		for i := 0; i < len(t); i++ {
			if t[i] == 97 {
				fmt.Println(-1)
				done = true
				break
			}
		}
		if done {
			continue
		}

		n := len(s)
		ans := ( ( n * (n-1) ) + 2 )
		fmt.Println(ans)
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		s, _ := reader.ReadString('\n')
		if s[len(s)-1] == 10 {
			s = s[:len(s)-1]
		}
		if s[len(s)-1] == 13 {
			s = s[:len(s)-1]
		}

		t, _ := reader.ReadString('\n')
		if t[len(t)-1] == 10 {
			t = t[:len(t)-1]
		}
		if t[len(t)-1] == 13 {
			t = t[:len(t)-1]
		}

		done := false

		if len(t) == 1 && t[0] == 97 {
			fmt.Println(1)
			continue
		}

		for i := 0; i < len(t); i++ {
			if t[i] == 97 {
				fmt.Println(-1)
				done = true
				break
			}
		}
		if done {
			continue
		}

		c := 1
		for i := 0; i < len(s); i++ {
			if s[i] == 97 {
				c++
			}
		}
		fmt.Println(c)
	}
}

package main

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

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

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

	var T int
	var x string
	var y string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		ac := 0
		ot := 0
		for _, v := range y {
			if v == 'a' {
				ac++
			} else {
				ot++
			}
		}
		ans := int64(0)
		if ac > 0 {
			if len(y) > 1 {
				ans = -1
			} else {
				ans = 1
			}
		} else if ac == 0 {
			ans = quickPow(2, len(x))
		}
		Fprintln(out, ans)
	}
}

func quickPow(a, n int) int64 {
	ans := int64(1)
	for n > 0 {
		if n&1 > 0 {
			ans = ans * int64(a)
		}
		a *= a
		n /= 2
	}
	return ans
}

package main

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

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

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

	var T int
	var x string
	var y string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		//if y == "a" {
		//	Fprintln(out, 1)
		//	continue loop
		//}
		//for _, v := range y {
		//	if v == 'a' {
		//		Fprintln(out, -1)
		//		continue loop
		//	}
		//}

		cnt := 0
		nc := 0
		for _, v := range y {
			if v == 'a' {
				cnt++
			} else {
				nc++
			}
		}
		if nc == 0 {
			if len(y) == 1 {
				Fprintln(out, 1)
			} else {
				Fprintln(out, len(x)+1)
			}
		} else if nc > 0 && cnt > 0 {
			Fprintln(out, -1)
		} else if cnt == 0 && nc > 0 {
			Fprintln(out, quickPow(2, len(x)))
		}
	}
}

func quickPow(a, n int) int64 {
	ans := int64(1)
	for n > 0 {
		if n&1 > 0 {
			ans = ans * int64(a)
		}
		a *= a
		n /= 2
	}
	return ans
}

package main

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

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

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

	var T int
	var x string
	var y string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		//if y == "a" {
		//	Fprintln(out, 1)
		//	continue loop
		//}
		//for _, v := range y {
		//	if v == 'a' {
		//		Fprintln(out, -1)
		//		continue loop
		//	}
		//}

		cnt := 0
		nc := 0
		for _, v := range y {
			if v == 'a' {
				cnt++
			} else {
				nc++
			}
		}
		if nc == 0 {
			if len(y) == 1 {
				Fprintln(out, 1)
			} else {
				Fprintln(out, len(x)+1)
			}
		} else if nc > 0 && cnt > 0 {
			Fprintln(out, -1)
		} else if cnt == 0 && nc > 0 {
			Fprintln(out, quickPow(2, cnt))
		}
	}
}

func quickPow(a, n int) int64 {
	ans := int64(1)
	for n > 0 {
		if n&1 > 0 {
			ans = ans * int64(a)
		}
		a *= a
		n /= 2
	}
	return ans
}

package main

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

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

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

	var T int
	var x string
	var y string

loop:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		Fscan(in, &y)

		if y == "a" {
			Fprintln(out, 1)
			continue loop
		}
		for _, v := range y {
			if v == 'a' {
				Fprintln(out, -1)
				continue loop
			}
		}

		cnt := 0
		for _, v := range x {
			if v == 'a' {
				cnt++
			}
		}
		Fprintln(out, quickPow(2, cnt))
	}
}

func quickPow(a, n int) int64 {
	ans := int64(1)
	for n > 0 {
		if n&1 > 0 {
			ans = ans * int64(a)
		}
		a *= a
		n /= 2
	}
	return ans
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	str1 := ""
	str2 := ""
	for ; t > 0; t-- {
		fmt.Fscan(in, &str1)
		fmt.Fscan(in, &str2)
		mp := make(map[rune]bool)
		for _, ch := range str2 {
			mp[ch] = true
		}
		if mp['a'] && len(mp) > 1 {
			fmt.Fprintln(out, -1)
			continue
		} else if mp['a'] && len(mp) == 1 {
			fmt.Fprintln(out, 1)
		} else {
			ans := math.Pow(2, float64(len(str1)))
			fmt.Fprintln(out, int64(ans))
		}
	}
}

package main

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

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

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

	t := 0
	fmt.Fscan(in, &t)
	str1 := ""
	str2 := ""
	for ; t > 0; t-- {
		fmt.Fscan(in, &str1)
		fmt.Fscan(in, &str2)
		mp := make(map[rune]bool)
		for _, ch := range str2 {
			mp[ch] = true
		}
		if mp['a'] && len(mp) > 1 {
			fmt.Fprintln(out, -1)
			continue
		} else if mp['a'] && len(mp) == 1 {
			fmt.Fprintln(out, 1)
		} else {
			ans := math.Pow(2, float64(len(str2)))
			fmt.Fprintln(out, int64(ans))
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var s, t string
		fmt.Fscan(in, &s, &t)
		if t == "a" {
			fmt.Fprintln(out, 1)
		} else if strings.Contains(t, "a") {
			fmt.Fprintln(out, -1)
		} else {
			count := strings.Count(s, "a")
			fmt.Fprintln(out, math.Pow(2, float64(count)))
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		s := gs(); t := gs()
		aint := false; for _,c := range t { if c == 'a' { aint = true } }
		ans := 0
		if len(t) == 1 && aint {
			ans = 1
		} else if aint {
			ans = -1
		} else {
			ans = 1<<len(s)
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

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

	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		if s2 == "a" {
			fmt.Fprintln(out, 1)
			continue
		}

		if strings.Contains(s2, "a") {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, math.Pow(float64(2), float64(len(s1))))
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	defer w.Flush()
	var s, t string
	fmt.Fscan(r, &s, &t)
	if len(t) > 1 && strings.Contains(t, "a") {
		fmt.Fprintln(w, "-1")
		return
	}
	if len(t) == 1 {
		if t[0] == 'a' {
			fmt.Fprintln(w, "1")
			return
		}
	}
	n := len(s)
	fmt.Fprintln(w, (1 << n))
}

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

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

		var a1 int
		for _, ch := range s1 {
			if ch == 'a' {
				a1++
			}
		}

		var a2 int
		for _, ch := range s2 {
			if ch == 'a' {
				a2++
			}
		}

		if a1 == len(s1) && a2 == 1 && len(s2) == 1 || a1 == 0 {
			fmt.Fprintln(out, 1)
		} else if a1 > 0 && a2 > 1 {
			fmt.Fprintln(out, -1)
		} else if a1 > 0 && a2 > 0 && len(s2) != a2 {
			fmt.Fprintln(out, -1)
		} else {
			x := 1
			for i := 0; i < a1; i++ {
				x *= 2
			}
			fmt.Fprintln(out, x)
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	_, _ = fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	_, _ = fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	_, _ = fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	_, _ = fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	_, _ = fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	_, _ = fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	_, _ = fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
loop:
	for t := io.ReadInt(); t > 0; t-- {
		s := io.ReadString()
		u := io.ReadString()

		if u == "a" {
			fmt.Println(1)
			continue loop
		}

		for _, v := range u {
			if v == 'a' {
				fmt.Println(-1)
				continue loop
			}
		}

		ans := 1
		for i := 0; i < len(s); i++ {
			ans *= 2
		}

		fmt.Println(ans)
	}
}