There's a chip in the point $$$(0, 0)$$$ of the coordinate plane. In one operation, you can move the chip from some point $$$(x_1, y_1)$$$ to some point $$$(x_2, y_2)$$$ if the Euclidean distance between these two points is an integer (i.e. $$$\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$$ is integer).Your task is to determine the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — number of test cases. The single line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$0 \le x, y \le 50$$$) — the coordinates of the destination point.

For each test case, print one integer — the minimum number of operations required to move the chip from the point $$$(0, 0)$$$ to the point $$$(x, y)$$$.

NoteIn the first example, one operation $$$(0, 0) \rightarrow (8, 6)$$$ is enough. $$$\sqrt{(0-8)^2+(0-6)^2}=\sqrt{64+36}=\sqrt{100}=10$$$ is an integer.In the second example, the chip is already at the destination point.In the third example, the chip can be moved as follows: $$$(0, 0) \rightarrow (5, 12) \rightarrow (9, 15)$$$. $$$\sqrt{(0-5)^2+(0-12)^2}=\sqrt{25+144}=\sqrt{169}=13$$$ and $$$\sqrt{(5-9)^2+(12-15)^2}=\sqrt{16+9}=\sqrt{25}=5$$$ are integers.

package main

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

var T int

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

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		var x, y int
		Fscan(in, &x, &y)
		if x == 0 && y == 0 {
			Fprintln(out, 0)
			continue
		}
		dis := x*x + y*y
		tmp := int(math.Sqrt(float64(dis)))
		if tmp * tmp == dis {
			Fprintln(out, 1)
		} else {
			Fprintln(out, 2)
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		//fmt.Println("O1:", tmp)
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64((math.Abs(float64((x-i))) * math.Abs(float64((x-i))) + math.Abs(float64((y-j)))*math.Abs(float64((y-j)))))) -
					float64(int(math.Sqrt(float64((math.Abs(float64((x-i))) * math.Abs(float64((x-i))) + math.Abs(float64((y-j)))*math.Abs(float64((y-j))))))))
					//fmt.Println("O:", tmp)
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x == 0 && y == 0 {
				fmt.Println("0")
			} else {
				fmt.Println("1")
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y float64
		fmt.Fscan(in,&x,&y)
		if x == 0 && y == 0 {
			fmt.Fprintln(out,0)
		} else {
			if isIntegral(math.Sqrt(x*x+y*y)) == true {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}
func isIntegral(val float64) bool {
	return val == float64(int(val))
}

package main

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

type CF1657A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1657A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1657A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1657A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1657A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1657A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1657A
Date: 1/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1657/A
Problem: CF1657A
**/
func (in *CF1657A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		x, y := in.NextInt(), in.NextInt()
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else {
			dist := math.Sqrt(float64((x * x) + (y * y)))
			compare := float64(int(dist))
			if dist == compare {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		}
	}
}

func NewCF1657A(r *bufio.Reader) *CF1657A {
	return &CF1657A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1657A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		x, y := 0, 0
		fmt.Fscan(reader, &x, &y)

		// p := make([]int, n)
		// for i := range p {
		// 	fmt.Fscan(reader, &p[i])
		// }

		fmt.Fprintln(writter, solve(x, y))

		t--
	}

	//fmt.Println(solve(8, 6))

	//fmt.Println(commonServices.Interger(1.00))
}

func solve(x, y int) int {

	count := 0

	for !(x == 0 && y == 0) {

		nowX, nowY := 0, 0
		finish := false

		for i := y; i >= 0; i-- {

			for j := x; j >= 0; j-- {
				if Interger(math.Sqrt(float64(i*i + j*j))) {
					nowX, nowY = j, i
					finish = true
					break
				}
			}

			if finish {
				break
			} else {
				return 0
			}

		}

		//fmt.Println(x, y)

		x -= nowX
		y -= nowY

		count++
	}

	return count
}

func Interger(num float64) bool {
	if num == float64(int64(num)) {
		return true
	} else {
		return false
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t, x, y int
	fmt.Scanf("%d ", &t)
	for ;t>0;t-=1{
		fmt.Scanf("%d %d ", &x, &y)
		dis := int(math.Sqrt(float64(x*x+y*y))+0.00000000001)
		if x == 0 && y == 0{
			fmt.Printf("0\n")
		} else if dis*dis == x*x+y*y{
			fmt.Printf("1\n")
		}else{
			fmt.Printf("2\n")
		}
	}
 }

package main

import (
	"fmt"
	"math"
)

type node struct{
	x int
	y int
}

func solve(a [64][64]int)(b [64][64]int){
	nmax := 51;
	okp := make([]node, 0)
	for xx:=0;xx<=nmax;xx++{
		for yy:=0;yy<=nmax;yy++{
			dis := int(math.Sqrt(float64(xx*xx+yy*yy))+0.000000001)
			if dis*dis == xx*xx+yy*yy{
				okp = append(okp, node{xx, yy})
			}
		}
	}
	for i:=0;i<=nmax;i++{
		for j:=0;j<=nmax;j++{
			a[i][j] = 1000;
		}
	}
	a[0][0] = 0;
	for i:=0;i<=nmax;i++{
		for j:=0;j<=nmax;j++{
			for _, val := range okp{
				if i+val.x <= nmax && j+val.y <= nmax && a[i+val.x][j+val.y] > a[i][j]+1{
					a[i+val.x][j+val.y] = a[i][j] + 1
				}
			}
		}
	}
	return a
}

func main() {
	var t, x, y int
	var a [64][64]int
	b := solve(a)
	fmt.Scanf("%d ", &t)
	for ;t>0;t-=1{
		fmt.Scanf("%d %d ", &x, &y)
		fmt.Printf("%d\n",b[x][y])
	}
 }

package main
import "fmt"
import "os"
import "bufio"
import "math"
//import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)
func main() {
	defer output.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		a := 0
		b := 0
		fmt.Fscan(input,&a)
		fmt.Fscan(input,&b)
		if a==0 && b==0 {
			fmt.Fprintln(output,0)
		} else {
			sqrt := math.Sqrt(float64(a*a+b*b))
			if int(sqrt)*int(sqrt) == a*a+b*b {
				fmt.Fprintln(output,1)
			} else {
				fmt.Fprintln(output,2)
			}
		}
	}
}

package main

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

func square(a int) bool {
	var int_root int = int(math.Sqrt(float64(a)))
	return (int_root * int_root) == a
}

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

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

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

		if x == 0 && y == 0 {
			fmt.Fprintln(out, 0)
		} else if square(x*x + y*y) {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	valid := make(map[int]map[int]bool)
	for i := 1; i <= 50; i++ {
		valid[i] = make(map[int]bool)
		for j := 1; j <= 50; j++ {
			k := int(math.Sqrt(float64(i*i) + float64(j*j)))
			if i*i+j*j == k*k {
				valid[i][j] = true
				// fmt.Println(i, j)
			}
		}
	}
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t >= 1; t-- {
		var x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
			continue
		}
		if x == 0 || y == 0 {
			fmt.Println(1)
			continue
		}
		if valid[x][y] {
			fmt.Println(1)
			continue
		}
		fmt.Println(2)
	}
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		x, y := readTwoNums(reader)
		res := solve(x, y)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(x, y int) int {
	if x == 0 && y == 0 {
		return 0
	}
	c := x*x + y*y
	d := int(math.Sqrt(float64(c)))

	if d*d == c {
		return 1
	}
	return 2
}

package main

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

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

	var T, x, y int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y)
		if x == 0 && y == 0 {
			Fprintln(out, 0)
		} else {
			s := x*x + y*y
			rt := int(math.Sqrt(float64(s)))
			if rt*rt == s {
				Fprintln(out, 1)
			} else {
				Fprintln(out, 2)
			}
		}
	}
}

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

package main

import (
	"fmt"
	"math"
)

func check(x int, y int) bool {
	var z = int(math.Sqrt(float64(x*x + y*y)))
	return z*z == x*x+y*y
}

func main() {
	check(6, 8)
	var T, x, y int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else if check(x, y) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func check(x int, y int) bool {
	var z = int(math.Sqrt(float64(x*x + y*y)))
	return z * z == x * x + y * y
}

func main()  {
	check(6, 8)
	var T, x, y int
	fmt.Scan(&T)
	for i := 0; i < T; i ++ {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
		} else if check(x, y) {
			fmt.Println(1)
		} else {
			fmt.Println(2)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var x, y int
		fmt.Fscan(in, &x, &y)

		dist := x*x + y*y
		sqrt := int(math.Sqrt(float64(dist)))
		dist2 := sqrt * sqrt
		if x == 0 && y == 0 {
			fmt.Fprintln(out, 0)
		} else if dist == dist2 {
			fmt.Fprintln(out, 1)
		} else {
			fmt.Fprintln(out, 2)
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func dist(x, y float64) float64 {
	return math.Sqrt(x*x + y*y)
}

func main() {
	t := 0
	fmt.Scan(&t)
	var x, y float64
	for i := 0; i < t; i++ {
		fmt.Scan(&x, &y)
		dst := dist(x, y)
		if dst == 0 {
			fmt.Println(0)
			continue
		}
		if dst == float64(int64(dst)) {
			fmt.Println(1)
			continue
		}

		// cx, cy := 0., 0.
		// move diagonally
		// for cx != x && cy != y {
		// 	cx++
		// 	cy++
		// }
		steps := 2
		fmt.Println(steps)
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var x, y int
	scanf("%d %d\n", &x, &y)

	if x == 0 && y == 0 {
		fmt.Fprintln(writer, 0)
		return
	}

	num := math.Sqrt(float64(x*x + y*y))

	if num == float64(int64(num)) {
		fmt.Fprintln(writer, 1)
	} else {
		fmt.Fprintln(writer, 2)
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return nums[minNumIdx]
}

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

	return nums[maxNumIdx]
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

var T int

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

	Fscan(in, &T)
	for t := 0; t < T; t++ {
		var x, y int
		Fscan(in, &x, &y)
		ans := 0
		curx, cury := 0, 0
		for i := x; i > curx; i-- {
			for j := y; j > cury; j-- {
				mx := (curx - i) * (curx - i)
				my := (cury - j) * (cury - j)
				dis := math.Sqrt(float64(mx + my))
				if int(dis)*int(dis) == mx+my {
					ans ++
					curx, cury = i, j
					i, j = x, y
				}
			}
		}
		Fprintln(out, ans)
	}
}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		//fmt.Println("O1:", tmp)
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j)))) - float64(int(math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j))))))
					//fmt.Println("O:", tmp)
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x == 0 && y == 0 {
				fmt.Println("0")
			} else if x == 0 || y == 0 {
                                fmt.Println("2")
			} else {
				fmt.Println("1")
			}
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

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

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		x, _ := strconv.Atoi(ninps[0])
		y, _ := strconv.Atoi(ninps[1])

		tmp := math.Sqrt(float64((x*x + y*y))) - float64(int(math.Sqrt(float64((x*x + y*y)))))
		if tmp > 0 {
			done := false
			for i := 1; i < 50; i++ {
				for j := 1; j < 50; j++ {
					tmp = math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j)))) - float64(int(math.Sqrt(float64(((x-i)*(x-i) + (y-j)*(y-j))))))
					if tmp > 0 {
						continue
					} else {
						fmt.Println("2")
						done = true
						break
					}
				}
				if done {
					break
				}
			}
		} else {
			if x != 0 && y != 0 {
				fmt.Println("1")
			} else {
                                fmt.Println("0")
			}
		}
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var x,y float64
		fmt.Fscan(in,&x,&y)
		if x == 0 || y == 0 {
			fmt.Fprintln(out,0)
		} else {
			if isIntegral(math.Sqrt(x*x+y*y)) == true {
				fmt.Fprintln(out,1)
			} else {
				fmt.Fprintln(out,2)
			}
		}
	}
}
func isIntegral(val float64) bool {
	return val == float64(int(val))
}

package main

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

type CF1657A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1657A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1657A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1657A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1657A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1657A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1657A
Date: 1/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1657/A
Problem: CF1657A
**/
func (in *CF1657A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		x, y := in.NextInt(), in.NextInt()
		if x != 0 && y != 0 {
			dist := math.Sqrt(float64((x * x) + (y * y)))
			compare := float64(int(dist))
			if dist == compare {
				fmt.Println(1)
			} else {
				fmt.Println(2)
			}
		} else {
			fmt.Println(0)
		}
	}
}

func NewCF1657A(r *bufio.Reader) *CF1657A {
	return &CF1657A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1657A(bufio.NewReader(os.Stdin)).Run()
}

package main
import "fmt"
import "os"
import "bufio"
import "math"
//import "sort"
var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)
func main() {
	defer output.Flush()
	count := 0
	fmt.Fscan(input,&count)
	for count>0 {
		count --
		a := 0
		b := 0
		fmt.Fscan(input,&a)
		fmt.Fscan(input,&b)
		if a==0 && b==0 {
			fmt.Fprintln(output,0)
		} else {
			sqrt := math.Sqrt(float64(a*a+b*b))
			if int(sqrt*sqrt) == a*a+b*b {
				fmt.Fprintln(output,1)
			} else {
				fmt.Fprintln(output,2)
			}
		}
	}
}

package main

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

func square(a int) bool {
	var int_root int = int(math.Sqrt(float64(a)))
	return (int_root * int_root) == a
}

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

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

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

		posX, posY := 0, 0
		var tot int
		for posX != x || posY != y {
			var max, maxA, maxB int
			for a := x - posX; a >= 0; a-- {
				for b := y - posY; b >= 0; b-- {
					if square(a*a+b*b) && a*a+b*b > max {
						max, maxA, maxB = a*a+b*b, a, b
					}
				}
			}

			posX += maxA
			posY += maxB
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	valid := make(map[int]map[int]bool)
	for i := 1; i <= 50; i++ {
		valid[i] = make(map[int]bool)
		for j := 1; j <= 50; j++ {
			k := int(math.Sqrt(float64(i*i) + float64(j*j)))
			if (i*i)+(j*j) == k*k {
				valid[i][j] = true
				// fmt.Println(i, j)
			}
		}
	}
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t >= 1; t-- {
		var x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		if x == 0 && y == 0 {
			fmt.Println(0)
			continue
		}
		if valid[x][y] {
			fmt.Println(1)
			continue
		}
		fmt.Println(2)
	}
}


Amugae is in a very large round corridor. The corridor consists of two areas. The inner area is equally divided by $$$n$$$ sectors, and the outer area is equally divided by $$$m$$$ sectors. A wall exists between each pair of sectors of same area (inner or outer), but there is no wall between the inner area and the outer area. A wall always exists at the 12 o'clock position.  The inner area's sectors are denoted as $$$(1,1), (1,2), \dots, (1,n)$$$ in clockwise direction. The outer area's sectors are denoted as $$$(2,1), (2,2), \dots, (2,m)$$$ in the same manner. For a clear understanding, see the example image above.Amugae wants to know if he can move from one sector to another sector. He has $$$q$$$ questions.For each question, check if he can move between two given sectors.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 10^{18}$$$, $$$1 \le q \le 10^4$$$) — the number of sectors in the inner area, the number of sectors in the outer area and the number of questions. Each of the next $$$q$$$ lines contains four integers $$$s_x$$$, $$$s_y$$$, $$$e_x$$$, $$$e_y$$$ ($$$1 \le s_x, e_x \le 2$$$; if $$$s_x = 1$$$, then $$$1 \le s_y \le n$$$, otherwise $$$1 \le s_y \le m$$$; constraints on $$$e_y$$$ are similar). Amague wants to know if it is possible to move from sector $$$(s_x, s_y)$$$ to sector $$$(e_x, e_y)$$$.

For each question, print "YES" if Amugae can move from $$$(s_x, s_y)$$$ to $$$(e_x, e_y)$$$, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteExample is shown on the picture in the statement.

package main

import (
	"bufio"
	"math/big"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n, m, t := readInt64(), readInt64(), readInt()
	k := gcd(n, m)
	for i := 0; i < t; i++ {
		a, b, c, d := readInt64(), readInt64(), readInt64(), readInt64()
		if check(n, m, k, a, b) == check(n, m, k, c, d) {
			print("YES")
		} else {
			print("NO")
		}
	}

}

func check(n, m, k, a, b int64) int64 {
	bint := big.NewInt(b - 1)
	bint.Mul(bint, big.NewInt(k))
	if a == 1 {
		bint.Div(bint, big.NewInt(n))
	} else {
		bint.Div(bint, big.NewInt(m))
	}
	return bint.Int64()
}

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

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

/*
URL:
https://codeforces.com/problemset/problem/1200/C
*/

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 (
	n, m           int64
	cn, cm         int64
	q              int
	sx, sy, ex, ey int64
)

func main() {
	n, m = ReadInt64_2()

	g := Gcd(n, m)
	cn, cm = n/g, m/g

	q = ReadInt()
	for i := 0; i < q; i++ {
		sx, sy, ex, ey = ReadInt64_4()

		var sid, eid int64
		if sx == 1 {
			sid = Kiriage(sy, cn)
		} else {
			sid = Kiriage(sy, cm)
		}
		if ex == 1 {
			eid = Kiriage(ey, cn)
		} else {
			eid = Kiriage(ey, cm)
		}

		if sid == eid {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int64) int64 {
	return (a + (b - 1)) / b
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int64) int64 {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int64) int64 {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

/*********** 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"
import "os"
import "bufio"

var input *bufio.Reader

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

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

func main(){
    input = bufio.NewReader(os.Stdin)

    var n, m int64
    var Q int
    fmt.Fscanf(input, "%d%d%d\n", &n, &m, &Q)

    g := __gcd(n, m)
    n/=g; m/=g

    for i:=0; i<Q; i++ {
        var a, c int
        var b, d int64
        fmt.Fscanf(input, "%d%d%d%d\n", &a, &b, &c, &d)
        if a==1 {
            b = (b-1)/n
        } else {
            b = (b-1)/m
        }

        if c==1 {
            d = (d-1)/n
        } else {
            d = (d-1)/m
        }

        if b==d {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }

}

// Author: sighduck
// URL: https://codeforces.com/contest/1200/problem/C

package main

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

type Question struct {
	Sx int64
	Sy int64
	Ex int64
	Ey int64
}

func ceilDiv(x int64, y int64) int64 {
	return (x + y - 1) / y
}

func gcd(n int64, m int64) int64 {
	for m > 0 {
		n, m = m, n%m
	}
	return n
}

func Solve(n int64, m int64, q int, questions []Question) []string {
	d := gcd(n, m)
	nGroupSize := n / d
	mGroupSize := m / d
	solutions := make([]string, q)
	for i := 0; i < q; i++ {
		var eGroup, sGroup int64
		if questions[i].Sx == 1 {
			sGroup = ceilDiv(questions[i].Sy, nGroupSize)
		} else if questions[i].Sx == 2 {
			sGroup = ceilDiv(questions[i].Sy, mGroupSize)
		}
		if questions[i].Ex == 1 {
			eGroup = ceilDiv(questions[i].Ey, nGroupSize)
		} else if questions[i].Ex == 2 {
			eGroup = ceilDiv(questions[i].Ey, mGroupSize)
		}
		if sGroup == eGroup {
			solutions[i] = "YES"
		} else {
			solutions[i] = "NO"
		}
	}
	return solutions
}

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

	var n, m int64
	var q int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &q)
	questions := make([]Question, q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d %d %d %d\n", &questions[i].Sx, &questions[i].Sy, &questions[i].Ex, &questions[i].Ey)
	}
	solutions := Solve(n, m, q, questions)
	for i := 0; i < q; i++ {
		fmt.Fprintf(writer, "%s\n", solutions[i])
	}
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n, m, t := readInt64(), readInt64(), readInt()
	k := gcd(n, m)
	for i := 0; i < t; i++ {
		if check(n, m, k, readInt64(), readInt64()) == check(n, m, k, readInt64(), readInt64()) {
			print("YES")
		} else {
			print("NO")
		}
	}

}

func check(n, m, k, a, b int64) int64 {
	if a == 1 {
		return (b - 1) * k / n
	}
	return (b - 1) * k / m
}

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

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

// Author: sighduck
// URL: https://codeforces.com/contest/1200/problem/C

package main

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

type Question struct {
	Sx uint64
	Sy uint64
	Ex uint64
	Ey uint64
}

func ceilDiv(x uint64, y uint64) uint64 {
	return uint64(math.Ceil(float64(x) / float64(y)))
}

func gcd(n uint64, m uint64) uint64 {
	for m > 0 {
		n, m = m, n%m
	}
	return n
}

func Solve(n uint64, m uint64, q int, questions []Question) []string {
	d := gcd(n, m)
	nGroupSize := n / d
	mGroupSize := m / d
	solutions := make([]string, q)
	for i := 0; i < q; i++ {
		var eGroup, sGroup uint64
		if questions[i].Sx == 1 {
			sGroup = ceilDiv(questions[i].Sy, nGroupSize)
		} else if questions[i].Sx == 2 {
			sGroup = ceilDiv(questions[i].Sy, mGroupSize)
		}
		if questions[i].Ex == 1 {
			eGroup = ceilDiv(questions[i].Ey, nGroupSize)
		} else if questions[i].Ex == 2 {
			eGroup = ceilDiv(questions[i].Ey, mGroupSize)
		}
		if sGroup == eGroup {
			solutions[i] = "YES"
		} else {
			solutions[i] = "NO"
		}
	}
	return solutions
}

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

	var n, m uint64
	var q int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &q)
	questions := make([]Question, q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d %d %d %d\n", &questions[i].Sx, &questions[i].Sy, &questions[i].Ex, &questions[i].Ey)
	}
	solutions := Solve(n, m, q, questions)
	for i := 0; i < q; i++ {
		fmt.Fprintf(writer, "%s\n", solutions[i])
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1200/problem/C

package main

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

type Question struct {
	Sx int64
	Sy int64
	Ex int64
	Ey int64
}

func ceilDiv(x int64, y int64) int64 {
	return int64(math.Ceil(float64(x) / float64(y)))
}

func gcd(n int64, m int64) int64 {
	for m > 0 {
		n, m = m, n % m
	}
	return n
}

func Solve(n int64, m int64, q int, questions []Question) []string {
	d := gcd(n, m)
	nGroupSize := n / d
	mGroupSize := m / d
	solutions := make([]string, q)
	for i := 0; i < q; i++ {
		var eGroup, sGroup int64
		if questions[i].Sx == 1 {
			sGroup = ceilDiv(questions[i].Sy, nGroupSize)
		}
		if questions[i].Sx == 2 {
			sGroup = ceilDiv(questions[i].Sy, mGroupSize)
		}
		if questions[i].Ex == 1 {
			eGroup = ceilDiv(questions[i].Ey, nGroupSize)
		}
		if questions[i].Ex == 2 {
			eGroup = ceilDiv(questions[i].Ey, mGroupSize)
		}
		if sGroup == eGroup {
			solutions[i] = "YES"
		} else {
			solutions[i] = "NO"
		}
	}
	return solutions
}

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

	var n, m int64
	var q int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &q)
	questions := make([]Question, q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d %d %d %d\n", &questions[i].Sx, &questions[i].Sy, &questions[i].Ex, &questions[i].Ey)
	}
	solutions := Solve(n, m, q, questions)
	for i := 0; i < q; i++ {
		fmt.Fprintf(writer, "%s\n", solutions[i])
	}
}


Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he remembers, that string ti occurs in string s at least ki times or more, he also remembers exactly ki positions where the string ti occurs in string s: these positions are xi, 1, xi, 2, ..., xi, ki. He remembers n such strings ti.You are to reconstruct lexicographically minimal string s such that it fits all the information Ivan remembers. Strings ti and string s consist of small English letters only.

The first line contains single integer n (1 ≤ n ≤ 105) — the number of strings Ivan remembers. The next n lines contain information about the strings. The i-th of these lines contains non-empty string ti, then positive integer ki, which equal to the number of times the string ti occurs in string s, and then ki distinct positive integers xi, 1, xi, 2, ..., xi, ki in increasing order — positions, in which occurrences of the string ti in the string s start. It is guaranteed that the sum of lengths of strings ti doesn't exceed 106, 1 ≤ xi, j ≤ 106, 1 ≤ ki ≤ 106, and the sum of all ki doesn't exceed 106. The strings ti can coincide. It is guaranteed that the input data is not self-contradictory, and thus at least one answer always exists.

Print lexicographically minimal string that fits all the information Ivan remembers.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	var n, k, st int
	var s string
	for Fscan(in, &n); n > 0; n-- {
		for Fscan(in, &s, &k); k > 0; k-- {
			Fscan(in, &st)
			st--
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"runtime/debug"
)

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	var n, k, st int
	var s string
	for Fscan(in, &n); n > 0; n-- {
		for Fscan(in, &s, &k); k > 0; k-- {
			Fscan(in, &st)
			st--
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

func main() {
	debug.SetGCPercent(-1)
	CF827A(os.Stdin, os.Stdout)
}

package main

import (
	. "fmt"
	"syscall"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			syscall.Read(syscall.Stdin, buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b-'0')
		}
		return
	}
	rs := func() (s []byte) {
		b := rc()
		for ; 'a' > b || b > 'z'; b = rc() {
		}
		for ; 'a' <= b && b <= 'z'; b = rc() {
			s = append(s, b)
		}
		return
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := r(); n > 0; n-- {
		s, k := rs(), r()
		for ; k > 0; k-- {
			st := r() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Print(string(ans))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	ans := make([]byte, 1e7)
	end := 0
	initFa(1e7)
	var n, k, st int
	var s string
	for Fscan(in, &n); n > 0; n-- {
		for Fscan(in, &s, &k); k > 0; k-- {
			Fscan(in, &st)
			st--
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				merge(i, e)
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b-'0')
		}
		return
	}
	rs := func() (s []byte) {
		b := rc()
		for ; 'a' > b || b > 'z'; b = rc() {
		}
		for ; 'a' <= b && b <= 'z'; b = rc() {
			s = append(s, b)
		}
		return
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := r(); n > 0; n-- {
		s, k := rs(), r()
		for ; k > 0; k-- {
			st := r() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprint(_w, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; !('0' <= b && b <= '9'); b = rc() {
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b-'0')
		}
		return
	}
	rs := func() (s []byte) {
		b := rc()
		for ; !('a' <= b && b <= 'z'); b = rc() {
		}
		for ; 'a' <= b && b <= 'z'; b = rc() {
			s = append(s, b)
		}
		return
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := r(); n > 0; n-- {
		s, k := rs(), r()
		for ; k > 0; k-- {
			st := r() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprint(_w, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	buf := make([]byte, 8192)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b || b > '9'; b = rc() {
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b-'0')
		}
		return
	}
	rs := func() (s []byte) {
		b := rc()
		for ; 'a' > b || b > 'z'; b = rc() {
		}
		for ; 'a' <= b && b <= 'z'; b = rc() {
			s = append(s, b)
		}
		return
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := r(); n > 0; n-- {
		s, k := rs(), r()
		for ; k > 0; k-- {
			st := r() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprint(_w, string(ans))
}

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

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var n int
	for I(&n) == nil {
		solve(n)
	}
	w.Flush()
}

func solve(n int) {
	res := make([]byte, 1e7)
	oo := make([]int, 1e7)
	for i := range res {
		res[i] = 'a'
	}
	l := 0
	for i := 0; i < n; i++ {
		in := ""
		I(&in)
		var k int
		I(&k)
		ll := len(in)
		pre := 0
		for j := 0; j < k; j++ {
			var o int
			I(&o)
			o--
			oo[o] = max(oo[o], pre-o)
			for d := oo[o]; d < ll; d++ {
				res[o+d] = in[d]
				oo[o]++
			}
			l = max(l, o+ll)
			pre = oo[o] + o
		}
	}
	O(string(res[:l]), "\n")
}

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

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

func atoi(s string) int { v, _ := strconv.Atoi(s); return v }
func atou(s string) uint64 { v, _ := strconv.ParseUint(s, 10, 64); return v }
func atof(s string) float64 { v, _ := strconv.ParseFloat(s, 64); return v }
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 }

var _red = bufio.NewScanner(os.Stdin)
var _tok []string

func init() { _red.Buffer(make([]byte, 1e7), 1e7) }

func gettok() (t string, e bool) {
	if len(_tok) == 0 { if !_red.Scan() { return }; _tok = strings.Split(_red.Text(), " ") }
	t = _tok[0]; _tok = _tok[1:]; e = len(_tok) == 0; return
}

func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int: t, _ := gettok(); *v = atoi(t)
		case *uint64: t, _ := gettok(); *v = atou(t)
		case *float64: t, _ := gettok(); *v = atof(t)
		case *string: *v, _ = gettok()
		case *[]int:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atoi(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atoi(t) } }
		case *[]uint64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atou(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atou(t) } }
		case *[]float64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atof(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atof(t) } }
		case *[]string:
			if len(*v) == 0 { *v = append(*v, _tok...); _tok = _tok[:0]
			} else { for j := range *v { (*v)[j], _ = gettok() } }
		}
	}
}

func main() {
	var n int
	read(&n)
	ans := make([]byte, 2e6+100)
	xs := make([]int, 1e6+100)
	mp := map[int]string{}
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if s, ok := mp[xi-1]; !ok || len(s) < size {
			    mp[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s, ok := mp[i]; ok {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k = i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k = i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

func atoi(s string) int { v, _ := strconv.Atoi(s); return v }
func atou(s string) uint64 { v, _ := strconv.ParseUint(s, 10, 64); return v }
func atof(s string) float64 { v, _ := strconv.ParseFloat(s, 64); return v }
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 }

var _red = bufio.NewScanner(os.Stdin)
var _tok []string
var _buf [1e7]byte
func init() { _red.Buffer(_buf[:], len(_buf)) }

func gettok() (t string, e bool) {
	if len(_tok) == 0 { if !_red.Scan() { return }; _tok = strings.Split(_red.Text(), " ") }
	t = _tok[0]; _tok = _tok[1:]; e = len(_tok) == 0; return
}

func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int: t, _ := gettok(); *v = atoi(t)
		case *uint64: t, _ := gettok(); *v = atou(t)
		case *float64: t, _ := gettok(); *v = atof(t)
		case *string: *v, _ = gettok()
		case *[]int:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atoi(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atoi(t) } }
		case *[]uint64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atou(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atou(t) } }
		case *[]float64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atof(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atof(t) } }
		case *[]string:
			if len(*v) == 0 { *v = append(*v, _tok...); _tok = _tok[:0]
			} else { for j := range *v { (*v)[j], _ = gettok() } }
		}
	}
}

var ans_ [2e6+100]byte
var xs_ [1e6+100]int
var tb_ [2e6+100]string

func main() {
	var n int
	read(&n)
	ans := ans_[:]
	xs := xs_[:]
	tb := tb_[:]
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if len(tb[xi-1]) < size {
			    tb[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s := tb[i]; len(s) > 0 {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k = i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k = i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var red = bufio.NewScanner(os.Stdin)

func init() {
    red.Buffer(make([]byte, 1e7), 1e7)
}

func read(vs ...interface{}) {
	if !red.Scan() {
		return
	}
	tx := strings.Split(red.Text(), " ")
	for i, v := range vs {
		switch v := v.(type) {
		case *int:
			*v, _ = strconv.Atoi(tx[i])
		case *string:
			*v = tx[i]
		case *[]int:
			for _, t := range tx[i:] {
				e, _ := strconv.Atoi(t)
				*v = append(*v, e)
			}
			return
		}
	}
}

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

func main() {
	var n int
	read(&n)
	ans := make([]byte, 2e6+100)
	xs := make([]int, 1e6+100)
	mp := map[int]string{}
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if s, ok := mp[xi-1]; !ok || len(s) < size {
			    mp[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s, ok := mp[i]; ok {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k = i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k = i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var buf_ [1e7]byte
var tok_ string
var hnd_ []byte
var p_ int
func init() {
    n, _ :=os.Stdin.Read(buf_[:])
    hnd_ = buf_[:n]
}

func gettok() (s string , e bool) {
    if p_ >= len(hnd_) { return }
    x := p_
    for {
        if c := hnd_[p_]; c == '\n' || c == '\r' || c == ' ' {
            break
        }
        p_++
        if p_ >= len(hnd_) { break }
    }
    s = string(hnd_[x:p_])
    e = p_ >= len(hnd_) || hnd_[p_] == '\n' || hnd_[p_] == '\r'
    for p_ < len(hnd_) {
        if c := hnd_[p_]; c == '\n' || c == '\r' || c == ' ' {
            p_++; continue
        }
        break
    }
    return
}

func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int:
		    t, _ := gettok()
			*v, _ = strconv.Atoi(t)
		case *string:
			*v, _ = gettok()
		case *[]int:
			for {
			    t, e := gettok()
				n, _ := strconv.Atoi(t)
				*v = append(*v, n)
				if e { break }
			}
			return
		}
	}
}

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

func main() {
	var n int
	read(&n)
	ans := make([]byte, 2e6+100)
	xs := make([]int, 1e6+100)
	mp := map[int]string{}
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if s, ok := mp[xi-1]; !ok || len(s) < size {
			    mp[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s, ok := mp[i]; ok {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k = i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k = i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

func atoi(s string) int { v, _ := strconv.Atoi(s); return v }
func atou(s string) uint64 { v, _ := strconv.ParseUint(s, 10, 64); return v }
func atof(s string) float64 { v, _ := strconv.ParseFloat(s, 64); return v }
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 }

var _red = bufio.NewScanner(os.Stdin)
var _tok []string

func init() { _red.Buffer(make([]byte, 1e7), 1e7) }

func gettok() (t string, e bool) {
	if len(_tok) == 0 { if !_red.Scan() { return }; _tok = strings.Split(_red.Text(), " ") }
	t = _tok[0]; _tok = _tok[1:]; e = len(_tok) == 0; return
}

func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int: t, _ := gettok(); *v = atoi(t)
		case *uint64: t, _ := gettok(); *v = atou(t)
		case *float64: t, _ := gettok(); *v = atof(t)
		case *string: *v, _ = gettok()
		case *[]int:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atoi(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atoi(t) } }
		case *[]uint64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atou(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atou(t) } }
		case *[]float64:
			if len(*v) == 0 { for { t, e := gettok(); *v = append(*v, atof(t)); if e { break } }
			} else { for j := range *v { t, _ := gettok(); (*v)[j] = atof(t) } }
		case *[]string:
			if len(*v) == 0 { *v = append(*v, _tok...); _tok = _tok[:0]
			} else { for j := range *v { (*v)[j], _ = gettok() } }
		}
	}
}

func main() {
	var n int
	read(&n)
	ans := make([]byte, 2e6+100)
	xs := make([]int, 1e6+100)
	tb := make([]string, 2e6+100)
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if len(tb[xi-1]) < size {
			    tb[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s := tb[i]; len(s) > 0 {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k = i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k = i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

package main

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

func solve() {
	n := readInt()
	res := make([]byte, 0)
	last := 0
	for i := 0; i < n; i++ {
		s := readString()
		t := readInt()
		end := 0
		for j := 0; j < t; j++ {
			pos := readInt() - 1
			for ii := max(end-pos, 0); ii < len(s); ii++ {
				for len(res) <= pos+ii {
					res = append(res, 'a')
				}
				res[pos+ii] = s[ii]
				end = max(pos+ii, end)
			}
		}
		last = max(last, end)
	}
	os.Stdout.Write(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()
}

// 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
}

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
}

package main

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

func solve() {
	n := readInt()
	res := make([]byte, 10000000)
	last := 0
	for i := 0; i < n; i++ {
		s := readString()
		t := readInt()
		end := 0
		for j := 0; j < t; j++ {
			pos := readInt() - 1
			for ii := max(end-pos, 0); ii < len(s); ii++ {
				res[pos+ii] = s[ii]
				end = max(pos+ii, end)
			}
		}
		last = max(last, end)
	}
	for i := 0; i < last+1; i++ {
		if res[i] == 0 {
			res[i] = 'a'
		}
	}
	fmt.Println(string(res[0 : last+1]))
}

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()
}

// 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
}

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
}

package main

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

func solve() {
	// update
	n := readInt()
	res := make([]byte, 2000001)
	last := 0
	for i := 0; i < n; i++ {
		s := readString()
		t := readInt()
		end := 0
		for j := 0; j < t; j++ {
			pos := readInt() - 1
			for ii := max(end-pos, 0); ii < len(s); ii++ {
				res[pos+ii] = s[ii]
				end = max(pos+ii, end)
			}
		}
		last = max(last, end)
	}
	for i := 0; i < last+1; i++ {
		if res[i] == 0 {
			res[i] = 'a'
		}
	}
	os.Stdout.Write(res[0 : last+1])
}

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()
}

// 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
}

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
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 1e7)
	initFa(1e7)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			if len(s) == 0 {
				panic(s)
			}
			st := read() - 1
			for i := st; ; {
				j := find(i)
				if j-st >= len(s) {
					break
				}
				ans[j] = s[j-st]
				fa[j] = j + 1
				i = j + 1
			}
		}
	}
	end := len(ans) - 1
	for ; end >= 0; end-- {
		if ans[end] > 0 {
			for i := end - 1; i >= 0; i-- {
				if ans[i] == 0 {
					ans[i] = 'a'
				}
			}
			break
		}
	}
	Fprintf(out, "%s", ans[:end+1])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for _, b := range s {
			if b<'a' || b>'z' {
				panic(b)
			}
		}
		ss := bytes.TrimSpace(s)
		if len(ss) != len(s) || len(ss) == 0 {
			panic(s)
		}
		for ; k > 0; k-- {

			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	read := func() (x int) {
		in.Scan()
		s := in.Bytes()
		if len(s) == 0 {
			panic(s)
		}
		for _, b := range s {
			if b < '0' || b > '9' {
				panic(b)
			}
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte {
		in.Scan()
		s := in.Bytes()
		if len(s) == 0 {
			panic(s)
		}
		for _, b := range s {
			if b < 'a' || b > 'z' {
				panic(b)
			}
		}
		return s
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for ; k > 0; k-- {
			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprint(_w, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	initFa(2e6)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			st := read() - 1
			for i := st; ; {
				j := find(i)
				if j-st >= len(s) {
					break
				}
				ans[j] = s[j-st]
				fa[j] = j + 1
				i = j + 1
			}
		}
	}
	end := len(ans) - 1
	for ; end >= 0; end-- {
		if ans[end] > 0 {
			for i := end - 1; i >= 0; i-- {
				if ans[i] == 0 {
					ans[i] = 'a'
				}
			}
			break
		}
	}
	Fprintf(out, "%s", ans[:end+1])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 1e7)
	end := 0
	initFa(1e7)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				merge(i, e)
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	initFa(2e6)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			st := read() - 1
			for i := st; ; {
				j := find(i)
				if j-st >= len(s) {
					break
				}
				ans[j] = s[j-st]
				fa[j] = j + 1
				i = j + 1
			}
		}
	}
	end := len(ans) - 1
	for ; end >= 0; end-- {
		if ans[end] > 0 {
			for i := end - 1; i >= 0; i-- {
				if ans[i] == 0 {
					ans[i] = 'a'
				}
			}
			break
		}
	}
	Fprintf(out, "%s", ans[:end+1])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	//in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		s := in.Bytes()
		if len(s) == 0 {
			panic(s)
		}
		for _, b := range s {
			if b < '0' || b > '9' {
				panic(b)
			}
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte {
		in.Scan()
		s := in.Bytes()
		if len(s) == 0 {
			panic(s)
		}
		for _, b := range s {
			if b < 'a' || b > 'z' {
				panic(b)
			}
		}
		return s
	}

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for ; k > 0; k-- {
			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	//in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for _, b := range s {
			if b<'a' || b>'z' {
				panic(b)
			}
		}
		ss := bytes.TrimSpace(s)
		if len(ss) != len(s) || len(ss) == 0 {
			panic(s)
		}
		for ; k > 0; k-- {

			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	//in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			if b < '0' || b>'9' {
				panic(b)
			}
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for _, b := range s {
			if b<'a' || b>'z' {
				panic(b)
			}
		}
		ss := bytes.TrimSpace(s)
		if len(ss) != len(s) || len(ss) == 0 {
			panic(s)
		}
		for ; k > 0; k-- {

			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	initFa(2e6)
	for n := read(); n > 0; n-- {
		for s, k := readS(), read(); k > 0; k-- {
			if len(s) == 0 {
				panic(s)
			}
			st := read() - 1
			for i := st; ; {
				j := find(i)
				if j-st >= len(s) {
					break
				}
				ans[j] = s[j-st]
				fa[j] = j + 1
				i = j + 1
			}
		}
	}
	end := len(ans) - 1
	for ; end >= 0; end-- {
		if ans[end] > 0 {
			for i := end - 1; i >= 0; i-- {
				if ans[i] == 0 {
					ans[i] = 'a'
				}
			}
			break
		}
	}
	Fprintf(out, "%s", ans[:end+1])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF827A(_r io.Reader, _w io.Writer) {
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	readS := func() []byte { in.Scan(); return in.Bytes() }

	ans := make([]byte, 2e6-1)
	end := 0
	initFa(2e6)
	for n := read(); n > 0; n-- {
		s, k := readS(), read()
		for _, b := range s {
			if b<'a' || b>'z' {
				panic(b)
			}
		}
		for ; k > 0; k-- {

			st := read() - 1
			e := st + len(s)
			if e > end {
				end = e
			}
			for i := find(st); i < e; i = find(i + 1) {
				ans[i] = s[i-st]
				fa[i] = e
			}
		}
	}
	ans = ans[:end]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	Fprintf(out, "%s", ans)
}

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

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var buf_ [1e7]byte
var tok_ string
var hnd_ []byte
var p_ int
func init() {
    n, _ :=os.Stdin.Read(buf_[:])
    hnd_ = buf_[:n]
}

func gettok() (s string , e bool) {
    if p_ >= len(hnd_) { return }
    x := p_
    for {
        if c := hnd_[p_]; c == '\n' || c == '\r' || c == ' ' {
            break
        }
        p_++
        if p_ >= len(hnd_) { break }
    }
    s = string(hnd_[x:p_])
    e = p_ >= len(hnd_) || hnd_[p_] == '\n' || hnd_[p_] == '\r'
    for p_ < len(hnd_) {
        if c := hnd_[p_]; c == '\n' || c == '\r' || c == ' ' {
            p_++; continue
        }
        break
    }
    return
}

func read(vs ...interface{}) {
	for _, v := range vs {
		switch v := v.(type) {
		case *int:
		    t, _ := gettok()
			*v, _ = strconv.Atoi(t)
		case *string:
			*v, _ = gettok()
		case *[]int:
			for {
			    t, e := gettok()
				n, _ := strconv.Atoi(t)
				*v = append(*v, n)
				if e { break }
			}
			return
		}
	}
}

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

func main() {
	var n int
	read(&n)
	ans := make([]byte, 2e6+100)
	xs := make([]int, 1e6+100)
	mp := map[int]string{}
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		for _, xi := range xs {
			if s, ok := mp[xi-1]; !ok || len(s) < size {
			    mp[xi-1] = ti
			}
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	k := 0
	for i := range ans {
		if s, ok := mp[i]; ok {
		    if k > i {
		        if k-i > len(s) { continue }
		        copy(ans[k:], []byte(s[k-i:]))
		        k += i + len(s)
		    } else {
		        copy(ans[i:], []byte(s))
		        k += i + len(s)
		    }
		} else if ans[i] == 0 {
			ans[i] = 'a'
		}
	}
	os.Stdout.Write(ans)
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var red = bufio.NewScanner(os.Stdin)

func read(vs ...interface{}) {
	if !red.Scan() {
		return
	}
	tx := strings.Split(red.Text(), " ")
	for i, v := range vs {
		switch v := v.(type) {
		case *int:
			*v, _ = strconv.Atoi(tx[i])
		case *string:
			*v = tx[i]
		case *[]int:
			for _, t := range tx[i:] {
				e, _ := strconv.Atoi(t)
				*v = append(*v, e)
			}
			return
		}
	}
}

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

func main() {
	var n int
	read(&n)
	ans := make([]byte, 1e7+100)
	xs := make([]int, 1e7+100)
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		word := []byte(ti)
		for _, xi := range xs {
			copy(ans[xi-1:], word)
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	for _, c := range ans {
		if c == 0 {
			fmt.Print('a')
		} else {
			fmt.Print(string(c))
		}
	}
	fmt.Println()
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

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

var red = bufio.NewScanner(os.Stdin)

func read(vs ...interface{}) {
	if !red.Scan() {
		return
	}
	tx := strings.Split(red.Text(), " ")
	for i, v := range vs {
		switch v := v.(type) {
		case *int:
			*v, _ = strconv.Atoi(tx[i])
		case *string:
			*v = tx[i]
		case *[]int:
			for _, t := range tx[i:] {
				e, _ := strconv.Atoi(t)
				*v = append(*v, e)
			}
			return
		}
	}
}

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 main() {
	var n int
	read(&n)
	ans := make([]byte, 1e7+100)
	xs := make([]int, 1e7+100)
	length := 0
	for i := 0; i < n; i++ {
		var ti string
		var ki int
		xs = xs[:0]
		read(&ti, &ki, &xs)
		size := len(ti)
		word := []byte(ti)
		for _, xi := range xs {
			copy(ans[xi-1:], word)
		}
		length = max(length, (xs[ki-1]-1)+size)
	}
	ans = ans[:length]
	for i, c := range ans {
		if c == 0 {
			ans[i] = 'a'
		}
	}
	x := 0
	const S = 10000
	for x+S < length {
		fmt.Print(string(ans[x : x+S]))
		x += S
	}
	fmt.Println(string(ans[x : x+length]))
}

package main

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

func solve() {
	n := readInt()
	res := make([]byte, 0)
	last := 0
	for i := 0; i < n; i++ {
		s := readString()
		t := readInt()
		end := 0
		for j := 0; j < t; j++ {
			pos := readInt() - 1
			for ii := max(end-pos, 0); ii < len(s); ii++ {
				if len(res) <= pos+ii {
					for jj := 0; jj-1 < pos+ii; jj++ {
						res = append(res, 'a')
					}
					res = append(res, s[ii])
				} else {
					res[pos+ii] = s[ii]
				}
				end = max(pos+ii, end)
			}
		}
		last = max(last, end)
	}
	os.Stdout.Write(res[0 : last+1])
}

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()
}

// 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
}

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
}

package main

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

func solve() {
	n := readInt()
	res := make([]byte, 1000001)
	last := 0
	for i := 0; i < n; i++ {
		s := readString()
		t := readInt()
		end := 0
		for j := 0; j < t; j++ {
			pos := readInt() - 1
			for ii := max(end-pos, 0); ii < len(s); ii++ {
				res[pos+ii] = s[ii]
				last = max(pos+ii, last)
				end = max(pos+ii, end)
			}
		}
	}
	fmt.Println(string(res[0 : last+1]))
}

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()
}

// 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
}

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
}


There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct.Every contestant hopes that he can find a teammate so that their team’s strength is as high as possible. That is, a contestant will form a team with highest strength possible by choosing a teammate from ones who are willing to be a teammate with him/her. More formally, two people A and B may form a team if each of them is the best possible teammate (among the contestants that remain unpaired) for the other one. Can you determine who will be each person’s teammate?

There are 2n lines in the input.  The first line contains an integer n (1 ≤ n ≤ 400) — the number of teams to be formed. The i-th line (i > 1) contains i - 1 numbers ai1, ai2, ... , ai(i - 1). Here aij (1 ≤ aij ≤ 106, all aij are distinct) denotes the strength of a team consisting of person i and person j (people are numbered starting from 1.)

Output a line containing 2n numbers. The i-th number should represent the number of teammate of i-th person.

NoteIn the first sample, contestant 1 and 2 will be teammates and so do contestant 3 and 4, so the teammate of contestant 1, 2, 3, 4 will be 2, 1, 4, 3 respectively.

package main

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

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

type TeamStrength struct {
	strength, first, second int
}

type ByStrength []TeamStrength

func (a ByStrength) Len() int           { return len(a) }
func (a ByStrength) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByStrength) Less(i, j int) bool { return a[i].strength < a[j].strength }

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

	n := nextInt()
	peoples := make([]int, n*2+1)
	teams := make([]TeamStrength, 0)

	for i := 1; i < 2*n; i++ {
		for j := 1; j <= i; j++ {
			teams = append(teams, TeamStrength{nextInt(), i + 1, j})
		}
	}

	sort.Sort(sort.Reverse(ByStrength(teams)))

	for i := range teams {
		if peoples[teams[i].first] == 0 && peoples[teams[i].second] == 0 {
			peoples[teams[i].first] = teams[i].second
			peoples[teams[i].second] = teams[i].first
		}
	}

	// println(peoples)
	// println(teams)

	for i := 1; i < len(peoples); i++ {
		print(peoples[i], " ")
	}

	println()
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in.During his ride, Arkady woke up several times and each time he saw the tram stopping at some stop. For each stop he knows which lines of tram stop there. Given this information, can you help Arkady determine what are the possible lines of the tram he was in?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$) — the number of stops Arkady saw. The next $$$n$$$ lines describe the stops. Each of them starts with a single integer $$$r$$$ ($$$1 \le r \le 100$$$) — the number of tram lines that stop there. $$$r$$$ distinct integers follow, each one between $$$1$$$ and $$$100$$$, inclusive, — the line numbers. They can be in arbitrary order. It is guaranteed that Arkady's information is consistent, i.e. there is at least one tram line that Arkady could take.

Print all tram lines that Arkady could be in, in arbitrary order.

NoteConsider the first example. Arkady woke up three times. The first time he saw a stop with lines $$$1$$$, $$$4$$$, $$$6$$$. The second time he saw a stop with lines $$$1$$$, $$$4$$$. The third time he saw a stop with lines $$$10$$$, $$$5$$$, $$$6$$$, $$$4$$$ and $$$1$$$. He can be in a tram of one of two lines: $$$1$$$ or $$$4$$$.

package main

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

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

func main() {
    var n int
    fmt.Fscanln(reader, &n)
    var num_elems, temp int
    mydic := make(map[int]int)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &num_elems)
        for i := 0; i < num_elems; i++ {
            fmt.Fscan(reader, &temp)
            mydic[temp]=mydic[temp]+1
        }
    }
    for k,v := range mydic {
        if v == n {
            fmt.Print(k)
            fmt.Print(" ")
        }
    }
}

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 main() {
	defer writer.Flush()
	var n, r, t int
	scanf("%d\n", &n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		scanf("%d", &r)
		for j := 0; j < r; j++ {
			scanf("%d", &t)
			m[t]++
		}
		scanf("\n")
	}

	for k, v := range m {
		if v == n {
			printf("%d ", k)
		}
	}

}

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

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

func scanInt64() int64 {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v
}

func scanInt() int {
	scanner.Scan()
	v, _ := strconv.Atoi(scanner.Text())
	return v
}

func scanInts(n int) []int {
	l := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
	}

	return l
}

func scanInts64(n int64) []int64 {
	l := make([]int64, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	return l
}

func scanBool() bool {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v == 1
}

func scanBools(n int64) []bool {
	l := make([]bool, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		l[i] = v == 1
	}

	return l
}

func main() {
	n := scanInt()

	m := [100000]int{}

	for i := 0; i < n; i++ {
		r := scanInt()
		for j := 0; j < r; j++ {
			num := scanInt()
			m[num]++
		}
	}

	for i := 1; i < len(m); i++ {
		if m[i] == n {
			fmt.Println(i)
		}
	}
}

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

	return -a
}

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

	return b
}