package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)
		bo := (n%2 == 0) || (m%2 == 0)
		for x := 0; x < n; x++ {
			for y := 0; y < m; y++ {
				if (x+y)%2 == 0 {
					fmt.Printf("B")
				} else {
					if bo {
						fmt.Printf("B")
						bo = false
					} else {
						fmt.Printf("W")
					}
				}
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Scan(&n, &m)
		if n*m%2 == 0 {
			for i := 0; i < n; i++ {
				if i == 0 {
					for j := 0; j < m; j++ {
						if j == 0 {
							fmt.Fprint(w, "B")
						} else if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				} else if i%2 == 0 {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				} else {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "B")
						} else {
							fmt.Fprint(w, "W")
						}
					}
				}
				fmt.Fprintln(w)
			}
		} else {
			for i := 0; i < n; i++ {
				if i%2 == 0 {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "B")
						} else {
							fmt.Fprint(w, "W")
						}
					}
				} else {
					for j := 0; j < m; j++ {
						if j%2 == 0 {
							fmt.Fprint(w, "W")
						} else {
							fmt.Fprint(w, "B")
						}
					}
				}
				fmt.Fprintln(w)
			}
		}
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

func main() {
    defer writer.Flush()
    t := reader.NextInt64()
    for ; t > 0; t-- {
        n, m := reader.NextInt64(), reader.NextInt64()
        isB := true
        colorBlackOnce := (n*m)&1==0
        for i := int64(0); i < n; i++ {
            for j := int64(0); j < m; j++ {
                if isB {
                    writer.Printf("B")
                } else if colorBlackOnce {
                    writer.Printf("B")
                    colorBlackOnce = false
                } else {
                    writer.Printf("W")
                }
                isB = !isB
                if j == m-1 {
                    writer.Printf("\n")
                }
            }
        }
    }
}

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if (i+j)%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
		    var flag bool = true
			for i := 1; i <= n; i++ {
			    for j := 1; j <= m; j++ {
			        if a[i][j]=='W' && flag {
			            flag = false
			            a[i][j] = 'B'
			        }
			    }
			}
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		exec()
	}
}

func exec() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	field := make([][]byte, n)
	for i := 0; i < n; i++ {
		field[i] = make([]byte, m)
		for j := 0; j < m-2; j++ {
			if j%2 == 0 {
				field[i][j] = 1
			}
		}
	}
	if m%2 == 0 {
		field[0][m-2] = 1
		for i := 0; i < n; i++ {
			field[i][m-1] = 1
		}
	} else {
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				field[i][m-1] = 1
			}
		}
		if n%2 == 0 {
			field[n-1][1] = 1
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 1 {
				printf("B")
				continue
			}
			printf("W")
		}
		printf("\n")
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	for t := 0; t < T; t++ {
		n, m := NextInt(), NextInt()

		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					fmt.Fprint(out, string('W'))
				} else {
					fmt.Fprint(out, string('B'))
				}
			}
			fmt.Fprintln(out)
		}
	}

}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scan(&n)
	for cas := 0; cas < n; cas++ {
		n, m := 0, 0
		fmt.Scan(&n, &m)
		work(n, m)
	}
}

func work(n, m int) {
	//输出第一行
	for r := 0; r < m; r++ {
		if r == 0 {
			fmt.Printf("W")
		} else {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")

	//输出剩下的n-1行
	for c := 1; c < n; c++ {
		for r := 0; r < m; r++ {
			fmt.Printf("B")
		}
		fmt.Printf("\n")
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'W')
				} else {
					fmt.Printf("%c", 'B')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

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

func main() {
	// var err error
	// os.Stdin, err = os.Open("")
	// noError(err)

	r := bufio.NewReaderSize(os.Stdin, 50*1024*1024)
	T := readInt(r)
	for t := 1; t <= T; t++ {
		N, M := readTwoInts(r)
		var black [2]int
		if (N * M) % 2 == 0 {
			if M == 1 {
				black = [2]int{0, M-1}
			} else if N == 1 {
				black = [2]int{N-1, 0}
			} else {
				black = [2]int{M % 2, M-1}
			}
		}
		for r := 0; r < N; r++ {
			off := 0
			if r % 2 == 1 {
				off = 1
			}
			for c := 0; c < M; c++ {
				if (off + c) % 2 == 0 || (r == black[0] && c == black[1]) {
					fmt.Print("B")
				} else {
					fmt.Print("W")
				}
			}
			if r != N-1 {
				fmt.Println()
			}
		}
		if t != T {
			fmt.Println()
		}
	}
}
/**
* Utils
*/
func readInt(r *bufio.Reader) int {
	return strToInt(readLine(r))
}

func readTwoInts(r *bufio.Reader) (int, int) {
	ints := readInts(r, 2)
	return ints[0], ints[1]
}

func readInts(r *bufio.Reader, n int) []int {
	result := make([]int, n)
	strs := strings.Split(readLine(r), " ")
	for i := 0; i < n; i++ {
		result[i] = strToInt(strs[i])
	}
	return result
}

func readLine(r *bufio.Reader) string {
	str, _, err := r.ReadLine()
	noError(err)
	return string(str)
}

func strToInt(s string) int {
	num, err := strconv.Atoi(s)
	noError(err)
	return num
}

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

// https://serhatgiydiren.github.io

package main

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

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

func solve(test_id int) {
 var n,m int
 fmt.Fscanf(reader, "%d %d\n", &n, &m)
 for i := 0 ; i < n ; i++ {
  for j := 0 ; j < m ; j++ {
   if ( i + j ) % 2 == 0 || ( ( n * m ) % 2 == 0 && i == 0 && j == 1 ) {
    fmt.Fprintf(writer,"B")
   } else {
    fmt.Fprintf(writer,"W")
   }
  }
  fmt.Fprintf(writer,"\n")
 }
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

import (
	"fmt"
)

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if i == 0 && j == 0 {
					fmt.Print("W")
				} else {
					fmt.Print("B")
				}
			}
			fmt.Println()
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		var n, m int
		fmt.Scan(&n)
		fmt.Scan(&m)
		var s2 = "B"
		var s1 = "W"
		for i := 1; i < m; i++ {
			s1 += "B"
			s2 += "B"
		}
		fmt.Println(s1)
		for i := 1; i < n; i++ {
			fmt.Println(s2)
		}
		t -= 1
	}
}

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if (i+j)%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
			a[n][m] = 'B'
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

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

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

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

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

const N = 105

var a [N][N]byte

func main() {
	defer writer.Flush()

	var t int
	scanf("%d", &t)
	for ; t > 0; t-- {
		var n, m int
		scanf("%d %d\n", &n, &m)
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if i+j%2 == 0 {
					a[i][j] = 'B'
				} else {
					a[i][j] = 'W'
				}
			}
		}
		if (n*m)%2 == 0 {
			a[n][m] = 'B'
		}
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				printf("%c", a[i][j])
			}
			printf("\n")
		}
	}
}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scanf("%d", &n)
	for cas := 0; cas < n; cas++ {
		n, m := 0, 0
		fmt.Scanf("%d %d", &n, &m)
		work(n, m)
	}
}

func work(n, m int) {
	//输出第一行
	for r := 0; r < m; r++ {
		if r == 0 {
			fmt.Printf("W")
		} else {
			fmt.Printf("B")
		}
	}
	fmt.Printf("\n")

	//输出剩下的n-1行
	for c := 1; c < n; c++ {
		for r := 0; r < m; r++ {
			fmt.Printf("B")
		}
		fmt.Printf("\n")
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'B')
				} else {
					fmt.Printf("%c", 'A')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

import (
	"fmt"
)

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

	for test := 0; test < testCount; test++ {
		var n, m int
		fmt.Scan(&n, &m)
		for i := 0; i < n; i++ {
			for k := 0; k < m; k++ {
				if i == 0 && k == 0 {
					fmt.Printf("%c", 'B')
				} else {
					fmt.Printf("%c", 'W')
				}
			}
			fmt.Printf("%c", '\n')
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scanf("%d %d\n", &n, &m)
		if n > 2 {
			for j := 0; j < n; j++ {
				for k := 0; k < m; k++ {
					if k == m-1 {
						if j == n-2 {
							fmt.Printf("B")
						} else {
							fmt.Printf("W")
						}
					} else {
						fmt.Printf("B")
					}
				}
				fmt.Println()
			}
		} else if m > 2 {
			for j := 0; j < n; j++ {
				for k := 0; k < m; k++ {
					if j == n-1 {
						if k == m-2 {
							fmt.Printf("B")
						} else {
							fmt.Printf("W")
						}
					} else {
						fmt.Printf("B")
					}
				}
				fmt.Println()
			}
		} else {
			fmt.Println("no solution")
		}
	}
}

package main

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

func main() {
	// var err error
	// os.Stdin, err = os.Open("")
	// noError(err)

	r := bufio.NewReaderSize(os.Stdin, 50*1024*1024)
	T := readInt(r)
	for t := 1; t <= T; t++ {
		N, M := readTwoInts(r)
		var black [2]int
		if (N * M) % 2 == 0 {
			if N == 1 {
				black = [2]int{0, M-1}
			} else if M == 1 {
				black = [2]int{N-1, 0}
			} else {
				black = [2]int{N-1, M-1}
			}
		}
		for r := 0; r < N; r++ {
			off := 0
			if r % 2 == 1 {
				off = 1
			}
			for c := 0; c < M; c++ {
				if (off + c) % 2 == 0 || (r == black[0] && c == black[1]) {
					fmt.Print("B")
				} else {
					fmt.Print("W")
				}
			}
			if r != N-1 {
				fmt.Println()
			}
		}
		if t != T {
			fmt.Println()
		}
	}
}
/**
* Utils
*/
func readInt(r *bufio.Reader) int {
	return strToInt(readLine(r))
}

func readTwoInts(r *bufio.Reader) (int, int) {
	ints := readInts(r, 2)
	return ints[0], ints[1]
}

func readInts(r *bufio.Reader, n int) []int {
	result := make([]int, n)
	strs := strings.Split(readLine(r), " ")
	for i := 0; i < n; i++ {
		result[i] = strToInt(strs[i])
	}
	return result
}

func readLine(r *bufio.Reader) string {
	str, _, err := r.ReadLine()
	noError(err)
	return string(str)
}

func strToInt(s string) int {
	num, err := strconv.Atoi(s)
	noError(err)
	return num
}

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

// https://serhatgiydiren.github.io

package main

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

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

func solve(test_id int) {
 var n,m int
 fmt.Fscanf(reader, "%d %d\n", &n, &m)
 for i := 0 ; i < n ; i++ {
  for j := 0 ; j < m ; j++ {
   if ( i + j ) % 2 == 0 || ( i == n - 1 && j == m - 1 ) {
    fmt.Fprintf(writer,"B")
   } else {
    fmt.Fprintf(writer,"W")
   }
  }
  fmt.Fprintf(writer,"\n")
 }
}

func solve_cases() {
 defer writer.Flush()
 t := 1
 fmt.Fscanf(reader, "%d\n", &t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}


package main

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

var reader io.Reader
var scanner *bufio.Scanner

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()

	a := make([]int, 32)
	f := make([]int64, 32)
	for t := 0; t < T; t++ {
		d, m := NextInt(), NextInt64()

		for i, x := 0, d; i < 31; i++ {
			a[i] = x & 1
			x >>= 1
			f[i] = 0
		}

		eq := true
		for i := 30; i >= 0; i-- {
			if eq && a[i] == 1 {
				f[i] = int64(d - (1 << uint32(i)) + 1)
				eq = false
			} else if eq && a[i] == 0 {
				f[i] = 0
			} else if !eq {
				f[i] = int64(1 << uint32(i))
			}
		}
		var total int64
		for i := 0; i < 31; i++ {
			res := f[i] % m
			for j := 0; j < i; j++ {
				res += ((f[i] % m) * (f[j] % m)) % m
				if res >= m {
					res -= m
				}
			}
			f[i] = res
			total += f[i]
			if total >= m {
				total %= m
			}
		}
		fmt.Fprintln(out, total)
	}

}

/*
URL:
https://codeforces.com/problemset/problem/1329/B
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	d, m int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		d, m = ReadInt64_2()

		solve()
	}
}

func solve() {
	PrintfDebug("d: %d\n", d)
	if m == 1 {
		fmt.Println(0)
		return
	}

	i := 0
	ans := int64(1)
	for 1<<uint(i+1) <= d {
		p := int64(1 << uint(i))
		ans *= (p + 1)
		PrintfDebug("kake: %d\n", p+1)
		ans %= m

		i++
	}
	mb := int64(1 << uint(i))
	ans *= (d - mb + 2)
	PrintfDebug("kake: %d\n", d-mb+2)
	PrintfDebug("\n")
	ans %= m
	fmt.Println(NegativeMod(ans-1, m))
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

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

	for t := 1; t <= tc; t++ {
		var d, m uint64
		fmt.Fscanf(r, "%d %d\n", &d, &m)

		dp := make([]uint64, 33)
		for i := 32; i >= 0; i-- {
			p := uint64(1) << uint64(i)
			if p > d {
				dp[i] = 0
			} else if p*2 > d {
				dp[i] = (d - p + 1) % m
			} else {
				dp[i] = (p*dp[i+1])%m + dp[i+1] + p
				dp[i] %= m
			}
		}

		fmt.Println(dp[0])
	}
}


package main

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

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

	var T, D int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &D)
		if 0 < D && D < 4 {
			Fprintln(out, "N")
			continue
		}
		d := float64(D)
		dt := math.Sqrt(d * (d - 4))
		Fprintf(out, "Y %.9f %.9f\n", (d+dt)/2, (d-dt)/2)
	}
}

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

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 50000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		diff := (float64(d)-mid)*mid - float64(d)
		if diff*diff > 1e-12 {
			fmt.Println("N")
			continue
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var test int
	var d float64
	var a, b, det float64
	fmt.Scan(&test)
	for i := 0; i < test; i++ {
		fmt.Scan(&d)
		det = math.Pow(d, 2) - (4 * d)
		if det >= 0 {
			a = (d + math.Pow(det, 0.5)) * 0.5
			if a == 0 {
				fmt.Println("Y 0.000000000 0.000000000")
			} else {
				b = d / a
				fmt.Printf("Y %.9f %.9f\n", a, b)
			}
		} else {
			fmt.Println("N")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	scanner := &Scanner{scanner: bufio.NewScanner(os.Stdin)}
	scanner.scanner.Split(bufio.ScanWords)
	return scanner
}

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %.10f %.10f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t, d := 0, 0
	fmt.Fscanf(in, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(in, "%d\n", &d)
		x1 := float64(d*d - 4*d)
		x2 := math.Sqrt(float64(x1))
		x3 := (-1.0*float64(d) + x2) / -2.0
		if x3 >= 0 {
			x4 := float64(d) - x3
			if x4 >= 0 {
				fmt.Fprintf(out, "Y %.9f %0.9f\n", math.Abs(x4), math.Abs(x3))
				continue
			}
		}
		x5 := (-1.0*float64(d) - x2) / -2.0
		if x5 >= 0 {
			x6 := float64(d) - x5
			if x6 >= 0 {
				fmt.Fprintf(out, "Y %.9f %0.9f\n", math.Abs(x6), math.Abs(x5))
				continue
			}
		}
		fmt.Fprintf(out, "N\n")

	}
	fmt.Fprintf(out, "\n")
	return
}

// Codeforces 1076 C Meme Problem train
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"math"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

var n int
var d []int
var a []float64
var b []float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	n, _, _, _, _ = readFive()
	d = make([]int, n)
	for i:=0; i<n; i++ {
		d[i],_,_,_,_ = readFive()
	}
}

func solve() {
	for i:=0; i<n; i++ {
		dd := float64(d[i])
		if dd <= 0.1 {
			fmt.Println("Y 0.0 0.0")
			continue
		}
		di := (dd*dd)/4.0 - dd
		if di < -0.000001 {
			fmt.Println("N")
			continue
		}
		di = math.Sqrt(di)
		a := dd/2.0 + di
		b := dd/2.0 - di
		fmt.Println("Y ", a, b)
	}
}

func printRes() {
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	scanner := &Scanner{scanner: bufio.NewScanner(os.Stdin)}
	scanner.scanner.Split(bufio.ScanWords)
	return scanner
}

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if ok {
			fmt.Printf("Y %f %f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	scanner := &Scanner{scanner: bufio.NewScanner(os.Stdin)}
	scanner.scanner.Split(bufio.ScanWords)
	return scanner
}

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %f %f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	scanner := &Scanner{scanner: bufio.NewScanner(os.Stdin)}
	scanner.scanner.Split(bufio.ScanWords)
	return scanner
}

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if ok {
			fmt.Printf("Y %.7f %.7f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

type Scanner struct {
	scanner *bufio.Scanner
}

func NewScanner() *Scanner {
	scanner := &Scanner{scanner: bufio.NewScanner(os.Stdin)}
	scanner.scanner.Split(bufio.ScanWords)
	return scanner
}

func (s *Scanner) Read() int {
	s.scanner.Scan()
	val, _ := strconv.Atoi(s.scanner.Text())
	return val
}

// a + b = d
// a  = d / b
/*
 d / b + b = d
 d + b**2 = d * b
 b ** 2 - d * b + d = 0
 b =  (d + sqrt(d**2 - 4 * d) ) / 2
 d > 4
*/

func solve(d float64) (bool, float64, float64) {
	if 0 < d && d < 4 {
		return false, 0, 0
	}
	b := (d + math.Sqrt(d*d-4*d)) / 2
	a := d - b
	if a >= 0 {
		return true, a, b
	}
	return false, 0, 0
}

func main() {
	scanner := NewScanner()
	t := scanner.Read()
	for i := 0; i < t; i++ {
		d := scanner.Read()
		ok, a, b := solve(float64(d))
		if a < b {
			a, b = b, a
		}
		if ok {
			fmt.Printf("Y %.7f %.7f\n", a, b)
		} else {
			fmt.Printf("N\n")
		}
	}
}

// Codeforces 1076 C Meme Problem train
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"math"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	delim := byte(' ')
	for i:=0; i<n; i++ {
		if i==(n-1) {
			delim = byte('\n')
		}
		s, err := in.ReadString(delim)
		s = strings.Trim(s, " \n\r")
		if err != nil {
			fmt.Println("read failure", err)
			panic(err)
		}
		aa,err := strconv.Atoi(s)
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[i] = aa
	}
	return a
}

var n int
var d []int
var a []float64
var b []float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	n, _, _, _, _ = readFive()
	d = make([]int, n)
	for i:=0; i<n; i++ {
		d[i],_,_,_,_ = readFive()
	}
}

func solve() {
	for i:=0; i<n; i++ {
		dd := float64(d[i])
		if dd <= 0.1 {
			fmt.Println("Y 0.0 0.0")
			continue
		} else if dd <= 2.1 {
			fmt.Println("N")
			continue
		}
		di := math.Sqrt((dd*dd)/4.0 - dd)
		a := dd/2.0 + di
		b := dd/2.0 - di
		fmt.Println("Y ", a, b)
	}
}

func printRes() {
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 50000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func scanNum() int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}
func main() {
	scanner.Split(bufio.ScanWords)
	n := scanNum()
	for i := 0; i < n; i++ {
		d := scanNum()
		if d == 0 {
			fmt.Println("Y 0.000000000 0.000000000")
			continue
		}
		if d == 1 {
			fmt.Println("N")
			continue
		}
		l, r, mid := 1.0, float64(d)/2, 1.0
		for c := 0; c < 1000; c++ {
			mid = (l + r) / 2
			if mid*(float64(d)-mid) < float64(d) {
				l = mid
			} else {
				r = mid
			}
		}
		fmt.Println("Y", float64(d)-mid, mid)
	}
}


package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		a := readInt()
		b := readInt()
		if b < a {
			a, b = b, a
		}
		var res int
		if 2 * a < b {
			res = b * b
		} else {
			res = (2 * a) * (2 * a)
		}
		fmt.Println(res)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	c := min(max(2*a, b), max(2*b, a))
	fmt.Println(c*c)
}

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
}

// You can edit this code!
// Click here and start typing.
package main

import "fmt"

// Max returns the larger of x or y.
func Max(x, y int) int {
    if x < y {
        return y
    }
    return x
}

// Min returns the smaller of x or y.
func Min(x, y int) int {
    if x > y {
        return y
    }
    return x
}

func main() {
	var t,a,b,ans int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a)
		fmt.Scan(&b)
		if a>b {
			var temp int
			temp = b
			b = a
			a = temp
		}
		ans = Max(a+a,b);
		fmt.Println(ans * ans)
	}

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Text()
	for scanner.Scan() {
		text := scanner.Text()
		num := strings.Split(text, " ")
		a, _ := strconv.Atoi(num[0])
		b, _ := strconv.Atoi(num[1])
		if a < b {
			a *= 2
		} else {
			b *= 2
		}
		if a > b {
			b = a
		} else {
			a = b
		}

		fmt.Println(a * b)
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		a,b := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(a,b))
	}
}

func sol(a,b int64) int64 {
	if(a==1 && b==1){
		return 4
	}else if(a==1){
		return b*b
	}else if(b==1){
		return a*a
	}else{
		x,y:=MnMx(a,b)
		if(y<=2*x){
		return 2*x*2*x
		}else{
			return y*y
		}
	}

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

package main
import(
	"fmt"
	"math"
)
func main()  {
	var test,a,b int
	fmt.Scan(&test)
	for i:=0;i<test;i++{
		fmt.Scan(&a)
		fmt.Scan(&b)
		c:=math.Min(float64(a),float64(b))
		d:=math.Max(float64(a),float64(b))
		if c*2>=d{
			fmt.Println(math.Pow(c*2,2))
		}else{
			fmt.Println(math.Pow(d,2))
		}

	}
}

/*
URL:
https://codeforces.com/contest/1360/problem/0
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	a, b int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		a, b = ReadInt2()
		solve(a, b)
	}
}

func solve(a, b int) {
	i := Max(2*a, b)
	j := Max(a, 2*b)
	k := Max(a, b, a+b)

	l := Min(i, j, k)
	fmt.Println(l * l)
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
  "fmt"
)

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

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

func main() {
  var t int
  fmt.Scan(&t)
  for i := 0 ; i < t; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    x := min(a, b)
    y := max(a, b)
    if x * 2 < y {
      fmt.Println(y * y)
    } else {
      fmt.Println(4 * x * x)
    }
  }
}

package main

import "fmt"

func main() {
	var t int
	var a int
	var b int
	var side int

	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d%d\n", &a, &b)
		if a > b {
			if b*2 > a {
				side = b * 2
			} else {
				side = a
			}
		}
		if a < b {
			if a*2 > b {
				side = a * 2
			} else {
				side = b
			}
		}
		if a == b {
			side = a * 2
		}
		fmt.Println(side*side)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scanln(&n)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		var a int
		var b int
		_, err := fmt.Scanf("%d %d\n", &a, &b)
		if err != nil {
			panic("Invalid input")
		}

		min := Min(a, b)
		max := Max(a, b)
		resA := Max(max, min*2)
		fmt.Println(resA * resA)
	}
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

package main

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

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

	var t, a,b int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a,&b)
		if a > b {
			a, b = b, a
		}
		if 2*a<=b{
			Fprintln(out, b*b)
		} else {
			Fprintln(out, 4*a*a)
		}
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		a, b := ScanInt(), ScanInt()
		ar1 := Mx((2*a), b) * Mx((2*a), b)
		ar2 := Mx(a, 2 * b) * Mx(a, 2 * b)
		P(Mn(ar1, ar2))
	}

}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"math"
	"sort"
)

func main()  {
	var test,a,b int
	fmt.Scan(&test)
	for i:=0;i<test;i++{
		fmt.Scan(&a,&b)
		c:=[]int{a,b}
		sort.Ints(c)
		fmt.Println(math.Pow(math.Max(float64(c[0]*2),float64(c[1])),2))
	}
}

package main

import (
	"fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,m int
		fmt.Scan(&n)
		fmt.Scan(&m)
		if  n>m {
		var t = n
		  n = m
		  m = t
		}
		if 2*n>m{
			var t = 2*n
		  n = m
		  m = t
		}
		fmt.Println(m*m)
	}
}

package main
import "fmt"
func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
func main(){
    var t, a, b int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&a, &b)
        if a > b {
            a, b = b, a
        }
        if (a+a)*b > (a+b)*b {
            fmt.Println(max(a+b, b) * max(a+b, b))
        } else {
            fmt.Println(max(a+a, b) * max(a+a, b))
        }
    }
}

package main
import (
    "fmt"
    "os"
    "bufio"
)
func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}
func main(){
    var t, a, b int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        fmt.Fscan(in, &a, &b)
        if a > b {
            a, b = b, a
        }
        if (a+a)*b > (a+b)*b {
            fmt.Println(max(a+b, b) * max(a+b, b))
        } else {
            fmt.Println(max(a+a, b) * max(a+a, b))
        }
    }
}

package main

import (
	"fmt"
)

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

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

func square(a int) int {
    return a * a
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		fmt.Println(min(square(max(2 * a, b)), square(max(2 * b, a))))
	}
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for tt := rd(); tt > 0; tt-- {
		a, b := rd(), rd()
		if a > b {
			a, b = b, a
		}
		ans := max(2*a, b)
		Fprintln(out, ans*ans)
	}
}

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 rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}

package main

import (
    "fmt"
    "math"
)

func Min(a, b, c float64) float64 {
    return math.Min(a, math.Min(b, c))
}

func main() {
  var t int
  var a, b float64

  fmt.Scan(&t)
  for ;t > 0; t-- {
      fmt.Scan(&a, &b)
      ans := Min(math.Max(2 * a, b), math.Max(a, 2 * b), a + b)
      fmt.Println(math.Pow(ans, 2))
  }
}

package main

import (
	"fmt"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var a, b, tmp int
		fmt.Scan(&a, &b)
		if a > b {
			tmp = a
			a = b
			b = tmp
		}
		s := 2*a
		if s < b {
			s = b
		}
		fmt.Println(s*s)
	}
}

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscanln(in, &t)
	for i := 0; i < t; i++ {
		a, b := 0, 0
		fmt.Fscanln(in, &a, &b)
		if a < b {
			a, b = b, a
		}
		ans := 2 * b
		if ans < a {
			ans = a
		}
		ans *= ans
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

package main

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

// https://codeforces.com/problemset/problem/1360/A
// A. Minimal Square
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Find the minimum area of a square land on which you can place two identical rectangular a×b

// houses. The sides of the houses should be parallel to the sides of the desired square land.

// Formally,

//     You are given two identical rectangles with side lengths a

// and b (1≤a,b≤100

//     ) — positive integers (you are given just the sizes, but not their positions).
//     Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.

// Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.
// The picture shows a square that contains red and green rectangles.
// Input

// The first line contains an integer t
// (1≤t≤10000) —the number of test cases in the input. Then t

// test cases follow.

// Each test case is a line containing two integers a
// , b (1≤a,b≤100

// ) — side lengths of the rectangles.
// Output

// Print t
// answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions a×b.

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

	var t int
	_, _ = fmt.Fscan(bufStdin, &t)

	for i := 0; i < t; i++ {
		var a, b int

		_, _ = fmt.Fscan(bufStdin, &a, &b)

		shorterSide, longerSide := intMin(a, b), intMax(a, b)

		squareSide := intMax(2*shorterSide, longerSide)
		area := squareSide * squareSide
		_, _ = fmt.Fprintln(bufStdout, area)
	}
}

func intMin(v1, v2 int) int {
	if v1 < v2 {
		return v1
	}
	return v2
}
func intMax(v1, v2 int) int {
	if v1 > v2 {
		return v1
	}
	return v2
}

package main

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

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}
func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		a, b = minmax(a, b)
		if 2*a > b {
			fmt.Fprintln(w, 4*a*a)
		} else {
			fmt.Fprintln(w, b*b)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

type numpair struct {
	a int
	b int
}

// https://codeforces.com/problemset/problem/1360/A
// комментарий к решению
func taskSolution(in []numpair) string {
	ans := make([]int, len(in))
	for i := 0; i < len(in); i += 1 {
		a, b := in[i].a, in[i].b
		if a > b {
			a, b = b, a
		}
		if 2*a > b {
			ans[i] = 4 * a * a
		} else {
			ans[i] = b * b
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

func main() {
	var t int
	if _, err := fmt.Scan(&t); err != nil {
		panic(err)
	}

	in := []numpair{}
	for i := 0; i < t; i += 1 {
		var a, b int
		if _, err := fmt.Scan(&a, &b); err != nil {
			panic(err)
		}
		in = append(in, numpair{a: a, b: b})
	}

	fmt.Println(taskSolution(in))
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		a, b := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(a,b))
	}
}

func sol(a, b int64) int64 {
	side := max(min(a,b)*2, max(a,b))
	return side * side
}

package main

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

func main() {
	var t, a, b int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b)
		min, max := minmax(a, b)
		_, max = minmax(min*2, max)
		fmt.Println(max * max)
	}
}

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

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		a, b := readTwoNums(reader)

		fmt.Println(solve(a, b))
	}
}

func solve(a, b int) int {
	if a > b {
		a, b = b, a
	}
	x := max(2*a, b)

	return x * x
}

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

package main

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		a, b := s.NextInt(), s.NextInt()
		res := 0
		x := max(a, 2*b)
		res = x * x

		y := max(b, 2*a)
		if res > y*y {
			res = y * y
		}

		fmt.Println(res)
	}
}

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

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

func (s *scanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *scanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	r1 := min(max(a+b, b), max(a+b, a))
	r2 := min(max(2*a, b), max(2*b, a))
	fmt.Println(min(r1, r2)*min(r1, r2))
}

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
}

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i/2 >= a*b && i/2 >= min(a, b)  {
			fmt.Println(i*i)
			return
		}
	}
}

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

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i/2 >= a*b && i/2 >= min(a, b)  {
			fmt.Println(int64(i)*int64(i))
			return
		}
	}
}

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

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)
	for i := 1; i < 1000000; i++ {
		if i*i >= 2*a*b && i >= 2*min(a, b)  {
			fmt.Println(i*i)
			return
		}
	}
}

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

package main

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

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		a,b := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(a,b))
	}
}

func sol(a,b int64) int64 {
	if(a==1 && b==1){
		return 4
	}else if(a==1){
		return b*b
	}else if(b==1){
		return a*a
	}else{
		x,_:=MnMx(a,b)
		return 2*x*2*x
	}

}

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

package main

import (
  "fmt"
)

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

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

func main() {
  var t int
  fmt.Scanf("%d", &t)
  for i := 0 ; i < t; i++ {
    var a, b int
    fmt.Scanf("%d%d", &a, &b)
    x := min(a, b)
    y := max(a, b)
    if x * 2 < y {
      fmt.Println(y * y)
    } else {
      fmt.Println(4 * x * x)
    }
  }
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		a := readInt()
		b := readInt()
		if b < a {
			a, b = b, a
		}
		var res int
		if a * a < b {
			res = b * b
		} else {
			res = (2 * a) * (2 * a)
		}
		fmt.Println(res)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}


package main

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

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

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

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

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

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

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

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

func sol(n, k int, xy [][2]int) int {
	points := make([]int, 2*n)
	for i := range points {
		points[i] = -1
	}
	for i := range xy {
		points[xy[i][0]] = xy[i][1]
		points[xy[i][1]] = xy[i][0]
	}
	// printf("%v\n", points)
	p1 := 0 // p1: first untaken position
	for p1 < len(points) && points[p1] != -1 {
		p1++
	}
	if p1 != len(points) {
		p2 := p1 + 1 // p2: opposite position
		off := 0
		target := n - k // (2n - 2k)/2
		for {
			if points[p2] == -1 {
				off++
				if off == target {
					break
				}
			}
			p2++
			if p2 == len(points) {
				p2 = 0
			}
		}
		for {
			points[p1] = p2
			points[p2] = p1
			refp1 := p1
			for points[p1] != -1 {
				p1++
				if p1 == len(points) {
					p1 = 0
				}
				if p1 == refp1 {
					break // this is very ugly
				}
			}
			if p1 == refp1 {
				break // this is very ugly
			}
			for points[p2] != -1 {
				p2++
				if p2 == len(points) {
					p2 = 0
				}
			}
		}
		// printf("%v\n", points)
	}
	ret := 0
	chords := [][2]int{}
	for i := range points {
		if points[i] == -1 {
			continue // avoid double counting
		}
		from, to := i, points[i]
		if points[points[i]] != i {
			panic("from != to")
		}
		points[points[i]] = -1
		points[i] = -1
		curr := [2]int{from, to}
		for _, isect := range chords {
			if intersect(isect, curr) {
				ret++
			}
		}
		chords = append(chords, curr)
    // printf("%v\n", chords)
	}
	return ret
}

func intersect(a, b [2]int) bool {
	if a[0] > a[1] {
		a[0], a[1] = a[1], a[0]
	}
	if b[0] > b[1] {
		b[0], b[1] = b[1], b[0]
	}
	if between(a[0], b[0], a[1]) && !between(a[0], b[1], a[1]) {
		return true
	}
	if between(a[0], b[1], a[1]) && !between(a[0], b[0], a[1]) {
		return true
	}
	if between(b[0], a[0], b[1]) && !between(b[0], a[1], b[1]) {
		return true
	}
	if between(b[0], a[1], b[0]) && !between(b[0], a[0], b[1]) {
		return true
	}
	return false
}

func between(a, b, c int) bool {
	return a < b && b < c
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func move(pos int, used []bool, steps int) int {
	for i := 0; i < steps; i += 1 {
		for used[pos] {
			pos = (pos + 1) % len(used)
		}
		if i+1 < steps {
			pos = (pos + 1) % len(used)
		}
	}
	return pos
}

func ordered(c []int) (int, int) {
	if c[0] < c[1] {
		return c[0], c[1]
	}
	return c[1], c[0]
}

func intersect(ca, cb []int) bool {
	la, ra := ordered(ca)
	lb, rb := ordered(cb)
	return (la <= lb && lb <= ra && ra <= rb) ||
		(lb <= la && la <= rb && rb <= ra)
}

func countPairs(cs [][]int) int {
	res := 0
	for i := 0; i < len(cs); i += 1 {
		for j := i + 1; j < len(cs); j += 1 {
			if intersect(cs[i], cs[j]) {
				res += 1
			}
		}
	}
	return res
}

func solve(cs [][]int, n int) int {
	if len(cs) < n {
		used := make([]bool, 2*n)
		for _, c := range cs {
			used[c[0]] = true
			used[c[1]] = true
		}

		k := len(cs)
		l := move(0, used, 2*(n-k)+1)
		r := move(0, used, n-k+1)

		for i := 0; i < n-k; i += 1 {
			cs = append(cs, []int{l, r})
			used[l] = true
			used[r] = true
			if i+1 < n-k {
				l = move(l, used, 1)
				r = move(r, used, 1)
			}
		}
	}
	return countPairs(cs)
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		n, k := stdin.Int(), stdin.Int()
		c := make([][]int, k)
		for j := range c {
			c[j] = []int{stdin.Int() - 1, stdin.Int() - 1}
		}
		fmt.Println(solve(c, n))
	}
}


package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	fmt.Scan(&s)
	a := len(s) / 20
	if len(s)%20 > 0 {
		a++
	}

	b, e := len(s)/a, len(s)%a
	if e > 0 {
		b++
	}
	fmt.Println(a, b)
	l := 0
	for i := 0; i < a; i++ {
		w := b
		if (e > 0) && (i >= e) {
			w--
			fmt.Print("*")
		}
		fmt.Println(s[l : l+w])
		l = l + w
	}
}

package main

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

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

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

func fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if j >= 1 {
		j = 0
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}
	if j >= 0 {
		j = 0
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j-1, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j+1, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

import "fmt"

func main() {

	var s string
	fmt.Scan(&s)

	length := len(s)
	lines := 1
	devider := -1
	var extras int
	for ; lines <= 5; lines++ {
		for d := 1; d <= 20; d++ {
			extras = lines * d - length
			if extras >= 0 && extras < lines {
				devider = d
				break
			}
		}
		if devider != -1 {
			break
		}
	}

	fmt.Printf("%d %d\n", lines, devider)

	counter := 0
	minus := 0
	for i := 0; i < lines; i++ {
		if extras > 0 {
			fmt.Printf("*")
			extras--
			minus = 1
		} else {
			minus = 0
		}
		for j := 0; j < devider-minus; j++ {
			fmt.Printf("%c", s[counter])
			counter++
		}
		fmt.Println()
	}
}

package main

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

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

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

func fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j-1, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j+1, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

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

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

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

func fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

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

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

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

func fun(i, k, j, n int) bool {
	if i == 0 {
		if n == 0 {
			return true
		} else {
			return false
		}
	}
	if n < 0 {
		return false
	}
	flag := false

	flag = flag || fun(i-1, k, j, n-k+j)
	if j > 0 {
		flag = flag || fun(i-1, k, j-1, n-k+j-1) // k-j+1
	}
	flag = flag || fun(i-1, k, j+1, n-k+j+1) // k - j -1

	return flag
}

var pos int
var S string

func print(i, k, j, n int) {
	if i == 0 {
		return
	}

	if fun(i-1, k, j, n-k+j) {
		for ss := 0; ss < j; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j])
		pos = pos + k - j
		print(i-1, k, j, n-k+j)
		return
	}
	if j > 0 && fun(i-1, k, j-1, n-k+j-1) {
		for ss := 0; ss < j-1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j+1])
		pos = pos + k - j + 1
		print(i-1, k, j, n-k+j-1)
		return
	}
	if fun(i-1, k, j+1, n-k+j+1) {
		for ss := 0; ss < j+1; ss++ {
			printf("*")
		}
		printf("%s\n", S[pos:pos+k-j-1])
		pos = pos + k - j - 1
		print(i-1, k, j, n-k+j+1)
		return
	}
}

func main() {
	defer writer.Flush()

	var s string
	scanf("%s", &s)
	n := len(s)

	//fmt.Println(n)

	for i := 1; i <= 5; i++ {
		for k := 1; k <= 20; k++ {
			for j := 0; j < k; j++ {
				//fmt.Println(i, k, j, fun(i, k, j, n))
				if fun(i, k, j, n) {
					printf("%d %d\n", i, k)
					pos = 0
					S = s
					print(i, k, j, n)
					return
				}
			}
		}
	}

}

package main

import "fmt"

func main() {

	var s string
	fmt.Scan(&s)

	length := len(s)
	lines := 1
	devider := -1
	var extras int
	for ; lines <= 5; lines++ {
		for d := 2; d <= 20; d++ {
			extras = lines * d - length
			if extras >= 0 && extras < lines {
				devider = d
				break
			}
		}
		if devider != -1 {
			break
		}
	}

	fmt.Printf("%d %d\n", lines, devider)

	counter := 0
	minus := 0
	for i := 0; i < lines; i++ {
		if extras > 0 {
			fmt.Printf("*")
			extras--
			minus = 1
		} else {
			minus = 0
		}
		for j := 0; j < devider-minus; j++ {
			fmt.Printf("%c", s[counter])
			counter++
		}
		fmt.Println()
	}
}


package main

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

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

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		u := make([]int, 0, n)
		s := make([]int, 0, n)

		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			u = append(u, temp)
		}

		for i := 0; i < n; i++ {
			var temp int
			_, _ = fmt.Fscan(in, &temp)

			s = append(s, temp)
		}

		mp := make(map[int][]int64)

		for i := 0; i < n; i++ {
			uni := u[i]
			scr := int64(s[i])

			if _, ok := mp[uni]; !ok {
				mp[uni] = make([]int64, 0)
			}

			mp[uni] = append(mp[uni], scr)
		}

		for _, slc := range mp {
			sort.SliceStable(slc, func(i, j int) bool {
				return slc[i] < slc[j]
			})

			for i := 1; i < len(slc); i++ {
				slc[i] += slc[i-1]
			}
		}

		ans := make([]int64, n+1)
		for _, v := range mp {
			for g := 1; g <= len(v); g++ {
				left := len(v) % g

				ans[g] += v[len(v)-1]
				if left > 0 {
					ans[g] -= v[left-1]
				}
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Printf("%d ", ans[i])
		}
		fmt.Println()
	}
}

package main

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

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

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		sToDList[n] = nil
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sz := len(v)
			if sz == 0 {
				continue
			}
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < sz; j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= sz; j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

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

	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		uni := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &uni[i])
			uni[i]--
		}
		stu := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &stu[i])
		}

		rec := make([][]int64, n)
		for i := 0; i < n; i++ {
			rec[uni[i]] = append(rec[uni[i]], int64(stu[i]))
		}

		ans := make([]int64, n + 1)
		for i := 0; i < n; i++ {
			sort.Slice(rec[i], func(ii, jj int) bool {
				return rec[i][ii] > rec[i][jj]
			})

			m := len(rec[i])
			for j := 1; j < m; j++ {
				rec[i][j] += rec[i][j - 1]
			}

			for j := 1; j <= m; j++ {
				ans[j] += rec[i][m / j * j - 1]
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Fprint(out, ans[i], " ")
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		//tot := int64(0)
		u := make([]int, n)
		for i := range u {
			Fscan(in, &u[i])
		}
		a := make([][]int, n)
		for _, v := range u {
			v--
			var w int
			Fscan(in, &w)
			a[v] = append(a[v], w)
		}

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

		sum := make([][]int64, n)
		for kk := range a {
			sort.Ints(a[kk])
			sum[kk] = make([]int64, len(a[kk])+1)
			for i, v := range a[kk] {
				sum[kk][i+1] = sum[kk][i] + int64(v)
			}
			//tot += sum[kk][len(a[kk])]
		}

		for k := 1; k <= n; k++ {
			ans := int64(0)
			for i, a := range a {
				if len(a) < k {
					break
				}

				j :=  len(a)%k
				ans += sum[i][len(a)] - sum[i][j]
			}
			Fprint(out, ans, " ")
		}
		Fprintln(out)
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

package main

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

const N = 200000

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		// read data
		fmt.Fscan(in, &n)
		str := make([]int64, n+1)
		participantUni := make([]int, n)
		uniSize := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &participantUni[i])
			participantUni[i]--
			uniSize[participantUni[i]]++
		}
		uni := make([][]int, n)
		for i := range uni {
			uni[i] = make([]int, 0, uniSize[i])
		}
		var participantStr int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &participantStr)
			uni[participantUni[i]] = append(uni[participantUni[i]], participantStr)
			str[1] += int64(participantStr)
		}

		// prepare data
		sort.Slice(uni, func(i, j int) bool {
			return len(uni[i]) > len(uni[j])
		})
		a := make([][]int64, len(uni[0])+1)
		var l int
		for i := 0; i < len(uni) && len(uni[i]) > 1; i++ {
			l = len(uni[i])
			if a[l] == nil {
				a[l] = make([]int64, l)
			}
			sort.Sort(sort.Reverse(sort.IntSlice(uni[i])))
			for j := 0; j < l; j++ {
				a[l][j] += int64(uni[i][j])
			}
		}
		for i := 2; i < len(a); i++ {
			for j := 1; j < len(a[i]); j++ {
				a[i][j] += a[i][j-1]
			}
		}

		// solve
		for i := 2; i < len(a); i++ {
			if a[i] == nil {
				continue
			}
			for j := 2; j <= i; j++ {
				str[j] += a[i][len(a[i])-1-len(a[i])%j]
			}
		}

		for i := 1; i <= n; i++ {
			fmt.Fprint(out, str[i], " ")
		}
		fmt.Fprintln(out)
		out.Flush()
	}
}

package main

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

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

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		u := make([]int, n)
		p := make([][]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &u[i])
			u[i]--
		}
		for i := 0; i < n; i++ {
			var s int64
			fmt.Fscan(in, &s)
			p[u[i]] = append(p[u[i]], s)
		}
		ans := make([]int64, n+1)

		for i := 0; i < n; i++ {
			sort.Slice(p[i], func(u, v int) bool {
				return p[i][u] < p[i][v]
			})
			for j := 1; j < len(p[i]); j++ {
				p[i][j] += p[i][j-1]
			}
			for j := 1; j <= len(p[i]); j++ {
				if len(p[i])%j != 0 {
					ans[j] += p[i][len(p[i])-1] - p[i][len(p[i])%j-1]
				} else {
					ans[j] += p[i][len(p[i])-1]
				}
			}
		}
		for i := 1; i < n+1; i++ {
			fmt.Fprint(out, ans[i], " ")
		}
		fmt.Fprintln(out)
	}

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

}

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

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sz := len(v)
			if sz == 0 {
				continue
			}
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < sz; j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= sz; j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	sq := make([]int64, 2e5+10)
	s, d := make([]int64, 2e5+10), make([]int64, 2e5+10)
	sToDList := make(map[int64][]int64)
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		sq[n] = 0
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
			sq[i] = 0
			sToDList[i] = nil
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
			sToDList[s[i]] = append(sToDList[s[i]], int64(d[i]))
		}

		for i := int64(1); i <= n; i++ {
			v := sToDList[i]
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			for j := 1; j <= len(v); j++ {
				sq[j] += prefix[len(v)/j*j]
			}
		}

		for k := int64(1); k <= n; k++ {
			fmt.Fprint(_w, sq[k], " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		s, d := make([]int64, n), make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
		}
		sToDList := make(map[int64][]int64)
		for i, v := range s {
			sToDList[v] = append(sToDList[v], int64(d[i]))
		}
		for i, v := range sToDList {
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			sToDList[i] = prefix
		}

		for k := int64(1); k <= n; k++ {
			total := int64(0)
			for _, v := range sToDList {
				if k > int64(len(v) -1) {
					continue
				}
				mod := int64(len(v)) % k
				total += v[int64(len(v)-1)-mod]
			}
			fmt.Fprint(_w, total, " ")
		}
		fmt.Fprintln(_w)
	}

}

package main

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

func main() {
	CF1519C(os.Stdin, os.Stdout)

}

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

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n int64
		fmt.Fscan(_r, &n)
		s, d := make([]int64, n), make([]int64, n)
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &s[i])
		}
		for i := int64(0); i < n; i++ {
			fmt.Fscan(_r, &d[i])
		}
		sToDList := make(map[int64][]int64)
		for i, v := range s {
			sToDList[v] = append(sToDList[v], int64(d[i]))
		}
		for i, v := range sToDList {
			sort.Slice(v, func(i, j int) bool { return v[i] > v[j] })
			prefix := make([]int64, len(v)+1)
			for j := 0; j < len(v); j++ {
				prefix[j+1] = prefix[j] + int64(v[j])
			}
			sToDList[i] = prefix
		}

		for k := int64(1); k <= n; k++ {
			total := int64(0)
			for _, v := range sToDList {
				if k > int64(len(v)) {
					continue
				}
				mod := int64(len(v)) % k
				total += v[int64(len(v)-1)-mod]
			}
			fmt.Fprint(_w, total, " ")
		}
		fmt.Fprintln(_w)
	}

}