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


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

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

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
}


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
}

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 (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        w = make([]int, 0)
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            continue
        }
        if n == 2 {
            fmt.Println(1)
            continue
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

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

	ans := 0
	for val := 1; val <= 2*n; val++ {

		used := make([]bool, n)
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if used[j] {
					continue
				}
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		var curAns int = 0
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

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

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

// only when n > 1
func match(dict []int, sorted []int) int {
	// Fetching the maximum possible weight of a team
	partNum := len(sorted)
	maxWeight := sorted[partNum-1] + sorted[partNum-2]

	var maxTeamNum = 0
	for teamWeight := maxWeight; teamWeight > 1; teamWeight-- {
		counter := 0
		var lighter int
		for heavier := len(dict); heavier > teamWeight/2; heavier-- {
			lighter = teamWeight - heavier
			if lighter < 1 {
				continue
			}
			counter += min(dict[heavier-1], dict[lighter-1])
		}
		if teamWeight&1 == 0 {
			counter += dict[(teamWeight/2)-1] / 2
		}
		if maxTeamNum < counter {
			maxTeamNum = counter
		}
	}
	return maxTeamNum
}

func solver(weights []int) int {
	if len(weights) < 2 {
		return 0
	}

	sorted := make([]int, len(weights))
	copy(sorted, weights)
	sort.Slice(sorted, func(i, j int) bool {
		return sorted[i] < sorted[j]
	})

	maxWeight := sorted[len(sorted)-1]
	inds := make([]int, maxWeight, maxWeight+1)
	dict := make([]int, maxWeight)
	for i := range inds {
		inds[i] = sort.SearchInts(sorted, i+1)
	}
	inds = append(inds, len(sorted))
	for i := range dict {
		dict[i] = inds[i+1] - inds[i]
	}
	return match(dict, sorted)
}

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

func main() {
	defer writer.Flush()
	var t int
	text, _ := reader.ReadString('\n')
	text = strings.TrimSpace(text)
	t, _ = strconv.Atoi(text)

	for i := 0; i < t; i++ {
		_, _ = reader.ReadString('\n')
		text, _ = reader.ReadString('\n')
		split := strings.Fields(text)
		arr := make([]int, len(split))
		for i, v := range split {
			arr[i], _ = strconv.Atoi(v)
		}
		fmt.Fprintln(writer, solver(arr))
	}
}

func test() {
	arr := []int{1, 1, 3, 4, 2, 2}
	fmt.Println(solver(arr))
}

package main

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

const (
	MaxN int = 50 + 5
	MaxWeight int = 100
)

var (
	read = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
	weight [MaxN]int
	vis [MaxN]bool
)

func main() {
	defer write.Flush()
	var t int
	fmt.Fscan(read, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(read, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(read, &weight[i])
		}
		var ans int = 0
		for w := 2; w <= MaxWeight; w++ {
			for i := 0; i < n; i++ {
				vis[i] = false
			}
			var tempAns int = 0
			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					if i != j && !vis[i] && !vis[j] && weight[i]+weight[j] == w {
						vis[i], vis[j] = true, true
						tempAns++
					}
				}
			}
			if ans < tempAns {
				ans = tempAns
			}
		}
		fmt.Fprintln(write, ans)
	}
}

package main

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

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

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		var n,cur int
		Fscan(in, &n)
		a:=make([]int,n+1)
		pos:=make([]int,2*n+1)

		for i:=0;i<n;i++{
			Fscan(in,&cur)
			a[cur]++
		}

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

		for i:=0;i<=n;i++{
			pos[2*i]+=a[i]/2
			for j:=i+1;j<=n;j++{
				pos[i+j]+=min(a[i],a[j])
			}
		}

		ans:=0
		for i:=0;i<=2*n;i++{
			if ans<pos[i]{
				ans=pos[i]
			}
		}

		Fprintln(out,ans)
	}
}

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

package main

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

/*
5
5
1 2 3 4 5
8
6 6 6 6 6 6 8 8
8
1 2 2 1 2 1 1 2
3
1 3 3
6
1 1 3 4 2 2

2
3
4
1
2
*/

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

	var T, N, S int
	for Fscan(in, &T); T > 0; T-- {
		target := make(map[int]int)
		Fscan(in, &N)

		for tmp := N; tmp > 0; tmp-- {
			Fscan(in, &S)
			target[S]++
		}
		sum := 0
		for i := 2 * N; i >= 2; i-- {
			var numOne, numTwo int
			var ok bool
			var tmp int
			for j := 1; j <= i/2; j++ {
				numOne, ok = target[j]
				if !ok {
					continue
				}

				numTwo, ok = target[i-j]
				if !ok {
					continue
				}

				if j == i-j {
					tmp += numOne / 2

				} else {
					tmp += Bmin(numOne, numTwo)
				}

			}

			sum = Bmax(sum, tmp)
		}

		Fprintln(out, sum)

	}
}

func Bmax(i, j int) int {
	if i < j {
		return j
	}
	return i
}

func Bmin(i, j int) int {
	if i < j {
		return i
	}
	return j
}

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

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

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

	var best int

	for s := 2; s <= 2*n; s++ {
		var cnt int
		for i, j := 0, n-1; i < j; {
			if W[i]+W[j] == s {
				cnt++
				i++
				j--
			} else if W[i]+W[j] < s {
				i++
			} else {
				j--
			}
		}
		if cnt > best {
			best = cnt
		}
	}

	return best
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.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 suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.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
}

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

func sol(n int64, w []int64) int64 {
	sort.Slice(w, func(idx1, idx2 int) bool {
		return w[idx1] < w[idx2]
	})
	utw := map[int64]bool{}
	for i := range w {
		for j := i+1; j < len(w); j++ {
			utw[w[i] + w[j]] = true
		}
	}
	// printf("utw %v\n", utw)
	ret := int64(0)
	for i := range utw {
		curr := int64(0)
		l := int64(0)
		r := n-1
		for l < r {
			if w[l] + w[r] == i {
				curr++
				l++
				r--
				continue
			}
			if w[l] + w[r] < i {
				l++
				continue
			}
			if w[l] + w[r] > i {
				r--
				continue
			}
		}
		ret = max(ret, curr)
	}
	return ret
}

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 i := 0; i < t; i++ {

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		for s := 1; s <= 2*n; s++ {
			cnt := 0
			l, r := 0, n-1
			for l < r {
				if a[l]+a[r] == s {
					l, r = l+1, r-1
					cnt++
				} else if a[l]+a[r] > s {
					r--
				} else {
					l++
				}
			}
			result = max(result, cnt)
		}

		fmt.Fprintln(out, result)

	}

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return 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 b
    }
    return a
}

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

        cnt := make([]int, 2 * n + 1)
        for i := 0; i < n; i++ {
            cnt[w[i]]++
        }

        maxTotal := 0
        for s := 2; s <= 2 * n; s++ {
            total := 0
            for i := 1; i < s / 2; i++ {
                total += min(cnt[i], cnt[s - i])
            }
            if s % 2 == 0 {
                total += cnt[s / 2] / 2
            } else {
                total += min(cnt[s / 2], cnt[s / 2 + 1])
            }
            maxTotal = max(maxTotal, total)
        }

        fmt.Println(maxTotal)

        t--
    }
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	for t := io.NextInt(); t > 0; t-- {
		n := io.NextInt()
		w := io.NextInts(n)
		f := make([]int, n+1)
		for _, x := range w {
			f[x]++
		}
		ans := 0
		for s := 2; s <= 2*n; s++ {
			c := 0
			for i := 1; i < s-i; i++ {
				if s-i <= n {
					c += min(f[i], f[s-i])
				}
			}
			if s%2 == 0 {
				c += f[s/2] / 2
			}
			ans = max(ans, c)
		}
		io.Println(ans)
	}
}

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

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, f.c[0])
	}
	return string(s)
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(' ', x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 10*1024*1024)
	scanner.Split(bufio.ScanWords)

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

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

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(max)
	}
}

package main

import (
	"fmt"
)

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

	for ; t > 0; t-- {
		var n int
		fmt.Scan(&n)

		w := [110]int{}
		w_c := [110]int{}

		for i := 0; i < n; i++ {
			fmt.Scan(&w[i])
			w_c[w[i]]++
		}

		ans := 0
		for s := 2 * n; s > 0; s-- {
			w_c2 := w_c

			cnt := 0
			for i := 0; i < n; i++ {
				a := w[i]
				b := s - a

				if w_c2[a] <= 0 {
					continue
				}

				if a == b {
					if w_c2[a] >= 2 {
						cnt++
						w_c2[b] -= 2
					}
				} else if b > 0 && w_c2[b] > 0 {
					cnt++
					w_c2[a]--
					w_c2[b]--
				}
			}

			if cnt > ans {
				ans = cnt
			}
		}

		fmt.Println(ans)
	}
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

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

	var best int

	for i := 0; i < n; i++ {
		for j := n - 1; j > i; j-- {
			s := W[i] + W[j]
			cnt := 1
			if j-i+1 < 2*best {
				break
			}
			for a, b := 1, j-1; a < b; {
				if W[a]+W[b] == s {
					cnt++
					a++
					b--
				} else if W[a]+W[b] < s {
					a++
				} else {
					b--
				}
			}
			if cnt > best {
				best = cnt
			}
		}
	}

	return best
}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

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

	var best int
	for j := n - 1; j > 0; j-- {
		s := W[0] + W[j]
		cnt := 1
		for a, b := 1, j-1; a < b; {
			if W[a]+W[b] == s {
				cnt++
				a++
				b--
			} else if W[a]+W[b] < s {
				a++
			} else {
				b--
			}
		}
		if cnt > best {
			best = cnt
		}
	}

	return best
}

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 i := 0; i < t; i++ {

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		l, r := 0, n-1

		for l+1 < r-1 {

			cnt := 1
			tmpL, tmpR := l, r
			for tmpL+1 < tmpR-1 {
				if a[tmpL]+a[tmpR] != a[tmpL+1]+a[tmpR-1] {
					break
				}
				tmpL, tmpR = tmpL+1, tmpR-1
				cnt++
			}

			result = max(result, cnt)

			if a[l]+a[r] >= a[l+1]+a[r-1] {
				r--
			} else {
				l++
			}

		}

		fmt.Fprintln(out, result)

	}

}

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

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 i := 0; i < t; i++ {

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

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

		sort.Ints(a)

		result := 0
		if n > 1 {
			result = 1
		}

		for s := 1; s < 2*n; s++ {
			cnt := 0
			l, r := 0, n-1
			for l < r {
				if a[l]+a[r] == s {
					l, r = l+1, r-1
					cnt++
				} else if a[l]+a[r] > s {
					r--
				} else {
					l++
				}
			}
			result = max(result, cnt)
		}

		fmt.Fprintln(out, result)

	}

}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 10*1024*1024)
	scanner.Split(bufio.ScanWords)

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

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

		sort.Ints(a)

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(max)

	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 10*1024*1024)
	scanner.Split(bufio.ScanWords)

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

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

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(b)

		fmt.Println(max)

	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buffer := make([]byte, 1024*1024)
	scanner.Buffer(buffer, 10*1024*1024)
	scanner.Split(bufio.ScanWords)

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

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

		return b
	}

	for t := input(); t > 0; t-- {
		n := input()
		a := make([]int, n+1)
		b := make([]int, 2*n+1)

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

		for s := 2; s <= 2*n; s++ {
			for i := 1; i <= s/2; i++ {
				if s-i <= n {
					if i == s-i {
						b[s] += a[i] / 2
					} else {
						b[s] += min(a[i], a[s-i])
					}
				}
			}
		}

		max := b[0]

		for i := range b {
			if max < b[i] {
				max = b[i]
			}
		}

		fmt.Println(b)
	}
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        w = make([]int, 0)
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 0
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
    "fmt"
    "sort"
)

func main() {
    var t, n, ans, maxans, x int
    var w []int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n)
        maxans = 0
        for i := 0; i < n; i++ {
            fmt.Scan(&x)
            w = append(w, x)
        }
        sort.Ints(w)
        if n == 1 {
            fmt.Println(0)
            return
        }
        if n == 2 {
            fmt.Println(1)
            return
        }
        maxw := w[n - 1] + w[n - 2]
        for i := 2; i <= maxw; i++ {
            ans = 0
            j := 1
            k := n - 1
            for ; j < k; {
                if w[j] + w[k] == i {
                    ans++
                    j++
                    k--
                } else if w[j] + w[k] > i {
                    k--
                } else {
                    j++
                }
            }
            if maxans < ans {
                maxans = ans
            }
        }
        fmt.Println(maxans)
    }
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

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

	ans := 0
	for val := 1; val <= 100; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

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

	ans := 0
	s := 0
	for val := 1; val <= 50; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			var t int = 0
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					t = 1
					break
				}
			}
			curAns += t
		}
		if ans < curAns {
			ans = curAns
			s = val
		}
	}
	fmt.Println(s)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

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

	ans := 0
	for val := 1; val <= 50; val++ {
		used := make([]bool, n)
		var curAns int = 0
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val {
					used[j] = true
					break
				}
			}
		}
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}

package main

import (
	"fmt"
)

func nxt() int {
	var x int
	fmt.Scan(&x)
	return x
}

func ok() {
	fmt.Println("YES")
}

func no() {
	fmt.Println("NO")
}

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

	ans := 0
	for val := 3; val <= 3; val++ {

		used := make([]bool, n)
		for i := 0; i < n; i++ {
			if used[i] {
				continue
			}
			for j := i + 1; j < n; j++ {
				if a[i]+a[j] == val && !used[j] {
					used[j] = true
					break
				}
			}
		}
		var curAns int = 0
		for _, v := range used {
			if v {
				curAns++
			}
		}
		if ans < curAns {
			ans = curAns
		}
	}
	fmt.Println(ans)

}

func main() {
	var t int = nxt()
	for t > 0 {
		t--
		solve()
	}
	return
}


package main

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

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

	var n, w int
	Fscan(in, &n)
	if n&1 == 0 {
		Fprint(out, "NO")
		return
	}
	Fprintln(out, "YES")
	g := make([][]int, n+1)
	for v := 1; v <= n; v++ {
		if Fscan(in, &w); w > 0 {
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
	}
	size := make([]int, n+1)
	var f func(v, fa int) int
	f = func(v, fa int) int {
		sz := 1
		for _, w := range g[v] {
			if w != fa {
				sz += f(w, v)
			}
		}
		size[v] = sz
		return sz
	}
	f(1, 0)
	var f2 func(v, fa int)
	f2 = func(v, fa int) {
		for _, w := range g[v] {
			if w != fa && size[w]&1 == 0 {
				f2(w, v)
			}
		}
		Fprintln(out, v)
		for _, w := range g[v] {
			if w != fa && size[w]&1 > 0 {
				f2(w, v)
			}
		}
	}
	f2(1, 0)
}

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

package main

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

var n int
var graph [][]int
var s []int
var visited []int

func dfs1(v, p int) int {
	s[v] = 1
	for _, i := range graph[v] {
		if i != p {
			s[v] += dfs1(i, v)
		}
	}
	return s[v]
}

func dfs2(v, p int) {
	for _, i := range graph[v] {
		if i != p && s[i] % 2 == 0 {
			dfs2(i, v)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if i != p && s[i] % 2 == 1 {
			dfs2(i, v)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("NO\n")
		return
	}
	graph = make([][]int, n + 1)
	s = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("YES\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
	}

	dfs1(1, 0)
	dfs2(1, 0)
}

package main

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

var n int
var graph [][]int
var deg []int
var visited []int

func dfs(v int) {
	for _, i := range graph[v] {
		if deg[i] % 2 == 0 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if deg[i] % 2 == 1 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("No\n")
		return
	}
	graph = make([][]int, n + 1)
	deg = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("Yes\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
		deg[i + 1]++
		deg[tmp]++
	}
	root := 0
	for i := 1; i <= n; i++ {
		if deg[i] % 2 == 0 {
			root = i
		}
	}
	visited[root] = 1
	dfs(root)
}

package main

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

var n int
var graph [][]int
var deg []int
var visited []int

func dfs(v int) {
	for _, i := range graph[v] {
		if deg[i] % 2 == 0 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
	fmt.Printf("%d\n", v)
	for _, i := range graph[v] {
		if deg[i] % 2 == 1 && visited[i] == 0 {
			visited[i] = 1
			dfs(i)
		}
	}
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	if n % 2 == 0 {
		fmt.Printf("NO\n")
		return
	}
	graph = make([][]int, n + 1)
	deg = make([]int, n + 1)
	visited = make([]int, n + 1)
	fmt.Printf("YES\n")
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Fscanf(stdin, "%d", &tmp)
		if tmp == 0 {
			continue
		}
		graph[i + 1] = append(graph[i + 1], tmp)
		graph[tmp] = append(graph[tmp], i + 1)
		deg[i + 1]++
		deg[tmp]++
	}
	root := 0
	for i := 1; i <= n; i++ {
		if deg[i] % 2 == 0 {
			root = i
		}
	}
	visited[root] = 1
	dfs(root)
}