package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	t := nextInt()
	for ti := 0; ti < t; ti++ {
		n := nextInt()
		r := map[int]int{}
		maxE := 0
		for ni := 0; ni < n; ni++ {
			e := nextInt()
			_, ok := r[e]
			if !ok {
				r[e] = 0
			}
			r[e]++
			maxE = max(maxE, e)
		}
		groups := 0
		for i := 1; i <= maxE; i++ {
			_, ok := r[i]
			if !ok {
				continue
			}
			groups += r[i] / i
			_, ok2 := r[i+1]
			if !ok2 {
				r[i+1] = r[i] % i
			} else {
				r[i+1] += r[i] % i
			}
		}
		fmt.Println(groups)
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

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

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

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

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		e := ScanIntSlice(n)

		P(solv(n, e))
	}

	close(O)
	oWg.Wait()
}

func solv(n int, e []int) int {
	c, l := 0, 0
	sort.Ints(e)

	for i := 0; i < n; i++ {
		if e[i] <= (i - l + 1) {
			c++
			l = i + 1
		}
	}

	return c
}

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

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

func init() {
	P = fmt.Println

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

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

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

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

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

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

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

package main

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

func max(var1 int,var2 int)  int  {
	if var1 > var2 {
		return var1
	}
	return var2
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var TestCases int
	fmt.Fscan(in,&TestCases)
	for TestCase:=0;TestCase<TestCases;TestCase++{
		var Length int
		fmt.Fscan(in,&Length)
		var members =make([]int,Length)
		for index:=0;index<Length;index++ {
			fmt.Fscan(in,&members[index])
		}
		sort.Ints(members)
//		PreviousGroup:=0
		TotalPossibleGroups:=0
		PreviousGroupSize:=0
		for index:=0;index<Length;index++{
			group:=members[index]
			if PreviousGroupSize+1>=group {
//				PreviousGroup=0
				TotalPossibleGroups++
				PreviousGroupSize=0
			}else {
//				PreviousGroup = group
				PreviousGroupSize++
			}
		}
		fmt.Println(TotalPossibleGroups)
	}

}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(r, &n)
		e := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &e[i])
		}
		sort.Ints(e)
		ans := 0
		size := 0
		for i := 0; i < n; i++ {
			size++
			if size == e[i] {
				size = 0
				ans++
			}
		}
		fmt.Fprintln(w, ans)
	}

}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

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

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

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

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

func sol(e []int64) int64 {
	sort.Slice(e, func(a, b int) bool {
		return e[a] < e[b]
	})
	groups := int64(0)
	currN := int64(0)
	toFill := int64(0)
	for i := range e {
		toFill = e[i]
		currN++
		if currN == toFill {
			groups++
			currN = 0
			toFill = 0
		}
	}
	return groups
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		sort.Ints(a)
		ans := 0
		curNum := 0
		for i := 0; i < n; i++ {
			curNum++
			if a[i] <= curNum {
				ans++
				curNum = 0
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

// @problemURL https://codeforces.com/contest/1355/problem/B
package main

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

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

func ni(s *bufio.Scanner) int {
	return atoi(nt(s))
}

func atoi(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var in = bufio.NewReader(os.Stdin)
	s := bufio.NewScanner(in)
	s.Split(bufio.ScanWords)

	// Code
	T := ni(s)
	for tt := 0; tt < T; tt++ {
		n := ni(s)
		ar := make([]int, n)
		for i := 0; i < n; i++ {
			ar[i] = ni(s)
		}
		sort.Ints(ar)
		var ans, i int

		for i < n {
			groupSize := 1
			need := ar[i]
			i++
			for i < n && need > groupSize {
				groupSize++
				need = ar[i]
				i++
			}

			if groupSize >= need {
				ans++
			}

		}
		fmt.Println(ans)
	}
}

package main

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

var sc = WordScanner()
var memory [2000000]int
var memory2 [2000000]int

func solve() int {
	n := sc.Int()
	es := memory[:n]
	dp := memory2[:n]
	for i := range es {
		es[i] = sc.Int()
		dp[i] = 0
	}
	sort.Ints(es)
	var ans int
	for i := range es {
		if es[i] == i + 1 {
			dp[i] = 1
		} else if es[i] < i + 1 {
			dp[i] = 1 + dp[i - es[i]]
		}
		if ans < dp[i] {
			ans = dp[i]
		}
	}
	return ans
}

func main() {
	t := sc.Int()
	for i := 1; i <= t; i++ {
		fmt.Println(solve())
	}
}

type Scanner struct {
	*bufio.Scanner
}

func WordScanner() Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Scanner{sc}
}

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

func (sc Scanner) Int() int {
	i, _ := strconv.Atoi(sc.Text())
	return i
}

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

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

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

func main() {
	var (
		T int
	)

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

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

	rem := 0
	ans := 0
	for i := 1; i < len(refs); i++ {
		if refs[i] == 0 {
			continue
		}
		ans += (refs[i] + rem) / i
		rem = (refs[i] + rem) % i
	}

	return ans
}

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t int

	n int
	A []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)

		solve()
	}

	stdout.Flush()
}

func solve() {
	sort.Sort(sort.IntSlice(A))

	comp, cnts := RunLengthEncoding(A)
	resi := 0
	ans := 0
	for i := 0; i < len(comp); i++ {
		val, cnt := comp[i], cnts[i]

		ans += (cnt + resi) / val
		resi = (cnt + resi) % val
	}

	PrintfBufStdout("%d\n", ans)
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		e := ScanInts(n)

		P(solv(n, e))
	}

	out.Flush()
}

func solv(n int, e []int) int {
	c, l := 0, 0
	sort.Ints(e)

	for i := 0; i < n; i++ {
		if e[i] <= (i - l + 1) {
			c++
			l = i + 1
		}
	}

	return c
}

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

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

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

func PS(args ...interface{}) {
	print(" ", args...)
	out.WriteByte('\n')
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case int64:
			str = strconv.FormatInt(v, 10)
		case string:
			str = v
		}
		out.WriteString(str + seperator)
	}
}

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

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

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

package main

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

func max(var1 int,var2 int)  int  {
	if var1 > var2 {
		return var1
	}
	return var2
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var TestCases int
	fmt.Fscan(in,&TestCases)
	for TestCase:=0;TestCase<TestCases;TestCase++{
		var Length int
		fmt.Fscan(in,&Length)
		var members =make([]int,Length)
		for index:=0;index<Length;index++ {
			fmt.Fscan(in,&members[index])
		}
		sort.Ints(members)
//		PreviousGroup:=0
		TotalPossibleGroups:=0
		PreviousGroupSize:=0
		for index:=0;index<Length;index++{
			group:=members[index]
			if PreviousGroupSize+1>=group {
//				PreviousGroup=0
				TotalPossibleGroups++
				PreviousGroupSize=0
			}else {
//				PreviousGroup = group
				PreviousGroupSize++
			}
		}
		println(TotalPossibleGroups)
	}

}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

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

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

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

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

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

func sol(e []int64) int64 {
	sort.Slice(e, func(a, b int) bool {
		return e[a] < e[b]
	})
	groups := int64(0)
	currN := int64(0)
	toFill := int64(0)
	for i := len(e)-1; i >= 0; i-- {
		if toFill == 0 {
			toFill = e[i]
		}
		currN++
		if currN == toFill {
			groups++
			currN = 0
			toFill = 0
		}
	}
	return groups
}


package main

import (
	"fmt"
	"math"
)

type (
	graph struct {
		source int
		sink   int
		edges  map[int]map[int]int
		caps   map[int]map[int]int
	}
)

func initGraph(n int) *graph {
	g := &graph{source: 0, sink: 2*n + 1}
	g.edges = map[int]map[int]int{}
	g.caps = map[int]map[int]int{}
	// g.edges = make([]map[int]int, 2*n+2)
	// g.caps = make([]map[int]int, 2*n+2)
	// for i := 0; i < 2*n+2; i++ {
	// 	g.edges[i] = map[int]int{}
	// 	g.caps[i] = map[int]int{}
	// }
	return g
}

func (g *graph) addEdge(src, dst, value int) {

	if _, exist := g.edges[src]; !exist {
		g.edges[src] = map[int]int{}
	}

	if _, exist := g.edges[dst]; !exist {
		g.edges[dst] = map[int]int{}
	}

	if _, exist := g.caps[src]; !exist {
		g.caps[src] = map[int]int{}
	}

	g.edges[src][dst] = value
	g.edges[dst][src] = 0
	g.caps[src][dst] = value
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		g.addEdge(g.source, i+1, a[i])
		g.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		g.addEdge(i+n+1, g.sink, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// fmt.Println(u, v)
		g.addEdge(u, v+n, a[u-1])
		g.addEdge(v, u+n, a[v-1])
	}
	// fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO")
		return
	}

	maxflow := 0
	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		// fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			// fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func bfs(g *graph) (map[int]int, bool) {

	if g == nil {
		return nil, false
	}

	// visited := map[int]bool{}
	// dist := make([]int, len(g.edges))
	dist := map[int]int{}

	queue := []int{}
	// visited[g.source] = true
	dist[g.source] = 1
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]

		if len(g.edges[tmp]) == 0 {
			continue
		}

		for enode, flow := range g.edges[tmp] {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				// fmt.Println("dist:", dist)
				return dist, true
			}

			if dist[enode] != 0 || flow <= 0 {
				continue
			}

			if dist[enode] == 0 && flow > 0 {
				// visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist map[int]int, node, max int) int {

	if g == nil {
		return 0
	}

	if node == g.sink {
		return max
	}

	if len(g.edges[node]) == 0 {
		return 0
	}

	for enode, flow := range g.edges[node] {
		if dist[enode] == dist[node]+1 && flow > 0 {
			value := dfs(g, dist, enode, min(flow, max))
			// fmt.Println(value)
			if value == 0 {
				continue
			}

			if value > 0 {
				g.edges[node][enode] -= value
				g.edges[enode][node] += value
			}
			return value
		}
	}

	return 0
}

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

package main

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

func ReadLine() (string, error) {
	line, err := bufio.NewReader(os.Stdin).ReadString('\n')
	if err != nil {
		// fmt.Println("readline err:", line, err)
		return line, err
	}
	return strings.TrimSpace(string(line)), nil
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	// line, _ := ReadLine()
	// parts := strings.Split(line, " ")
	// n, _ := strconv.Atoi(parts[0])
	// m, _ := strconv.Atoi(parts[1])
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0
	// fmt.Println("input n m", n, m)
	// fmt.Println("parts n m", parts)

	f := NewFlow(2*n + 2)
	// fmt.Println("new flow")
	ns := 0
	ne := 2*n + 1

	// format := ""
	// params := make([]interface{}, n)
	// for i := 0; i < n; i++ {
	// 	format += "%d"
	// 	if i != n-1 {
	// 		format += " "
	// 	} else {
	// 		format += "\n"
	// 	}
	// 	params = append(params, &a[i])
	// }
	// fmt.Scanf(format, params...)
	// line, _ = ReadLine()
	// parts = strings.Split(line, " ")
	// fmt.Println("parts a", parts)
	// for i := 0; i < n; i++ {
	// 	a[i], _ = strconv.Atoi(parts[i])
	// 	fmt.Println("a[i]:", i, a[i])
	// }
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		f.addEdge(ns, i+1, a[i])
		f.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)
	// fmt.Println("add edges a")

	// format = ""
	// params = make([]interface{}, n)
	// for i := 0; i < n; i++ {
	// 	format += "%d"
	// 	if i != n-1 {
	// 		format += " "
	// 	} else {
	// 		format += "\n"
	// 	}
	// 	params = append(params, &b[i])
	// }
	// fmt.Scanf(format, params...)
	// line, _ = ReadLine()
	// parts = strings.Split(line, " ")
	// for i := 0; i < n; i++ {
	// b[i], _ = strconv.Atoi(parts[i])
	// }
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		f.addEdge(i+n+1, ne, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)
	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// line, _ = ReadLine()
		// parts = strings.Split(line, " ")
		// u, _ := strconv.Atoi(parts[0])
		// v, _ := strconv.Atoi(parts[1])
		f.addEdge(u, v+n, a[u-1])
		f.addEdge(v, u+n, a[v-1])
	}
	// fmt.Println("input edge")
	if sa != sb {
		fmt.Println("NO")
		return
	}
	maxflow := f.EK(ns, ne)
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(f.flow[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

type flow struct {
	volume []map[int]int
	flow   []map[int]int
}

func NewFlow(n int) *flow {
	f := new(flow)
	f.volume = make([]map[int]int, n)
	for i := range f.volume {
		f.volume[i] = make(map[int]int)
	}
	f.flow = make([]map[int]int, n)
	for i := range f.flow {
		f.flow[i] = make(map[int]int)
	}
	return f
}

func (f *flow) addEdge(u, v, c int) {
	// fmt.Println("add edge", u, v, c)
	f.volume[u][v] = c
	f.flow[u][v] = 0
}

func (f *flow) EK(start, end int) int {
	maxflow := 0

	for {
		nodeFlow := make([]int, len(f.volume))
		nodeFlow[start] = math.MaxInt32

		pre := make([]int, len(f.volume))

		queue := make([]int, 0)
		queue = append(queue, start)
		for len(queue) > 0 {
			u := queue[0]
			queue = queue[1:]
			for v, ff := range f.flow[u] {
				c := f.volume[u][v]
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, "flow[u][v]:", f.flow[u][v], "vol[u][v]:", c)
				if nodeFlow[v] != 0 || c <= ff {
					// 节点被标记 或 边流量用尽，跳过
					continue
				}

				nodeFlow[v] = c - ff
				if nodeFlow[u] < nodeFlow[v] {
					nodeFlow[v] = nodeFlow[u]
				}
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, nodeFlow[v])

				pre[v] = u
				queue = append(queue, v)
			}
		}
		// fmt.Println("nodeFlow[end]:", nodeFlow[end])
		if nodeFlow[end] == 0 {
			return maxflow
		}
		// fmt.Println("pre:", pre)
		for u := end; u != start; u = pre[u] {
			f.flow[pre[u]][u] += nodeFlow[end]
			f.flow[u][pre[u]] -= nodeFlow[end]
		}
		// fmt.Println("flow:")
		// for u, m := range f.flow {
		// 	for v, ff := range m {
		// 		fmt.Println(u, v, ff)
		// 	}
		// }
		// fmt.Println("")
		maxflow += nodeFlow[end]
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF546E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var N, m, v, w, s, maxFlow int
	Fscan(in, &N, &m)
	st, end, n := 2*N, 2*N+1, 2*N+2
	type nb struct{ to, rid, cap int }
	g := make([][]nb, n)
	addEdge := func(from, to, cap int) {
		g[from] = append(g[from], nb{to, len(g[to]), cap})
		g[to] = append(g[to], nb{from, len(g[from]) - 1, 0})
	}
	for i := 0; i < N; i++ {
		Fscan(in, &v)
		addEdge(st, i, v)
		s += v
	}
	sum := s
	for i := N; i < 2*N; i++ {
		Fscan(in, &v)
		addEdge(i, end, v)
		s -= v
	}
	if s != 0 {
		Fprint(out, "NO")
		return
	}
	for i := 0; i < N; i++ {
		addEdge(i, i+N, inf)
	}
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		addEdge(v, w+N, inf)
		addEdge(w, v+N, inf)
	}

	dep := make([]int, n)
	bfs := func() bool {
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		q := []int{st}
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			for _, e := range g[v] {
				if w := e.to; e.cap > 0 && dep[w] < 0 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep[end] >= 0
	}
	var it []int
	var dfs func(int, int) int
	dfs = func(v, minF int) int {
		if v == end {
			return minF
		}
		for ; it[v] < len(g[v]); it[v]++ {
			e := &g[v][it[v]]
			if w := e.to; e.cap > 0 && dep[w] > dep[v] {
				if f := dfs(w, min(minF, e.cap)); f > 0 {
					e.cap -= f
					g[w][e.rid].cap += f
					return f
				}
			}
		}
		return 0
	}
	for bfs() {
		it = make([]int, n)
		for {
			if f := dfs(st, inf); f > 0 {
				maxFlow += f
			} else {
				break
			}
		}
	}
	if maxFlow < sum {
		Fprint(out, "NO")
		return
	}
	Fprintln(out, "YES")
	for _, es := range g[:N] {
		ans := make([]int, N)
		for _, e := range es {
			if e.to >= N && e.to < 2*N {
				ans[e.to-N] = g[e.to][e.rid].cap
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	const inf int = 1e9
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var N, m, v, w, s, maxFlow int
	Fscan(in, &N, &m)
	st, end, n := 2*N, 2*N+1, 2*N+2
	type nb struct{ to, rid, cap int }
	g := make([][]nb, n)
	addEdge := func(from, to, cap int) {
		g[from] = append(g[from], nb{to, len(g[to]), cap})
		g[to] = append(g[to], nb{from, len(g[from]) - 1, 0})
	}
	for i := 0; i < N; i++ {
		Fscan(in, &v)
		addEdge(st, i, v)
		s += v
	}
	sum := s
	for i := N; i < 2*N; i++ {
		Fscan(in, &v)
		addEdge(i, end, v)
		s -= v
	}
	if s != 0 {
		Fprint(out, "NO")
		return
	}
	for i := 0; i < N; i++ {
		addEdge(i, i+N, inf)
	}
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		addEdge(v, w+N, inf)
		addEdge(w, v+N, inf)
	}

	dep := make([]int, n)
	bfs := func() bool {
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		q := []int{st}
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			for _, e := range g[v] {
				if w := e.to; e.cap > 0 && dep[w] < 0 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep[end] >= 0
	}
	var it []int
	var dfs func(int, int) int
	dfs = func(v, minF int) int {
		if v == end {
			return minF
		}
		for ; it[v] < len(g[v]); it[v]++ {
			e := &g[v][it[v]]
			if w := e.to; e.cap > 0 && dep[w] > dep[v] {
				if f := dfs(w, min(minF, e.cap)); f > 0 {
					e.cap -= f
					g[w][e.rid].cap += f
					return f
				}
			}
		}
		return 0
	}
	for bfs() {
		it = make([]int, n)
		for {
			if f := dfs(st, inf); f > 0 {
				maxFlow += f
			} else {
				break
			}
		}
	}
	if maxFlow < sum {
		Fprint(out, "NO")
		return
	}
	Fprintln(out, "YES")
	for _, es := range g[:N] {
		ans := make([]int, N)
		for _, e := range es {
			if w := e.to; N <= w && w < 2*N {
				ans[w-N] = g[w][e.rid].cap
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF546E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9

	var N, m, v, w, s, maxFlow int
	Fscan(in, &N, &m)
	st, end, n := 2*N, 2*N+1, 2*N+2
	type nb struct{ to, rid, cap int }
	g := make([][]nb, n)
	addEdge := func(from, to, cap int) {
		g[from] = append(g[from], nb{to, len(g[to]), cap})
		g[to] = append(g[to], nb{from, len(g[from]) - 1, 0})
	}
	for i := 0; i < N; i++ {
		Fscan(in, &v)
		addEdge(st, i, v)
		s += v
	}
	sum := s
	for i := N; i < 2*N; i++ {
		Fscan(in, &v)
		addEdge(i, end, v)
		s -= v
	}
	if s != 0 {
		Fprint(out, "NO")
		return
	}
	for i := 0; i < N; i++ {
		addEdge(i, i+N, inf)
	}
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		addEdge(v, w+N, inf)
		addEdge(w, v+N, inf)
	}

	d := make([]int, n)
	for i := range d {
		d[i] = -1
	}
	d[end] = 0
	cd := make([]int, n+1)
	q := []int{end}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		cd[d[v]]++
		for _, e := range g[v] {
			if w := e.to; d[w] < 0 {
				d[w] = d[v] + 1
				q = append(q, w)
			}
		}
	}

	iter := make([]int, n)
	type pair struct{ v, i int }
	fa := make([]pair, n)
o:
	for v := st; d[st] < n; {
		if v == end {
			minF := inf
			for v := end; v != st; {
				p := fa[v]
				if c := g[p.v][p.i].cap; c < minF {
					minF = c
				}
				v = p.v
			}
			for v := end; v != st; {
				p := fa[v]
				e := &g[p.v][p.i]
				e.cap -= minF
				g[v][e.rid].cap += minF
				v = p.v
			}
			maxFlow += minF
			v = st
		}
		for i := iter[v]; i < len(g[v]); i++ {
			e := g[v][i]
			if w := e.to; e.cap > 0 && d[w] < d[v] {
				fa[w] = pair{v, i}
				iter[v] = i
				v = w
				continue o
			}
		}
		if cd[d[v]] == 1 {
			break
		}
		cd[d[v]]--
		minD := n - 1
		for _, e := range g[v] {
			if e.cap > 0 && d[e.to] < minD {
				minD = d[e.to]
			}
		}
		d[v] = minD + 1
		cd[d[v]]++
		iter[v] = 0
		if v != st {
			v = fa[v].v
		}
	}
	if maxFlow < sum {
		Fprint(out, "NO")
		return
	}
	Fprintln(out, "YES")
	for _, es := range g[:N] {
		ans := make([]int, N)
		for _, e := range es {
			if w := e.to; N <= w && w < 2*N {
				ans[w-N] = g[w][e.rid].cap
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

const infinity = 1000000000

func slice2D(n int) [][]int {
	res := make([][]int, n)
	for i := range res {
		res[i] = make([]int, n)
	}
	return res
}

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

	}
	return b
}

func dfs(v, t, w int, cap, flow [][]int, was []bool) int {
	if v == t {
		return w
	}
	if was[v] {
		return 0
	}
	was[v] = true
	for u := range was {
		if flow[v][u] >= cap[v][u] {
			continue
		}
		nw := dfs(u, t, min(w, cap[v][u]-flow[v][u]), cap, flow, was)
		if nw > 0 {
			flow[v][u] += nw
			flow[u][v] -= nw
			return nw
		}
	}
	return 0
}

func main() {
	n := nextInt()
	m := nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = nextInt()
	}
	cap := slice2D(2*n + 2)
	flow := slice2D(2*n + 2)
	s := 2 * n
	t := 2*n + 1
	for i := 0; i < m; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		cap[u][v+n] = infinity
		cap[v][u+n] = infinity
	}
	var sumA, sumB int
	for i := 0; i < n; i++ {
		cap[s][i] = a[i]
		cap[i+n][t] = b[i]
		cap[i][i+n] = infinity
		sumA += a[i]
		sumB += b[i]
	}
	if sumA != sumB {
		fmt.Println("NO")
		return
	}
	flowSize := 0
	was := make([]bool, 2*n+2)
	for {
		for i := range was {
			was[i] = false
		}
		add := dfs(s, t, infinity, cap, flow, was)
		if add == 0 {
			break
		}
		flowSize += add
	}
	if flowSize != sumA {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(flow[i][j+n])
		}
		fmt.Println()
	}
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"fmt"
	"math"
)

type (
	graph struct {
		source int
		sink   int
		edges  []map[int]int
		caps   []map[int]int
	}
)

func initGraph(n int) *graph {
	g := &graph{source: 0, sink: 2*n + 1}
	g.edges = make([]map[int]int, 2*n+2)
	g.caps = make([]map[int]int, 2*n+2)
	for i := 0; i < 2*n+2; i++ {
		g.edges[i] = map[int]int{}
		g.caps[i] = map[int]int{}
	}
	return g
}

func (g *graph) addEdge(src, dst, value int) {
	g.edges[src][dst] = value
	g.edges[dst][src] = 0
	g.caps[src][dst] = value
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		g.addEdge(g.source, i+1, a[i])
		g.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		g.addEdge(i+n+1, g.sink, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// fmt.Println(u, v)
		g.addEdge(u, v+n, a[u-1])
		g.addEdge(v, u+n, a[v-1])
	}
	// fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO")
		return
	}

	maxflow := 0
	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		// fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			// fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func bfs(g *graph) ([]int, bool) {

	// if g == nil {
	// 	return nil, false
	// }

	// visited := map[int]bool{}
	dist := make([]int, len(g.edges))

	queue := []int{}
	// visited[g.source] = true
	dist[g.source] = 1
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]

		if len(g.edges[tmp]) == 0 {
			continue
		}

		for enode, flow := range g.edges[tmp] {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				// fmt.Println("dist:", dist)
				return dist, true
			}

			if dist[enode] != 0 || flow <= 0 {
				continue
			}

			if dist[enode] == 0 && flow > 0 {
				// visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist []int, node, max int) int {

	// if g == nil {
	// 	return 0
	// }

	if node == g.sink {
		return max
	}

	if len(g.edges[node]) == 0 {
		return 0
	}

	for enode, flow := range g.edges[node] {
		if dist[enode] == dist[node]+1 && flow > 0 {
			value := dfs(g, dist, enode, min(flow, max))
			// fmt.Println(value)
			if value == 0 {
				continue
			}

			if value > 0 {
				g.edges[node][enode] -= value
				g.edges[enode][node] += value
			}
			return value
		}
	}

	return 0
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)

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

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

	n, m := readInt(), readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = readInt()
	}
	edges := make([][]int, n*2+2)
	addEdge := func(i, j int) {
		edges[i] = append(edges[i], j)
		edges[j] = append(edges[j], i)
	}
	for i := 0; i < m; i++ {
		u, v := readInt()-1, readInt()-1
		addEdge(u, n+v)
		addEdge(v, n+u)
	}
	for i := 0; i < n; i++ {
		addEdge(i, n+i)
		addEdge(i, 2*n)
		addEdge(n+i, 2*n+1)
	}
	capacity := func(v, u int) int {
		if v < 2*n && u < 2*n {
			if v < u {
				return 0x7fffffff
			}
			return 0
		}
		if v < u {
			v, u = u, v
		}
		if v == 2*n {
			return a[u]
		}
		return b[u-n]
	}
	fl := make(map[[2]int]int)
	residual := func(v, u int) int {
		return capacity(v, u) - fl[[2]int{v, u}]
	}

	bfs := func() (path []int) {
		parent := make([]int, 2*n+2)
		for i := range parent {
			parent[i] = -1
		}
		parent[2*n] = 2 * n
		queue := []int{2 * n}
		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]
			for _, u := range edges[v] {
				if residual(v, u) <= 0 {
					continue
				}
				if u == 2*n+1 {
					var reversed []int
					for w := v; w != 2*n; w = parent[w] {
						reversed = append(reversed, w)
					}
					rl := len(reversed)
					path := make([]int, rl+2)
					path[0] = 2 * n
					path[rl+1] = 2*n + 1
					for i, r := range reversed {
						path[rl-i] = r
					}
					return path
				}
				if parent[u] != -1 {
					continue
				}
				parent[u] = v
				queue = append(queue, u)
			}
		}
		return nil
	}
	flow := 0
	for {
		path := bfs()
		if len(path) == 0 {
			break
		}
		f := residual(path[0], path[1])
		for i := range path[2:] {
			if r := residual(path[i+1], path[i+2]); r < f {
				f = r
			}
		}
		for i := range path[1:] {
			fl[[2]int{path[i], path[i+1]}] += f
			fl[[2]int{path[i+1], path[i]}] -= f
		}
		flow += f
	}

	army := 0
	for _, c := range a {
		army += c
	}
	armyB := 0
	for _, c := range b {
		armyB += c
	}
	if army != armyB {
		fmt.Fprintln(out, "NO")
		return
	}
	if flow != army {
		if flow > army {
			panic("whoa")
		}
		fmt.Fprintln(out, "NO")
		return
	}
	fmt.Fprintln(out, "YES")
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Fprint(out, fl[[2]int{i, n + j}])
			if j+1 == n {
				fmt.Fprintln(out)
			} else {
				fmt.Fprint(out, " ")
			}
		}
	}
}

package main

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

type (
	graph struct {
		source string
		sink   string
		edges  map[string]map[string]int
		// caps   map[int]map[int]int
	}
)

const (
	source = "source"
	sink   = "sink"
)

func initGraph(n int) *graph {
	g := &graph{source: source, sink: sink}
	g.edges = map[string]map[string]int{}
	return g
}

func getVnode(idx int) string {
	return "v_" + strconv.Itoa(idx)
}

func (g *graph) addEdge(src, dst string, value int) {

	if _, exist := g.edges[src]; !exist {
		g.edges[src] = map[string]int{}
	}

	if _, exist := g.edges[dst]; !exist {
		g.edges[dst] = map[string]int{}
	}

	g.edges[src][dst] = value
	g.edges[dst][src] = 0
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		g.addEdge(g.source, strconv.Itoa(i+1), a[i])
		g.addEdge(strconv.Itoa(i+1), getVnode(i+1), a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		g.addEdge(getVnode(i+1), g.sink, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// fmt.Println(u, v)
		g.addEdge(strconv.Itoa(u), getVnode(v), a[u-1])
		g.addEdge(strconv.Itoa(v), getVnode(u), a[v-1])
	}
	// fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO")
		return
	}

	maxflow := 0
	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		// fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			// fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				// fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				// fmt.Print(g.edges[j+n][i])
				fmt.Print(g.edges[getVnode(j)][strconv.Itoa(i)])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func bfs(g *graph) (map[string]int, bool) {

	if g == nil {
		return nil, false
	}

	// visited := map[int]bool{}
	// dist := make([]int, len(g.edges))
	dist := map[string]int{}

	queue := []string{}
	// visited[g.source] = true
	dist[g.source] = 1
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]

		if len(g.edges[tmp]) == 0 {
			continue
		}

		for enode, flow := range g.edges[tmp] {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				// fmt.Println("dist:", dist)
				return dist, true
			}

			if dist[enode] != 0 || flow <= 0 {
				continue
			}

			if dist[enode] == 0 && flow > 0 {
				// visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist map[string]int, node string, max int) int {

	if g == nil {
		return 0
	}

	if node == g.sink {
		return max
	}

	if len(g.edges[node]) == 0 {
		return 0
	}

	for enode, flow := range g.edges[node] {
		if dist[enode] == dist[node]+1 && flow > 0 {
			value := dfs(g, dist, enode, min(flow, max))
			// fmt.Println(value)
			if value == 0 {
				continue
			}

			if value > 0 {
				g.edges[node][enode] -= value
				g.edges[enode][node] += value
			}
			return value
		}
	}

	return 0
}

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

package main

import (
	"fmt"
	"math"
)

type (
	graph struct {
		source int
		sink   int
		edges  map[int]map[int]int
		// caps   map[int]map[int]int
	}
)

func initGraph(n int) *graph {
	g := &graph{source: 0, sink: 2*n + 1}
	g.edges = map[int]map[int]int{}
	// g.caps = map[int]map[int]int{}
	// g.edges = make([]map[int]int, 2*n+2)
	// g.caps = make([]map[int]int, 2*n+2)
	// for i := 0; i < 2*n+2; i++ {
	// 	g.edges[i] = map[int]int{}
	// 	g.caps[i] = map[int]int{}
	// }
	return g
}

func (g *graph) addEdge(src, dst, value int) {

	if _, exist := g.edges[src]; !exist {
		g.edges[src] = map[int]int{}
	}

	if _, exist := g.edges[dst]; !exist {
		g.edges[dst] = map[int]int{}
	}

	// if _, exist := g.caps[src]; !exist {
	// 	g.caps[src] = map[int]int{}
	// }

	g.edges[src][dst] = value
	g.edges[dst][src] = 0
	// g.caps[src][dst] = value
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		g.addEdge(g.source, i+1, a[i])
		g.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		g.addEdge(i+n+1, g.sink, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// fmt.Println(u, v)
		g.addEdge(u, v+n, a[u-1])
		g.addEdge(v, u+n, a[v-1])
	}
	// fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO")
		return
	}

	maxflow := 0
	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		// fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			// fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				// fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				fmt.Print(g.edges[j+n][i])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func bfs(g *graph) (map[int]int, bool) {

	if g == nil {
		return nil, false
	}

	// visited := map[int]bool{}
	// dist := make([]int, len(g.edges))
	dist := map[int]int{}

	queue := []int{}
	// visited[g.source] = true
	dist[g.source] = 1
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]

		if len(g.edges[tmp]) == 0 {
			continue
		}

		for enode, flow := range g.edges[tmp] {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				// fmt.Println("dist:", dist)
				return dist, true
			}

			if dist[enode] != 0 || flow <= 0 {
				continue
			}

			if dist[enode] == 0 && flow > 0 {
				// visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist map[int]int, node, max int) int {

	if g == nil {
		return 0
	}

	if node == g.sink {
		return max
	}

	if len(g.edges[node]) == 0 {
		return 0
	}

	for enode, flow := range g.edges[node] {
		if dist[enode] == dist[node]+1 && flow > 0 {
			value := dfs(g, dist, enode, min(flow, max))
			// fmt.Println(value)
			if value == 0 {
				continue
			}

			if value > 0 {
				g.edges[node][enode] -= value
				g.edges[enode][node] += value
			}
			return value
		}
	}

	return 0
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	f := NewFlow(2*n + 2)
	ns := 0
	ne := 2*n + 1

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		f.addEdge(ns, i+1, a[i])
		f.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		f.addEdge(i+n+1, ne, b[i])
	}
	fmt.Scanf("\n")
	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		f.addEdge(u, v+n, a[u-1])
		f.addEdge(v, u+n, a[v-1])
	}
	if sa != sb {
		fmt.Println("NO")
		return
	}
	maxflow := f.dinic(ns, ne)
	// maxflow := f.EK(ns, ne)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(f.flow[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

type flow struct {
	volume []map[int]int
	flow   []map[int]int
}

func NewFlow(n int) *flow {
	f := new(flow)
	f.volume = make([]map[int]int, n)
	for i := range f.volume {
		f.volume[i] = make(map[int]int)
	}
	f.flow = make([]map[int]int, n)
	for i := range f.flow {
		f.flow[i] = make(map[int]int)
	}
	return f
}

func (f *flow) addEdge(u, v, c int) {
	// fmt.Println("add edge", u, v, c)
	f.volume[u][v] = c
	f.flow[u][v] = 0
}

func (f *flow) EK(start, end int) int {
	maxflow := 0

	for {
		nodeFlow := make([]int, len(f.volume))
		nodeFlow[start] = math.MaxInt32

		pre := make([]int, len(f.volume))

		queue := make([]int, 0)
		queue = append(queue, start)
		for len(queue) > 0 {
			u := queue[0]
			queue = queue[1:]
			for v, ff := range f.flow[u] {
				c := f.volume[u][v]
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, "flow[u][v]:", f.flow[u][v], "vol[u][v]:", c)
				if nodeFlow[v] != 0 || c <= ff {
					// 节点被标记 或 边流量用尽，跳过
					continue
				}

				nodeFlow[v] = c - ff
				if nodeFlow[u] < nodeFlow[v] {
					nodeFlow[v] = nodeFlow[u]
				}
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, nodeFlow[v])

				pre[v] = u
				queue = append(queue, v)
			}
		}
		// fmt.Println("nodeFlow[end]:", nodeFlow[end])
		if nodeFlow[end] == 0 {
			return maxflow
		}
		// fmt.Println("pre:", pre)
		for u := end; u != start; u = pre[u] {
			f.flow[pre[u]][u] += nodeFlow[end]
			f.flow[u][pre[u]] -= nodeFlow[end]
		}
		// fmt.Println("flow:")
		// for u, m := range f.flow {
		// 	for v, ff := range m {
		// 		fmt.Println(u, v, ff)
		// 	}
		// }
		// fmt.Println("")
		maxflow += nodeFlow[end]
	}
}

func (f *flow) dinic(start, end int) int {
	maxflow := 0

	for {
		dis := make([]int, len(f.volume))
		dis[start] = 1
		queue := make([]int, 0)
		queue = append(queue, start)
		for len(queue) > 0 {
			u := queue[0]
			queue = queue[1:]
			for v, ff := range f.flow[u] {
				c := f.volume[u][v]
				if dis[v] != 0 || ff >= c {
					continue
				}
				dis[v] = dis[u] + 1
				queue = append(queue, v)
			}
		}
		if dis[end] == 0 {
			return maxflow
		}

		for {
			nodeFlow := make([]int, len(f.volume))
			nodeFlow[start] = math.MaxInt32
			pre := make([]int, len(f.volume))
			queue = make([]int, 0)
			queue = append(queue, start)
			for len(queue) > 0 {
				u := queue[0]
				queue = queue[1:]
				for v, ff := range f.flow[u] {
					c := f.volume[u][v]
					if nodeFlow[v] != 0 || ff >= c || dis[v] != dis[u]+1 {
						continue
					}
					pre[v] = u
					nodeFlow[v] = c - ff
					if nodeFlow[u] < nodeFlow[v] {
						nodeFlow[v] = nodeFlow[u]
					}
					queue = append(queue, v)
				}
			}
			if nodeFlow[end] == 0 {
				break
			}
			for u := end; u != start; u = pre[u] {
				f.flow[pre[u]][u] += nodeFlow[end]
				f.flow[u][pre[u]] -= nodeFlow[end]
			}
			maxflow += nodeFlow[end]
		}
	}
}

package main

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

var in = bufio.NewScanner(os.Stdin)

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

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

	n, m := readInt(), readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = readInt()
	}
	edges := make([][]int, n*2+2)
	addEdge := func(i, j int) {
		edges[i] = append(edges[i], j)
		edges[j] = append(edges[j], i)
	}
	for i := 0; i < m; i++ {
		u, v := readInt()-1, readInt()-1
		addEdge(u, n+v)
		addEdge(v, n+u)
	}
	for i := 0; i < n; i++ {
		addEdge(i, n+i)
		addEdge(i, 2*n)
		addEdge(n+i, 2*n+1)
	}
	capacity := func(v, u int) int {
		if v < 2*n && u < 2*n {
			if v < u {
				return 0x7fffffff
			}
			return 0
		}
		if v < u {
			v, u = u, v
		}
		if v == 2*n {
			return a[u]
		}
		return b[u-n]
	}
	fl := make(map[[2]int]int)
	residual := func(v, u int) int {
		return capacity(v, u) - fl[[2]int{v, u}]
	}

	bfs := func() (path []int) {
		parent := make([]int, 2*n+2)
		for i := range parent {
			parent[i] = -1
		}
		parent[2*n] = 2 * n
		queue := []int{2 * n}
		for len(queue) > 0 {
			v := queue[0]
			queue = queue[1:]
			for _, u := range edges[v] {
				if residual(v, u) <= 0 {
					continue
				}
				if u == 2*n+1 {
					var reversed []int
					for w := v; w != 2*n; w = parent[w] {
						reversed = append(reversed, w)
					}
					rl := len(reversed)
					path := make([]int, rl+2)
					path[0] = 2 * n
					path[rl+1] = 2*n + 1
					for i, r := range reversed {
						path[rl-i] = r
					}
					return path
				}
				if parent[u] != -1 {
					continue
				}
				parent[u] = v
				queue = append(queue, u)
			}
		}
		return nil
	}
	flow := 0
	for {
		path := bfs()
		if len(path) == 0 {
			break
		}
		f := residual(path[0], path[1])
		for i := range path[2:] {
			if r := residual(path[i+1], path[i+2]); r < f {
				f = r
			}
		}
		for i := range path[1:] {
			fl[[2]int{path[i], path[i+1]}] += f
			fl[[2]int{path[i+1], path[i]}] -= f
		}
		flow += f
	}

	army := 0
	for _, c := range a {
		army += c
	}
	if flow != army {
		if flow > army {
			panic("whoa")
		}
		fmt.Fprintln(out, "NO")
		return
	}
	fmt.Fprintln(out, "YES")
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			fmt.Fprint(out, fl[[2]int{i, n + j}])
			if j+1 == n {
				fmt.Fprintln(out)
			} else {
				fmt.Fprint(out, " ")
			}
		}
	}
}

package main

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

func ReadLine() (string, error) {
	line, err := bufio.NewReader(os.Stdin).ReadString('\n')
	if err != nil {
		fmt.Println("readline err:", line, err)
		return line, err
	}
	return strings.TrimSpace(string(line)), nil
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	// line, _ := ReadLine()
	// parts := strings.Split(line, " ")
	// n, _ := strconv.Atoi(parts[0])
	// m, _ := strconv.Atoi(parts[1])
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0
	fmt.Println("input n m", n, m)
	// fmt.Println("parts n m", parts)

	f := NewFlow(2*n + 2)
	fmt.Println("new flow")
	ns := 0
	ne := 2*n + 1

	// format := ""
	// params := make([]interface{}, n)
	// for i := 0; i < n; i++ {
	// 	format += "%d"
	// 	if i != n-1 {
	// 		format += " "
	// 	} else {
	// 		format += "\n"
	// 	}
	// 	params = append(params, &a[i])
	// }
	// fmt.Scanf(format, params...)
	// line, _ = ReadLine()
	// parts = strings.Split(line, " ")
	// fmt.Println("parts a", parts)
	// for i := 0; i < n; i++ {
	// 	a[i], _ = strconv.Atoi(parts[i])
	// 	fmt.Println("a[i]:", i, a[i])
	// }
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		f.addEdge(ns, i+1, a[i])
		f.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	fmt.Println("input a", a)
	fmt.Println("add edges a")

	// format = ""
	// params = make([]interface{}, n)
	// for i := 0; i < n; i++ {
	// 	format += "%d"
	// 	if i != n-1 {
	// 		format += " "
	// 	} else {
	// 		format += "\n"
	// 	}
	// 	params = append(params, &b[i])
	// }
	// fmt.Scanf(format, params...)
	// line, _ = ReadLine()
	// parts = strings.Split(line, " ")
	// for i := 0; i < n; i++ {
	// b[i], _ = strconv.Atoi(parts[i])
	// }
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		f.addEdge(i+n+1, ne, b[i])
	}
	fmt.Scanf("\n")
	fmt.Println("input b", b)
	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// line, _ = ReadLine()
		// parts = strings.Split(line, " ")
		// u, _ := strconv.Atoi(parts[0])
		// v, _ := strconv.Atoi(parts[1])
		f.addEdge(u, v+n, a[u-1])
		f.addEdge(v, u+n, a[v-1])
	}
	fmt.Println("input edge")
	if sa != sb {
		fmt.Println("NO")
		return
	}
	maxflow := f.EK(ns, ne)
	fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(f.flow[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

type flow struct {
	volume []map[int]int
	flow   []map[int]int
}

func NewFlow(n int) *flow {
	f := new(flow)
	f.volume = make([]map[int]int, n)
	for i := range f.volume {
		f.volume[i] = make(map[int]int)
	}
	f.flow = make([]map[int]int, n)
	for i := range f.flow {
		f.flow[i] = make(map[int]int)
	}
	return f
}

func (f *flow) addEdge(u, v, c int) {
	fmt.Println("add edge", u, v, c)
	f.volume[u][v] = c
	f.flow[u][v] = 0
}

func (f *flow) EK(start, end int) int {
	maxflow := 0

	for {
		nodeFlow := make([]int, len(f.volume))
		nodeFlow[start] = math.MaxInt32

		pre := make([]int, len(f.volume))

		queue := make([]int, 0)
		queue = append(queue, start)
		for len(queue) > 0 {
			u := queue[0]
			queue = queue[1:]
			for v, ff := range f.flow[u] {
				c := f.volume[u][v]
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, "flow[u][v]:", f.flow[u][v], "vol[u][v]:", c)
				if nodeFlow[v] != 0 || c <= ff {
					// 节点被标记 或 边流量用尽，跳过
					continue
				}

				nodeFlow[v] = c - ff
				if nodeFlow[u] < nodeFlow[v] {
					nodeFlow[v] = nodeFlow[u]
				}
				// fmt.Println("u:", u, nodeFlow[u], "v:", v, nodeFlow[v])

				pre[v] = u
				queue = append(queue, v)
			}
		}
		// fmt.Println("nodeFlow[end]:", nodeFlow[end])
		if nodeFlow[end] == 0 {
			return maxflow
		}
		// fmt.Println("pre:", pre)
		for u := end; u != start; u = pre[u] {
			f.flow[pre[u]][u] += nodeFlow[end]
			f.flow[u][pre[u]] -= nodeFlow[end]
		}
		// fmt.Println("flow:")
		// for u, m := range f.flow {
		// 	for v, ff := range m {
		// 		fmt.Println(u, v, ff)
		// 	}
		// }
		// fmt.Println("")
		maxflow += nodeFlow[end]
	}
}

package main

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

const infinity = 1000000000

func slice2D(n int) [][]int {
	res := make([][]int, n)
	for i := range res {
		res[i] = make([]int, n)
	}
	return res
}

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

	}
	return b
}

func dfs(v, t, w int, cap, flow [][]int, was []bool) int {
	if v == t {
		return w
	}
	if was[v] {
		return 0
	}
	was[v] = true
	for u := range was {
		if flow[v][u] >= cap[v][u] {
			continue
		}
		nw := dfs(u, t, min(w, cap[v][u]-flow[v][u]), cap, flow, was)
		if nw > 0 {
			flow[v][u] += nw
			flow[u][v] -= nw
			return nw
		}
	}
	return 0
}

func main() {
	n := nextInt()
	m := nextInt()
	a := make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}
	b := make([]int, n)
	for i := range b {
		b[i] = nextInt()
	}
	cap := slice2D(2*n + 2)
	flow := slice2D(2*n + 2)
	s := 2 * n
	t := 2*n + 1
	for i := 0; i < m; i++ {
		u := nextInt() - 1
		v := nextInt() - 1
		cap[u][v+n] = infinity
		cap[v][u+n] = infinity
	}
	var sumA, sumB int
	for i := 0; i < n; i++ {
		cap[s][i] = a[i]
		cap[i+n][t] = b[i]
		cap[i][i+n] = infinity
		sumA += a[i]
		sumB += b[i]
	}
	if sumA != sumB {
		fmt.Println("NO")
		return
	}
	flowSize := 0
	was := make([]bool, 2*n+2)
	for {
		for i := range was {
			was[i] = false
		}
		add := dfs(s, t, infinity, cap, flow, was)
		if add == 0 {
			break
		}
		flowSize += add
	}
	fmt.Println(flowSize, sumA)
	if flowSize != sumA {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j > 0 {
				fmt.Print(" ")
			}
			fmt.Print(flow[i][j+n])
		}
		fmt.Println()
	}
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"fmt"
	"math"
)

type (
	graph struct {
		source int
		sink   int
		edges  map[int]map[int]int
		caps   map[int]map[int]int
	}
)

func initGraph(n int) *graph {
	g := &graph{source: 0, sink: 2*n + 1}
	g.edges = map[int]map[int]int{}
	g.caps = map[int]map[int]int{}
	return g
}

func (g *graph) addEdge(src, dst, value int) {
	_, exist := g.edges[src]
	if !exist {
		g.edges[src] = map[int]int{}
	}

	_, exist = g.edges[dst]
	if !exist {
		g.edges[dst] = map[int]int{}
	}

	_, exist = g.caps[src]
	if !exist {
		g.caps[src] = map[int]int{}
	}

	g.edges[src][dst] = value
	g.edges[dst][src] = 0
	g.caps[src][dst] = value
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)
	// line, _ := ReadLine()
	// parts := strings.Split(line, " ")
	// n, _ := strconv.Atoi(parts[0])
	// m, _ := strconv.Atoi(parts[1])
	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		// f.addEdge(ns, i+1, a[i])
		g.addEdge(g.source, i+1, a[i])
		// f.addEdge(i+1, n+i+1, a[i])
		g.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	fmt.Println("input a", a)
	// fmt.Println("add edges a")

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		// f.addEdge(i+n+1, ne, b[i])
		g.addEdge(i+n+1, g.sink, b[i])
	}
	fmt.Scanf("\n")
	fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		// f.addEdge(u, v+n, a[u-1])
		fmt.Println(u, v)
		g.addEdge(u, v+n, a[u-1])
		// f.addEdge(v, u+n, a[v-1])
		g.addEdge(v, u+n, a[v-1])
	}
	fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO", sa, sb)
		return
	}

	maxflow := 0

	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO", maxflow)
	}
}

func bfs(g *graph) (map[int]int, bool) {

	if g == nil {
		return nil, false
	}

	visited := map[int]bool{}
	dist := map[int]int{}

	queue := []int{}
	visited[g.source] = true
	dist[g.source] = 0
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]
		edgeFlows, exist := g.edges[tmp]

		if !exist {
			continue
		}

		for enode, flow := range edgeFlows {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				fmt.Println("dist:", dist)
				return dist, true
			}

			if !visited[enode] && flow > 0 {
				visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist map[int]int, node, max int) int {

	if g == nil {
		return 0
	}

	if node == g.sink {
		return max
	}

	edgeFlows, exist := g.edges[node]
	if exist {
		for enode, flow := range edgeFlows {
			if dist[enode] == dist[node]+1 && flow > 0 {
				value := dfs(g, dist, enode, min(flow, max))
				fmt.Println(value)
				if value > 0 {
					g.edges[node][enode] -= value
					g.edges[enode][node] += value
				}
				return value
			}
		}
	}

	return 0
}

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

package main

import (
	"fmt"
	"math"
)

type (
	graph struct {
		source int
		sink   int
		edges  map[int]map[int]int
		caps   map[int]map[int]int
	}
)

func initGraph(n int) *graph {
	g := &graph{source: 0, sink: 2*n + 1}
	g.edges = map[int]map[int]int{}
	g.caps = map[int]map[int]int{}
	return g
}

func (g *graph) addEdge(src, dst, value int) {
	_, exist := g.edges[src]
	if !exist {
		g.edges[src] = map[int]int{}
	}

	_, exist = g.edges[dst]
	if !exist {
		g.edges[dst] = map[int]int{}
	}

	_, exist = g.caps[src]
	if !exist {
		g.caps[src] = map[int]int{}
	}

	g.edges[src][dst] = value
	g.edges[dst][src] = 0
	g.caps[src][dst] = value
}

func main() {
	var n, m int
	fmt.Scanf("%d %d\n", &n, &m)

	g := initGraph(n)
	a := make([]int, n)
	b := make([]int, n)
	sa := 0
	sb := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		sa += a[i]
		g.addEdge(g.source, i+1, a[i])
		g.addEdge(i+1, n+i+1, a[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input a", a)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &b[i])
		sb += b[i]
		g.addEdge(i+n+1, g.sink, b[i])
	}
	fmt.Scanf("\n")
	// fmt.Println("input b", b)

	for m > 0 {
		m--
		var u, v int
		fmt.Scanf("%d %d\n", &u, &v)
		fmt.Println(u, v)
		g.addEdge(u, v+n, a[u-1])
		g.addEdge(v, u+n, a[v-1])
	}
	// fmt.Println("input edge", g.edges)
	if sa != sb {
		fmt.Println("NO")
		return
	}

	maxflow := 0

	for {
		dist, hasRoad := bfs(g)
		if !hasRoad {
			break
		}

		// fmt.Println(dist)
		for {
			value := dfs(g, dist, g.source, math.MaxInt32)
			// fmt.Println(value)
			if value == 0 {
				break
			}
			maxflow += value
		}
	}
	// fmt.Println("EK")
	// fmt.Println("maxflow:", maxflow)
	if maxflow == sa {
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				fmt.Print(g.caps[i][j+n] - g.edges[i][j+n])
				if j == n {
					fmt.Println("")
				} else {
					fmt.Print(" ")
				}
			}
		}
	} else {
		fmt.Println("NO")
	}
}

func bfs(g *graph) (map[int]int, bool) {

	if g == nil {
		return nil, false
	}

	visited := map[int]bool{}
	dist := map[int]int{}

	queue := []int{}
	visited[g.source] = true
	dist[g.source] = 0
	queue = append(queue, g.source)

	for len(queue) > 0 {
		tmp := queue[0]
		queue = queue[1:]
		edgeFlows, exist := g.edges[tmp]

		if !exist {
			continue
		}

		for enode, flow := range edgeFlows {
			if enode == g.sink && flow > 0 {
				dist[enode] = dist[tmp] + 1
				// fmt.Println("dist:", dist)
				return dist, true
			}

			if !visited[enode] && flow > 0 {
				visited[enode] = true
				dist[enode] = dist[tmp] + 1
				queue = append(queue, enode)
			}
		}
	}

	return nil, false
}

func dfs(g *graph, dist map[int]int, node, max int) int {

	if g == nil {
		return 0
	}

	if node == g.sink {
		return max
	}

	edgeFlows, exist := g.edges[node]
	if exist {
		for enode, flow := range edgeFlows {
			if dist[enode] == dist[node]+1 && flow > 0 {
				value := dfs(g, dist, enode, min(flow, max))
				fmt.Println(value)
				if value > 0 {
					g.edges[node][enode] -= value
					g.edges[enode][node] += value
				}
				return value
			}
		}
	}

	return 0
}

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


package main

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

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

	var t, max1, min1, max2, min2 int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &max1, &min1)
		fmt.Fscan(r, &max2, &min2)

		if max1 < min1 {
			max1, min1 = min1, max1
		}

		if max2 < min2 {
			max2, min2 = min2, max2
		}

		if (max1 == max2) && (min2+min1 == max1) {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}

	}
}

// Problem statement can be found in
// https://codeforces.com/problemset/problem/1351/B

package main

import (
	"fmt"
	"math"
)

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

	for i:=0; i < t ; i++ {
		var a1, a2, b1, b2 float64
		fmt.Scan(&a1, &b1, &a2, &b2)

		if math.Max(a1, b1)==math.Max(a2, b2) && (math.Min(a1, b1)+math.Min(a2, b2) == math.Max(a1, b1)) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var a, b, c,d int
	fmt.Fscan(input, &a, &b, &c, &d)
	if a > b {
		a, b = b, a
	}
	if c > d {
		c, d = d, c
	}

	if d == b && a + c == d {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

package main

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

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

	var t, a, b, c, d int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &a, &b, &c, &d)
		if a > b {
			a, b = b, a
		}
		if c > d {
			c, d = d, c
		}
		if b == d && b == a+c {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

import (
    "fmt"
)

func main() {
    var t int
    fmt.Scanf("%d\n", &t)
    for i := 0; i < t; i++ {
        var a1, b1, a2, b2 int
        fmt.Scanf("%d %d\n%d %d\n", &a1, &b1, &a2, &b2)
        if (a1 == a2 && a1 == b1 + b2) || (b1 == b2 && a1 + a2 == b1) {
            fmt.Println("Yes")
            continue
        }
        a2, b2 = b2, a2
        if (a1 == a2 && a1 == b1 + b2) || (b1 == b2 && a1 + a2 == b1) {
            fmt.Println("Yes")
            continue
        }
        fmt.Println("No")
    }
}

package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		aa := make([]int, 2)
		bb := make([]int, 2)
		for j := 0; j < 2; j++ {
			aa[j] = getNextInt(scanner)
		}
		for j := 0; j < 2; j++ {
			bb[j] = getNextInt(scanner)
		}

		if isYes(aa, bb) {
			fmt.Fprintln(writer, "Yes")
			continue
		}
		fmt.Fprintln(writer, "No")
	}
}

func isYes(aa, bb []int) bool {
	for j := 0; j < 2; j++ {
		for k := 0; k < 2; k++ {
			if aa[j] != bb[k] {
				continue
			}
			if aa[j] == aa[1-j]+bb[1-k] {
				return true
			}
		}
	}
	return false
}

// Problem statement can be found in
// https://codeforces.com/problemset/problem/1351/B

package main

import (
	"fmt"
	"math"
)

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

	for i:=0; i < t ; i++ {
		var a1, a2, b1, b2 int
		fmt.Scan(&a1, &b1, &a2, &b2)

		v := math.Sqrt(float64(a1+a2+b1+b2))
		if v - math.Floor(v) == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// Problem statement can be found in
// https://codeforces.com/problemset/problem/1351/B

package main

import (
	"fmt"
	"math"
)

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

	for i:=0; i < t ; i++ {
		var a1, a2, b1, b2 int
		fmt.Scan(&a1, &b1, &a2, &b2)

		v := math.Sqrt(float64((a1*b1)+(a2*b2)))
		if v - math.Floor(v) == 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"math/big"
	"os"
	"strconv"
)

var scan *bufio.Scanner
var reader io.Reader
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	reader = os.Stdin
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	n := nextInt()
	var c, m, x int
	for i := 0; i < n; i++ {
		c = nextInt()
		m = nextInt()
		x = nextInt()
		fmt.Fprintln(writer, min(c, m, (c+m+x)/3))
	}
}

func nextWord() string {
	var s string
	fmt.Fscan(reader, &s)
	return s
}

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

func max(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Max(res, float64(z))
	}
	return int(res)
}

func min(x int, y ...int) int {
	res := float64(x)
	for _, z := range y {
		res = math.Min(res, float64(z))
	}
	return int(res)
}

func abs(x int) int {
	return int(math.Abs(float64(x)))
}

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

func int2Int(x int) big.Int {
	var res big.Int
	res.SetInt64(int64(x))
	return res
}

package main

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

func clear(arr []byte) []byte {
	if string(arr[len(arr)-2:len(arr)]) == "\r\n" {
		return arr[:len(arr)-2]
	} else if string(arr[len(arr)-1]) == "\n" {
		return arr[:len(arr)-1]
	}
	return arr
}

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

func isWin(b []byte) int {
	values := strings.Split(string(clear(b)), " ")
	c, _ := strconv.Atoi(values[0])
	m, _ := strconv.Atoi(values[1])
	x, _ := strconv.Atoi(values[2])

	var team int

	min := int(math.Abs(float64(c - m)))
	progers := c + m - min
	x += min

	if x <= progers/2 {
		team += x
		progers -= x * 2
		x = 0
	} else {
		team += progers / 2
		progers = 0
	}

	if progers > 2 {
		team += progers / 3
	}

	return team
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadBytes('\n')
	q, _ := strconv.Atoi(string(clear(line)))

	for i := 0; i < q; i++ {
		array, _ := reader.ReadBytes('\n')
		fmt.Printf("%v\n", isWin(array))
	}
}

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		printInt(solveOne())
	}
}

func solveOne() int {
	c, m, x := readInt(), readInt(), readInt()
	min := c
	if m < min {
		min = m
	}
	r := c + m + x - min*2
	if min <= r {
		return min
	}
	return (c + m + x) / 3
}

/* 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 printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

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

package main

import (
    "fmt"
    "bufio"
    "os"
)
var input *bufio.Reader

func min(x, y, z int64) int64 {
    var res int64
    res = x
    if y < res {
        res = y
    }
    if z < res {
        res = z
    }
    return res
}

func solve() {
    var (
        C, M, X int64
        max_teams int64
    )
    fmt.Fscanf(input, "%d %d %d\n", &C, &M, &X)
    max_teams = (C+M+X) / 3
    fmt.Println(min(max_teams,C,M))
}

func main () {
    input = bufio.NewReader(os.Stdin)
    var T int
    fmt.Fscanf(input, "%d\n", &T)
    for i:=0 ; i<T ; i++ {
        solve()
    }
}

package main

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

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

	for count > 0 {
		count--
		var (
			coder   int
			mather  int
			useless int
		)
		_, _ = fmt.Fscan(input, &coder, &mather, &useless)

		maxTeam := coder
		if maxTeam > mather {
			maxTeam = mather
		}

		rMaxTeam := (coder + mather + useless) / 3
		if maxTeam > rMaxTeam {
			maxTeam = rMaxTeam
		}
		fmt.Println(maxTeam)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		c, m, x := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &c, &m, &x)
		l := 0
		r := (c + m + x) / 3
		for l < r {
			mid := (l + r + 1) / 2
			if !can(c,m,x,mid) {
				r = mid  - 1
			} else {
				l = mid
			}
		}
		fmt.Fprintf(out,"%d\n", l)
	}
	return
}

func can(a, b, c, aim int) bool {
	if a < aim {
		return false
	}
	if b < aim {
		return false
	}
	if (a - aim) + b - aim + c < aim {
		return false
	}
	return true
}

func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

func toInt(buf []byte) uint32 {
	n := uint32(0)
	for _, v := range buf {
		n = n*10 + uint32(v-'0')
	}

	return n
}

func solve(c, m, o uint32) uint32 {
	if c <= m && c <= o {
		return c
	}

	if m <= c && m <= o {
		return m
	}

	r := (m + c + o) / 3
	if c < r {
		r = c
	}
	if m < r {
		r = m
	}

	return r
}

func main() {
	var q uint32

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	q = toInt(scanner.Bytes())

	for i := uint32(0); i < q; i++ {
		a := make([]uint32, 3)
		for j := range a {
			scanner.Scan()
			a[j] = toInt(scanner.Bytes())
		}

		res := solve(a[0], a[1], a[2])

		fmt.Println(res)
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var testCase int

	_, err := fmt.Fscan(input, &testCase)
	if err != nil {
	}

	for testCase > 0 {
		testCase--

		var c, m, x int
		_, err := fmt.Fscan(input, &c, &m, &x)
		if err != nil {
		}

		teamNum := (c + m + x) / 3
		if c < m {
			if c < teamNum {
				fmt.Println(c)
			} else {
				fmt.Println(teamNum)
			}
		} else {
			if m < teamNum {
				fmt.Println(m)
			} else {
				fmt.Println(teamNum)
			}
		}

	}

}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var c, m, x int
		fmt.Fscanf(reader, "%d %d %d\n", &c, &m, &x)

		mm := min(min(c, m), x)
		c -= mm
		m -= mm
		x -= mm

		if c == 0 || m == 0 {
		} else {
			if c == m {
				mm += (c + m) / 3
			} else {
				if c > m {
					c, m = m, c
				}
				mm += min(c, (c + m) / 3)
			}
		}
		fmt.Println(mm)
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

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

package main

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

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

func Solve(c int, m int, x int) int {
	p := min(c, m)
	c -= p
	m -= p
	f := c + m + x
	if p < f {
		return p
	}
	return f + (p-f)*2/3
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var c, m, x int
		fmt.Fscanf(reader, "%d %d %d\n", &c, &m, &x)
		fmt.Fprintf(writer, "%d\n", Solve(c, m, x))
	}
}

package main

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

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		printInt(solveOne())
	}
}

func solveOne() int {
	c, m, x := readInt(), readInt(), readInt()
	min := c
	if m < min {
		min = m
	}
	x += c + m - min - min
	if min <= x {
		return min
	}
	return (c + m + x) / 3
}

/* 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 printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

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

package main

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

func toInt(buf []byte) uint32 {
	n := uint32(0)
	for _, v := range buf {
		n = n*10 + uint32(v-'0')
	}

	return n
}

func solve(c, m, o uint32) uint32 {
	//var r uint32

	if c <= m && c <= o {
		return c
	}

	if m <= c && m <= o {
		return m
	}

	return (m + c + o) / 3
}

func main() {
	var q uint32

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	q = toInt(scanner.Bytes())

	for i := uint32(0); i < q; i++ {
		a := make([]uint32, 3)
		for j := range a {
			scanner.Scan()
			a[j] = toInt(scanner.Bytes())
		}

		res := solve(a[0], a[1], a[2])

		fmt.Println(res)
	}
}

package main

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

func toInt(buf []byte) uint32 {
	n := uint32(0)
	for _, v := range buf {
		n = n*10 + uint32(v-'0')
	}

	return n
}

func solve(c, m, o uint32) uint32 {
	if c <= m && c <= o {
		return c
	}

	if m <= c && m <= o {
		return m
	}

	r := (m + c + o) / 3
	if m < c {
		r = c
	}
	if m < r {
		r = m
	}

	return r
}

func main() {
	var q uint32

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	q = toInt(scanner.Bytes())

	for i := uint32(0); i < q; i++ {
		a := make([]uint32, 3)
		for j := range a {
			scanner.Scan()
			a[j] = toInt(scanner.Bytes())
		}

		res := solve(a[0], a[1], a[2])

		fmt.Println(res)
	}
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var c, m, x int
		fmt.Fscanf(reader, "%d %d %d\n", &c, &m, &x)

		mm := min(min(c, m), x)
		c -= mm
		m -= mm
		x -= mm

		if c == 0 || m == 0 {
			fmt.Println(mm)
		} else {
			fmt.Println((c + m) / 3 + mm)
		}

	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var c, m, x int
		fmt.Fscanf(reader, "%d %d %d\n", &c, &m, &x)

		mm := min(min(c, m), x)
		c -= mm
		m -= mm
		x -= mm

		if c == 0 || m == 0 {
			fmt.Println(mm)
		} else {
			if c == m {
				fmt.Println((c + m) / 3 + mm)
			} else {
				if c > m {
					fmt.Println(mm + min(m, c - m))
				} else {
					fmt.Println(mm + min(c, m - c))
				}
			}
		}

	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var c, m, x int
		fmt.Fscanf(reader, "%d %d %d\n", &c, &m, &x)

		mm := min(min(c, m), x)
		c -= mm
		m -= mm
		x -= mm

		if c == 0 || m == 0 {
			fmt.Println(mm)
		} else {
			if c == m {
				fmt.Println((c + m) / 3 + mm)
			} else {
				if c > m {
					fmt.Println(mm + min(m, (c - m) / 2))
				} else {
					fmt.Println(mm + min(c, (m - c) / 2))
				}
			}
		}

	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}