package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		d := make([]int, n+1)
		for i := range d {
			d[i] = -1
		}
		d[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		return d
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		ans := int64(1e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		for v := 1; v <= n; v++ {
			if cost := depA[v] + depB[v] + depC[v]; cost <= m {
				if s := sum[cost] + sum[depB[v]]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		firstLine := readNNums(reader, 5)
		n, m, a, b, c := firstLine[0], firstLine[1], firstLine[2], firstLine[3], firstLine[4]
		P := readNNums(reader, m)
		edges := make([][]int, m)
		for i := 0; i < m; i++ {
			edges[i] = readNNums(reader, 2)
		}
		fmt.Println(solve(n, m, a, b, c, P, edges))
	}
}

func solve(n, m, a, b, c int, P []int, edges [][]int) int64 {
	sort.Ints(P)

	pref := make([]int64, m+1)

	for i := 0; i < m; i++ {
		pref[i+1] = pref[i] + int64(P[i])
	}

	E := make([][]int, n)

	for i := 0; i < n; i++ {
		E[i] = make([]int, 0, 10)
	}

	for _, edge := range edges {
		u, v := edge[0], edge[1]
		u--
		v--
		E[u] = append(E[u], v)
		E[v] = append(E[v], u)
	}

	da := make([]int, n)
	db := make([]int, n)
	dc := make([]int, n)

	for i := 0; i < n; i++ {
		da[i] = -1
		db[i] = -1
		dc[i] = -1
	}

	que := make([]int, n)

	bfs := func(x int, dist []int) {
		var front, end int
		que[end] = x
		dist[x] = 0
		end++
		for front < end {
			u := que[front]
			front++
			for _, v := range E[u] {
				if dist[v] < 0 {
					dist[v] = dist[u] + 1
					que[end] = v
					end++
				}
			}
		}
	}

	bfs(a-1, da)
	bfs(b-1, db)
	bfs(c-1, dc)

	var best = int64(-1)

	for i := 0; i < n; i++ {
		if da[i]+db[i]+dc[i] > m {
			continue
		}
		tmp := pref[db[i]] + pref[da[i]+db[i]+dc[i]]
		if best < 0 || best > tmp {
			best = tmp
		}
	}

	return best
}

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		if dab == 0 {
			d := depB[c]
			Fprintln(out, sum[d])
			continue
		}
		ans := int64(1e18)
		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] > dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(9e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		for v := 1; v <= n; v++ {
			dav, dbv, dcv := depA[v], depB[v], depC[v]
			if dav+dbv > dab {
				continue
			}
			if cost := dav + dbv + dcv; cost <= m {
				if s := sum[cost] + sum[dbv]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(1e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] > dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(9e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		if a == c {
			Fprintln(out, 2*sum[depA[b]])
			continue
		}

		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] != dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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


package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func getVal(s byte) int {
	// fmt.Println("xxx: ", s, byte('R'), byte('B'))
	if s == byte('R') {
		// fmt.Println("is R")
		return 1
	} else {
		// fmt.Println("is B")
		return 2
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			n := iost.GetNextInt()
			s := iost.Text()
			idx := -1
			for i := 0; i < n; i++ {
				if s[i] != '?' {
					idx = i
					break
				}
			}
			prev := byte('B')
			if idx > -1 {
				if idx%2 == 0 {
					prev = s[idx]
				} else {
					if s[idx] == 'B' {
						prev = 'R'
					} else {
						prev = 'B'
					}
				}
			}
			iost.Printf("%s", string(prev))
			for i := 1; i < n; i++ {
				if s[i] == '?' {
					if prev == 'B' {
						prev = 'R'
						iost.Printf("R")
					} else {
						prev = 'B'
						iost.Printf("B")
					}
				} else {
					iost.Printf("%s", string(s[i]))
					prev = s[i]
				}
			}
			iost.Println()

			// for i := 0; i < n; i++ {
			// 	if s[i] == '?' {
			// 		k := i + 1
			// 		for ; k < n; k++ {
			// 			if s[k] != '?' {
			// 				ret[k] = getVal(s[k])
			// 				break
			// 			}
			// 		}
			// 		for j := k - 1; j >= i; j-- {
			// 			if ret[j+1] == 2 {
			// 				ret[j] = 1
			// 			} else {
			// 				ret[j] = 2
			// 			}
			// 		}
			// 		i = k - 1
			// 	} else {
			// 		ret[i] = getVal(s[i])
			// 	}
			// }
			// for i := 0; i < n; i++ {
			// 	if ret[i] == 1 {
			// 		iost.Printf("R")
			// 	} else {
			// 		iost.Printf("B")
			// 	}
			// }
			// iost.Println()
		}()
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	s      string
)

func solve(n int, s string) string {
	var m, cnt = []byte(s), 0
	for _, x := range m {
		if x != '?' {
			cnt++
		}
	}
	if cnt == 0 {
		m[0] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if m[i+1] != '?' && m[i] == '?' {
			m[i] = 'B'
			if m[i+1] == 'B' {
				m[i] = 'R'
			}
		}
	}
	for i := 1; i < n; i++ {
		if m[i-1] != '?' && m[i] == '?' {
			m[i] = 'B'
			if m[i-1] == 'B' {
				m[i] = 'R'
			}
		}
	}
	return string(m)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &s)
		fmt.Println(solve(n, s))
	}
}

// 1559B. Mocha and Red and Blue
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		var s string
		fmt.Fscan(reader, &s)
		a := []byte(s)
		i := 0
		for i < n && a[i] == '?' {
			i++
		}
		if i == n {
			blue := true
			for i > 0 {
				if blue {
					a[i-1] = 'B'
				} else {
					a[i-1] = 'R'
				}
				i--
				blue = !blue
			}
		}
		for i > 0 {
			if a[i] == 'B' {
				a[i-1] = 'R'
			} else {
				a[i-1] = 'B'
			}
			i--
		}
		for i < n {
			if a[i] == '?' {
				if a[i-1] == 'R' {
					a[i] = 'B'
				} else {
					a[i] = 'R'
				}
			}
			i++
		}
		fmt.Println(string(a))
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	var n int
	var s string
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n, &s)
		w1 := do(n, s)
		if ti != 0 {
			fmt.Fprintln(w)
		}
		fmt.Fprint(w, w1)
	}
}

var m = map[byte]byte{'R': 'B', 'B': 'R'}

func do(n int, s string) string {
	t := []byte(s)
	i := 0
	for i < n && t[i] == '?' {
		i++
	}
	if i == n {
		return strings.Repeat("BR", (n+1)/2)[:n]
	}
	for ; i >= 1; i-- {
		t[i-1] = m[t[i]]
	}
	for i = 1; i < n; i++ {
		if t[i] == '?' {
			t[i] = m[t[i-1]]
		}
	}
	return string(t)
}

package main

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

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

	tmpLine, _ := reader.ReadString('\n')
	testCount, _ := strconv.Atoi(strings.TrimSpace(tmpLine))

	for i := 0; i < testCount; i++ {
		reader.ReadString('\n')
		tmpLine, _ = reader.ReadString('\n')
		newArr := strings.Split(strings.TrimSpace(tmpLine), "")
		var count int
		for {
			newArr, count = solve(newArr)
			if count == 0 {
				break
			}
		}
		var res string
		for j := range newArr {
			res+=newArr[j]
		}
		fmt.Println(res)
	}
}

func solve(ss []string) ([]string, int) {
	var count int
	for i := range ss {
		switch ss[i] {
		case "B":
			if i != 0 {
				if ss[i-1] == "?" {
					ss[i-1] = "R"
				}
			}
			if i != len(ss)-1 {
				if ss[i+1] == "?" {
					ss[i+1] = "R"
				}
			}
		case "?":
			count++
		case "R":
			if i != 0 {
				if ss[i-1] == "?" {
					ss[i-1] = "B"
				}
			}
			if i != len(ss)-1 {
				if ss[i+1] == "?" {
					ss[i+1] = "B"
				}
			}
		}
	}
	if count == len(ss) {
		for i := range ss {
			if i%2 == 0 {
				ss[i] = "R"
			} else {
				ss[i] = "B"
			}
		}
		count = 0
	}
	return ss, count
}

func countSlozh(ss []string) int {
	var count int
	for i := 0; i < len(ss)-1; i++ {
		if ss[i] == ss[i+1] {
			count++
		}
	}
	return count
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution B --- */
func solve() {
	n := in.nextInt()

	s := []byte(in.next())

	var pos int

	for i := 0; i < n; i++ {
		if s[i] != '?' {
			pos = i
			break
		}
	}

	c := [2]byte{'B', 'R'}

	k := pos % 2
	if s[pos] == 'R' {
		k++
	}
	for i := 0; i < n; i++ {
		if s[i] == '?' {
			s[i] = c[k%2]
			k++
		} else if s[i] == 'B' {
			k = 1
		} else if s[i] == 'R' {
			k = 0
		}
	}

	out.println(string(s))
}

func cases() {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 1e7

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

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

func (in *In) nextDouble() float64 {
	in.scanner.Scan()
	i, _ := strconv.ParseFloat(in.scanner.Text(), 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		fmt.Fprintln(wr, solve())
	}
}

// imperfectness as the number of pairs of adjacent squares that share the same color.
func solve() string {
	n := scanInt()
	s := scanStr()

	b := make([]byte, n)
	q := 0
	for i := range s {
		if s[i] == '?' {
			q++
			continue
		}
		b[i] = s[i]
		if q == 0 {
			continue
		}
		j := i - q - 1
		var c byte
		if j < 0 {
			if q%2 == 0 {
				c = s[i]
			} else {
				c = op[s[i]]
			}
		} else {
			c = op[s[j]]
		}

		j++
		for ; j < i; j++ {
			b[j] = c
			c = op[c]
		}
		q = 0
	}

	if q > 0 {
		j := n - q - 1
		var c byte
		if j < 0 {
			c = 'R'
		} else {
			c = op[s[j]]
		}

		j++
		for ; j < n; j++ {
			b[j] = c
			c = op[c]
		}
	}
	return string(b)
}

var op = map[byte]byte{
	'R': 'B',
	'B': 'R',
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)

		// ARR := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARR[i])
		// }

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		le := 0
		begin := 0
		for i := 0; i < n; i++ {
			if STRING[i] == 63 {
				le++
			} else {
				begin = int(STRING[i])
				break
			}

		}
		if le == 0 {
			for i := 1; i < n; i++ {
				if STRING[i] == 63 {
					if STRING[i-1] == 66 {
						STRING[i] = 82
					} else {
						STRING[i] = 66
					}
				}
			}
		} else {
			if le%2 == 0 {
				if begin == 66 {
					STRING[0] = 66
				} else {
					STRING[0] = 82
				}
				for i := 1; i < n; i++ {
					if STRING[i] == 63 {
						if STRING[i-1] == 66 {
							STRING[i] = 82
						} else {
							STRING[i] = 66
						}
					}
				}
			} else {
				if begin == 66 {
					STRING[0] = 82
				} else {
					STRING[0] = 66
				}
				for i := 1; i < n; i++ {
					if STRING[i] == 63 {
						if STRING[i-1] == 66 {
							STRING[i] = 82
						} else {
							STRING[i] = 66
						}
					}
				}
			}
		}
		fmt.Println(string(STRING))

	}

}

package main

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

type Scanner struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

type state struct {
	pos int
	ch  byte
}

func expand(b []byte, i int, q *[]state) {
	if b[i] == '?' {
		panic("what")
	}

	ch := byte('B')
	if b[i] == 'B' {
		ch = 'R'
	}

	if l := i - 1; l >= 0 && b[l] == '?' {
		*q = append(*q, state{pos: l, ch: ch})
	}
	if r := i + 1; r < len(b) && b[r] == '?' {
		*q = append(*q, state{pos: r, ch: ch})
	}
}

func solve(s string) string {
	b := []byte(s)
	q := []state{}

	for i := range b {
		if b[i] != '?' {
			expand(b, i, &q)
		}
	}

	for len(q) > 0 {
		st := q[0]
		q = q[1:]

		if b[st.pos] == '?' {
			b[st.pos] = st.ch
			expand(b, st.pos, &q)
		}
	}

	if b[0] == '?' {
		for i := range b {
			if i%2 == 0 {
				b[i] = 'B'
			} else {
				b[i] = 'R'
			}
		}
	}

	return string(b)
}

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

	for i := 0; i < tests; i += 1 {
		stdin.Int()
		s := stdin.Word()
		fmt.Println(solve(s))
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		dp := make([][2]int, n)
		from := make([][2]int, n)
		if s[0] == 'B' {
			dp[0][1] = 1e9
		} else if s[0] == 'R' {
			dp[0][0] = 1e9
		}
		for i := 1; i < n; i++ {
			if s[i] == 'B' {

				dp[i][0] ,from[i][0] = min(dp[i-1][0]+1, dp[i-1][1])
				dp[i][1] = 1e9
			} else if s[i] == 'R' {
				dp[i][0] = 1e9
				dp[i][1],from[i][1] = min(dp[i-1][0], dp[i-1][1]+1)
			} else {
				dp[i][0],from[i][0]  = min(dp[i-1][0]+1, dp[i-1][1])
				dp[i][1] ,from[i][1] = min(dp[i-1][0], dp[i-1][1]+1)
			}
		}
		_,j := min(dp[n-1][0],dp[n-1][1])
		for i := len(s) - 1; i >= 0; i-- {
			v := s[i]
			if v == '?' {
				if j == 0 {
					s[i] = 'B'
				} else {
					s[i] ='R'
				}
				j = from[i][j]
			} else if v == 'B' {
				j = from[i][0]
			}  else {
				j = from[i][1]
			}
		}
		Fprintln(out, string(s))
	}

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

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

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

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

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 0; i+1 < n; i++ {
		if arr[i+1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i+1] = 'R'
			} else {
				arr[i+1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import (
    "fmt"
)

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

    for i := 0; i < tC; i++ {
        var (
            length int
            line string
        )
        fmt.Scanln(&length)
        fmt.Scanln(&line)
        if length == 1 && line == "?" {
            fmt.Println("R")
            continue
        }
        answ := []byte(line)
        contrary := map[byte]byte{
            'R': 'B',
            'B': 'R',
        }
        count := 0
        for _, v := range line {
            if v != '?' {
                count++
            }
        }

        if count == 0 {
            chars := []byte{'R', 'B'}
            for i, _ := range line {
                answ[i] = chars[i % 2]
            }
        } else {
            back, forw := 0, 1
            for forw < length {
                if answ[back] != '?' && answ[forw] == '?' {
                    answ[forw] = contrary[answ[back]]
                }
                back++
                forw++
            }
            forw, back = length-2, length-1
            for back > 0 {
                if answ[back] != '?' && answ[forw] == '?' {
                    answ[forw] = contrary[answ[back]]
                }
                back -= 1
                forw -= 1
            }
        }

        fmt.Println(string(answ))
    }
}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			n := iost.GetNextInt()
			s := iost.Text()
			idx := -1
			for i := 0; i < n; i++ {
				if s[i] != '?' {
					idx = i
					break
				}
			}
			prev := byte('B')
			if idx > -1 {
				if idx%2 == 0 {
					prev = s[idx]
				} else {
					if s[idx] == 'B' {
						prev = 'R'
					} else {
						prev = 'B'
					}
				}
			}
			iost.Print(string(prev))
			for i := 1; i < n; i++ {
				if s[i] == '?' {
					if prev == 'B' {
						prev = 'R'
						iost.Print("R")
					} else {
						prev = 'B'
						iost.Print("B")
					}
				} else {
					iost.Print(string(s[i]))
					prev = s[i]
				}
			}
			iost.Println()
		}()
	}
}

// 45min，'B' is byte, "B" is string

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'B'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import (
    "fmt"
)

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

    for i := 0; i < tC; i++ {
        var (
            length int
            line string
        )
        fmt.Scanln(&length)
        fmt.Scanln(&line)
        if length == 1 && line == "?" {
            fmt.Println("R")
            continue
        }
        answ := []byte(line)
        contrary := map[byte]byte{
            'R': 'B',
            'B': 'R',
        }

        back, forw := 0, 1
        for forw < length {
            if answ[back] != '?' && answ[forw] == '?' {
                answ[forw] = contrary[answ[back]]
            }
            back++
            forw++
        }
        forw, back = length-2, length-1
        for back > 0 {
            if answ[back] != '?' && answ[forw] == '?' {
                answ[forw] = contrary[answ[back]]
            }
            back -= 1
            forw -= 1
        }

        fmt.Println(string(answ))
    }
}

package main

import (
    "fmt"
)

func main() {
    var testCases int
    var length int
    fmt.Println("Scanning testcases")
    fmt.Scan(&testCases)

    for i := 0; i < testCases; i++ {
        fmt.Scan(&length)
        var row string
        fmt.Scan(&row)
        if length == 1 {
            if row == "?" {
                fmt.Println("B")
            } else {
                fmt.Println(row)
            }
        } else {
            fmt.Println(formAnsw(row))
        }
    }
}

func formAnsw(row string) string {
    back, forward := 0, 1
    contrary := map[string]string{
        "B": "R",
        "R": "B",
    }
    for ; forward < len(row);  {
        if row[back] == '?' && row[forward] == '?' {
            row = row[:back] + "RB" + row[forward+1:]
        } else if row[back] == '?' && row[forward] != '?' {
            row = row[:back] + contrary[string(row[forward])] + row[back+1:]
        } else if row[back] != '?' && row[forward] == '?' {
            row = row[:forward] + contrary[string(row[back])] + row[forward+1:]
        }
        back++
        forward++
    }
    return row
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n int
		var s string

		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fscanf(r, "%s\n", &s)

		res := []byte(s)

		for i := 0; i < len(res); i++ {
			if res[i] == '?' {
				cr := 0
				cb := 0
				if i > 0 {
					if res[i-1] == 'B' {
						cb++
					} else if res[i-1] == 'R' {
						cr++
					}
				}
				if i < n-1 {
					if res[i+1] == 'B' {
						cb++
					} else if res[i+1] == 'R' {
						cr++
					}
				}

				if cb < cr {
					res[i] = 'B'
				} else {
					res[i] = 'R'
				}
			}
		}

		fmt.Println(string(res))
	}
}


package main

import (
	"fmt"
)

func get_count(x int64, A [] int64) int64 {
	ret := x
	for _, v := range A {
		if v < x {
			ret--
		}
	}
	return ret
}

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		A := make([]int64, n)
		for i := 0; i < n; i++ {
			var s string
			fmt.Scan(&s)
			for j := 0; j < m; j++ {
				A[i] = (A[i] << 1) + int64(s[j] - '0')
			}
		}
		var tot int64 = 1
		tot = (tot << m) - 1
		target := (tot - int64(n)) >> 1
		var s int64 = 0
		e := tot
		for s < e {
			mid := s + ((e-s) >> 1)
			if(get_count(mid, A) >= target)  {
				e = mid
			} else {
				s = mid + 1
			}
		}
		for {
			is_in := false
			for _, v := range A {
				if v == s {
					is_in = true
					break
				}
			}
			if !is_in {
				break
			}
			s++
		}
		res := make([]rune, m)
		for i := 0; i < m; i++ {
			b := (s >> (m-1-i)) & 1
			if b == 1 {
				res[i] = '1'
			} else {
				res[i] = '0'
			}
		}
		fmt.Println(string(res))
	}

}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	search := func(n int64, f func(int64) bool) int64 {
		i, j := int64(0), n
		for i < j {
			h := (i + j) >> 1
			if f(h) {
				j = h
			} else {
				i = h + 1
			}
		}
		return i
	}

	var t, n, m int64
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		k := 1<<m - n
		midId := (k - 1) / 2
		ans := search(1<<m, func(x int64) bool {
			cnt := x
			for _, v := range a {
				if v <= x {
					cnt--
				}
			}
			return cnt >= midId
		})
		Fprintf(out, "%0*b\n", m, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	search := func(n int64, f func(int64) bool) int64 {
		i, j := int64(0), n
		for i < j {
			h := (i + j) >> 1
			if f(h) {
				j = h
			} else {
				i = h + 1
			}
		}
		return i
	}

	var t, n, m int64
	var s string
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		mid := (1<<m - n - 1) / 2
		ans := search(1<<m, func(x int64) bool {
			cnt := x
			for _, v := range a {
				if v <= x {
					cnt--
				}
			}
			return cnt >= mid
		})
		Fprintf(out, "%0*b\n", m, ans)
	}
}

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

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for i := rd(); i > 0; i-- {
		n, m := rdll(), rdll()
		a := make([]int64, n)
		for i := range a {
			s := rds()
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		target := ((1 << m) - n - 1) / 2
		var l, r int64 = 0, (1 << m) - 1
		for l <= r {
			mid := (l + r) >> 1
			cnt := 0
			for _, it := range a {
				if it < mid {
					cnt++
				}
			}
			if mid-int64(cnt) <= target {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		Fprintf(out, "%0*b\n", m, r)
	}

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Split(bufio.ScanWords)
	for i := rd(); i > 0; i-- {
		n, m := rdll(), rdll()
		a := make([]int64, n)
		for i := range a {
			var s string
			Fscan(in, &s)
			a[i], _ = strconv.ParseInt(s, 2, 64)
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		target := ((1 << m) - n - 1) / 2
		var l, r int64 = 0, (1 << m) - 1
		for l <= r {
			mid := (l + r) >> 1
			cnt := 0
			for _, it := range a {
				if it < mid {
					cnt++
				}
			}
			if mid-int64(cnt) <= target {
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		Fprintf(out, "%0*b\n", m, r)
	}

}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	f := 1
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int(b&15)
	}
	return f * x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	f := int64(1)
	if data[0] == '-' {
		f = -1
		data = data[1:]
	}
	for _, b := range data {
		x = x*10 + int64(b&15)
	}
	return f * x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	const mod int64 = 1e9 + 7
	var d string
	Fscan(bufio.NewReader(os.Stdin), &d)
	var s, k, t, n int64 = 0, 0, 1, int64(len(d))
	for i := n - 1; i >= 0; i-- {
		s += int64(d[i]&15) * (i*(i+1)/2%mod*t%mod + k)
		k = (k + (n-i)*t) % mod
		t = t * 10 % mod
	}
	Print(s % mod)
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func Max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func solve() {
	arr := []byte(next())

	var res int64

	var ways int64
	var pow int64 = 1

	for i := len(arr) - 1; i >= 0; i-- {
		res = Add(res, Mult(int64(i)*int64(i+1)/2, Mult(int64(arr[i]-'0'), pow)))
		res = Add(res, Mult(ways, int64(arr[i]-'0')))
		ways = Add(ways, Mult(int64(len(arr)-i), pow))
		pow = Mult(pow, 10)
	}

	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	// for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
	// printf("Case #%d:\n", i)
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

var reader = bufio.NewReader(os.Stdin)

var mod int64 = 1e9 + 7

func main() {
	var s string
	fmt.Fscan(reader, &s)

	var arr []int
	for _, c := range s {
		arr = append(arr, int(c-'0'))
	}

	n := len(arr)

	var total int64 = 0
	var tenPow int64 = 1
	var tenTotal int64 = 0
	var multiple int64 = 1
	for i := n - 1; i >= 0; i-- {
		// left combinations
		total = add(total, mul(int64(arr[i]), mul(nc2(int64(i)), tenPow)))

		// right combinations
		total = add(total, mul(int64(arr[i]), tenTotal))

		tenTotal = add(tenTotal, mul(tenPow, multiple))
		tenPow = mul(tenPow, 10)
		multiple = add(multiple, 1)
	}

	fmt.Println(total)
}

func add(a, b int64) int64 {
	return ((a+b)%mod + mod) % mod
}

func mul(a, b int64) int64 {
	return ((a*b)%mod + mod) % mod
}

func nc2(n int64) int64 {
	return add(n*(n+1)/2, 0)
}


package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt()

		for kk := k; kk > 0; kk-- {
			divisor := f(n)
			if divisor%2 == 0 {
				n += int64(kk << 1)
				break
			} else {
				n += divisor
			}
		}
		P(n)
	}

	close(O)
	oWg.Wait()
}

func f(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	sqr := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqr; i += 2 {
		if n%int64(i) == 0 {
			return int64(i)
		}
	}
	return n
}

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

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	if n&1 == 0 {
		fmt.Println(n + 2*k)
	} else {
		for i := 2; i <= n; i++ {
			if n%i == 0 {
				n += i
				break
			}
		}
		k--
		fmt.Println(n + 2*k)
	}

}

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

package main

import "fmt"

func main() {

	var t int

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

		var n,k int;

		fmt.Scan( &n, &k )

		if (n % 2 == 1) {

			i := 2

			for ; i < n/2; i++ {
				if n % i == 0 {
					break
				}
			}

			if n % i == 0 {
				n += i + 2 * ( k - 1 )
			} else {
				n += n + 2 * ( k - 1 )
			}

		} else {
			n += 2 * k
		}

		fmt.Print(n, "\n" )
	}
}

package main

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

type Scan struct {
	f *os.File
	in *bufio.Reader
	out *bufio.Writer
}

func setup() *Scan {
	r := &Scan{ f: nil }

	inputFile := os.Getenv("INPUT_FILE")
	if inputFile != "" {
		var err error
		if r.f, err = os.Open(inputFile); err == nil {
			os.Stdin = r.f
		}
	}
	r.in = bufio.NewReader(os.Stdin)
	r.out = bufio.NewWriter(os.Stdout)

	return r
}

func (r *Scan) close() {
	if r.f != nil {
		r.f.Close()
	}
	r.out.Flush()
}

func (r *Scan) readString() string {
	var x string
	fmt.Fscan(r.in, &x)
	return x
}

func (r *Scan) readInt() int {
	x, err := strconv.Atoi(r.readString())
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) readLongInt() int64 {
	x, err := strconv.ParseInt(r.readString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return x
}

func (r *Scan) strings(refs ... *string) {
	for _, ref := range refs {
		*ref = r.readString()
	}
}

func (r *Scan) ints(refs ... *int) {
	for _, ref := range refs {
		*ref = r.readInt()
	}
}

func (r *Scan) longInts(refs ... *int64) {
	for _, ref := range refs {
		*ref = r.readLongInt()
	}
}

func (r *Scan) print(s string) {
	fmt.Fprintf(r.out, "%s", s)
}

func smallestDivisor(x int64) int64 {
	for i := int64(2); i <= x*x; i++ {
		if x%i == 0 {
			return i
		}
	}
	return x
}

func main() {
	scan := setup()

	var t int
	var n, k int64

	scan.ints(&t)
	for tc := 0; tc < t; tc++ {
		scan.longInts(&n, &k)

		ans := n
		div := smallestDivisor(n)
		ans = n + div
		k--;
		if k > 0 {
			ans += 2 * k;
		}
		scan.print(fmt.Sprintf("%d\n", ans))
	}

	scan.close()
}

// https://codeforces.com/contest/1352/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 n, k int
	fmt.Fscan(input, &n, &k)

	minp := n
	for i := 2; i*i <= n; i++ {
		if n % i == 0 {
			minp = i
			break
		}
	}

	fmt.Println(2 * (k - 1) + (minp + n))
}

package main

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

func main()  {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		nks := scanner.Text()

		ps := strings.Fields(nks)

		n, err := strconv.Atoi(ps[0])

		if err != nil {
			panic(err)
		}

		k, err := strconv.Atoi(ps[1])

		if err != nil {
			panic(err)
		}

		ans := solve1(int64(n), int64(k))

		fmt.Println(ans)
	}
}

func solve1(n, k int64 ) int64 {

	if n % 2 == 0 {
		return 2 * k + n
	}

	var i int64
	for i = 2 ; i <= n ; i++ {
		if n % i == 0 {
			break
		}
	}

	n += i

	return 2 * (k - 1) + n
}

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

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, k int64
)

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		n, k = ReadInt64_2()
		solve(n, k)
	}
}

func solve(n, k int64) {
	tmp := divisor(int(n))
	sort.Sort(sort.IntSlice(tmp))

	D := []int64{}
	for i := 0; i < len(tmp); i++ {
		D = append(D, int64(tmp[i]))
	}

	ans := n
	ans += D[1]

	ans += (k - 1) * 2
	fmt.Println(ans)
}

// 約数の列挙: O(sqrt(n))
func divisor(n int) []int {
	res := []int{}

	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / 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"
	"fmt"
	"os"
)

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

	var t int
	var n, k int64

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &n, &k)

		minDivisor := getMinDivisor(n)

		fmt.Fprintln(w, n+minDivisor+2*(k-1))
	}
}

func getMinDivisor(n int64) int64 {
	if n%2 == 0 {
		return 2
	}

	var i int64
	for i = 3; i*i <= n; i += 2 {
		if n%i == 0 {
			return i
		}
	}

	return n
}

package main

import (
	"fmt"
)

func solve(n, k int64) int64 {
	if k == 0 {
		return n
	} else if n % 2 == 0 {
		return n + k*2
	} else {
		return solve(n+f(n), k-1)
	}
}

func f(n int64) int64{
	for i := int64(2); i*i <= n; i++ {
		if n % i == 0 {
			return i
		}
	}
	return n
}

func main() {
	var T int
	var n, k int64
	fmt.Scanf("%d\n", &T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scanf("%d%d\n", &n, &k)
		fmt.Printf("%v\n", solve(n, k))
	}
}

package main

import "fmt"

func main() {
	n := int(1e6) * 2
	data := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if data[i] != 0 {
			continue
		}
		data[i] = i
		if i > n/i {
			continue
		}
		for j := i * i; j <= n; j += i {
			if data[j] == 0 {
				data[j] = i
			}
		}
	}

	var t int
	fmt.Scan(&t)

	for ; t > 0; t-- {
		var n, k int
		fmt.Scan(&n, &k)
		ans := int64(n)
		ans += int64(data[n])
		k--
		if k > 0 {
			ans += int64(2 * k)
		}
		fmt.Println(ans)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

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

func gcd(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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, k := reader.NextInt64(), reader.NextInt64()
		writer.Printf("%d\n", sol(n, k))
	}
}

func sol(n, k int64) int64 {
	for ; k > 0; k-- {
		for i := int64(2); i <= n; i++ {
			if n % i == 0 {
				if i == 2 {
					return n + k*2
				}
				n += i
				break
			}
		}
	}
	return n
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt64(), ScanInt()

		for kk := k; kk > 0; kk-- {
			divisor := f(n)
			if divisor%2 == 0 {
				n += int64(math.Pow(2, float64(kk)))
				break
			} else {
				n += divisor
			}
		}
		P(n)
	}

	close(O)
	oWg.Wait()
}

func f(n int64) int64 {
	if n%2 == 0 {
		return 2
	}
	sqr := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqr; i += 2 {
		if n%int64(i) == 0 {
			return int64(i)
		}
	}
	return n
}

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

func solve(n, k int64) int64 {
	if k == 0 {
		return n
	} else if n % 2 == 0 {
		return n + k*2
	} else {
		return solve(n+f(n), k-1)
	}
}

func f(n int64) int64{
	for i := int64(2); i*i <= n; i++ {
		if n % i == 0 {
			return i
		}
	}
	return n
}

func main() {
	var T int
	var n, k int64
	fmt.Scanf("%v", &T)
	for kase := 1; kase <= T; kase++ {
		fmt.Scanf("%d%d", &n, &k)
		fmt.Printf("%v\n", solve(n, k))
	}
}


package main

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

const MEGACITY int64 = 1000000

type Pair struct {
	X      int
	Y      int
	K      int64
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Less(i, j int) bool {
	return p[i].Radius < p[j].Radius
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

func abs(x, y int64) int64 {
	if x > y {
		return x - y
	}
	return y - x
}

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

	var n int
	var s int64
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		p.Radius = p.Dist()
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	sum := s
	for _, p := range pairs {
		sum = sum + p.K
		p.K = sum
		//fmt.Fprintln(writer, p.X, p.Y, p.K, p.Radius)
	}
	var min int64
	min = math.MaxInt64
	idx := -1
	for i := 0; i < n; i++ {
		if pairs[i].K >= MEGACITY {
			if min > pairs[i].K {
				min = pairs[i].K
				idx = i
			}
		}
	}
	if idx >= 0 && idx < n {
		fmt.Fprintf(writer, "%.7f\n", pairs[idx].Radius)
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}

package main

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

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

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

	n, s := nextInt(), nextInt()

	radius := make([]float64, n)
	numberOfPeoples := make([]int, n)
	var a, b float64

	for i:=0; i<n; i++ {
		a, b = nextFloat(), nextFloat()
		radius[i] = math.Sqrt(a*a + b*b)
		numberOfPeoples[i] = nextInt()
	}

	minIndex := 0
	for {
		minIndex = min(radius)

		if minIndex == -1 {
			println(-1)
			return
		}
		// println(minIndex)
		s += numberOfPeoples[minIndex]

		if s >= 1000000 {
			break
		}
		radius[minIndex] = 0
	}

	println(radius[minIndex])
}

func min(a []float64) (index int) {
	for a[index] == 0 {
		index++

		if index >= len(a) {
			return -1
		}
	}

	for i:=index+1; i<len(a); i++ {
		if a[i]!=0 && a[i]<a[index] {
			index = i
		}
	}

	if a[index] == 0 {
		return -1
	}

	return
}

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

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

//https://codeforces.com/problemset/problem/424/B
//http://bigocoder.com/courses/BLUE20/BLUE20_LEC13/BLUE_L13P03/statement
package main

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

type city struct {
	r int
	p int
}

func solve(cities []city, population int) int {
	for i := range cities {
		population += cities[i].p
		if population >= 1000000 {
			return cities[i].r
		}
	}

	return -1
}

func calculateRadius(x int, y int) int {
	//formula : sqt((x1-x0)2 + (y1-y0)2)
	return x*x + y*y
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, population, x, y, p int
	fmt.Fscanf(r, "%d %d\n", &n, &population)
	cities := make([]city, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d %d %d\n", &x, &y, &p)
		cities[i] = city{calculateRadius(x, y), p}
	}

	sort.Slice(cities, func(i, j int) bool { return cities[i].r < cities[j].r })

	result := solve(cities, population)

	if result == -1 {
		fmt.Fprintf(os.Stdout, "%d\n", result)
	} else {
		fmt.Fprintf(os.Stdout, "%.7f\n", math.Sqrt(float64(result)))
	}
}

package main

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

const MEGACITY = 1000000

type Pair struct {
	X      int
	Y      int
	K      int
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Less(i, j int) bool {
	if p[i].X == p[j].X {
		return p[i].Y < p[j].Y
	}
	return p[i].Y < p[i].Y
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

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

	var n, s int
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	dist := s
	for _, p := range pairs {
		p.Radius = p.Dist()
		dist = dist + p.K
		p.K = dist
	}
	low := 0
	high := n - 1
	mid := -1
	for low <= high {
		mid = (low + high) >> 1
		p := pairs[mid]
		if p.K < MEGACITY {
			low = mid + 1
		} else if p.K > MEGACITY {
			high = mid - 1
		} else {
			break
		}
	}
	if mid >= 0 && mid < n {
		p := pairs[mid]
		if p.K >= MEGACITY {
			fmt.Fprintf(writer, "%.7f\n", p.Radius)
		} else {
			fmt.Fprintf(writer, "-1\n")
		}
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}

package main

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

const MEGACITY = 1000000

type Pair struct {
	X      int
	Y      int
	K      int
	Radius float64
}

type Pairs []*Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Less(i, j int) bool {
	return p[i].Dist() < p[j].Dist()
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pair) Dist() float64 {
	return math.Sqrt(float64(p.X*p.X + p.Y*p.Y))
}

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

	var n, s int
	fmt.Fscanf(reader, "%d %d\n", &n, &s)
	pairs := make([]*Pair, 0)
	for i := 1; i <= n; i++ {
		p := Pair{}
		fmt.Fscanf(reader, "%d %d %d\n", &p.X, &p.Y, &p.K)
		pairs = append(pairs, &p)
	}
	sort.Sort(Pairs(pairs))
	dist := s
	for _, p := range pairs {
		p.Radius = p.Dist()
		dist = dist + p.K
		p.K = dist
		//fmt.Fprintln(writer, p.X, p.Y, p.K, p.Radius)
	}
	low := 0
	high := n - 1
	mid := -1
	for low <= high {
		mid = (low + high) >> 1
		p := pairs[mid]
		//fmt.Println(p.X, p.Y, p.K, p.Radius)
		if p.K < MEGACITY {
			low = mid + 1
		} else if p.K > MEGACITY {
			high = mid - 1
		} else {
			break
		}
	}
	if mid >= 0 && mid < n {
		p := pairs[mid]
		//fmt.Println("mid is ", p.X, p.Y, p.K, p.Radius)
		if p.K >= MEGACITY {
			fmt.Fprintf(writer, "%.7f\n", p.Radius)
		} else {
			fmt.Fprintf(writer, "-1\n")
		}
	} else {
		fmt.Fprintf(writer, "-1\n")
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var ans [][]byte
	solve := func(Case int) (_b bool) {
		var n, m, k int
		Fscan(in, &n, &m, &k)

		ans = make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}

		mx := 0
		base := 0
		if m&1 == 0 {
			mx = n * m / 2

			if n&1 == 0 {

			} else {
				base = m / 2
			}

			if k < base {
				return false
			}
			if (k-base)&1 > 0 {
				return false
			}

		} else { // m&1==1 && n&1==0
			mx = n*m/2 - n/2
			if k > mx {
				return false
			}
			if k&1 > 0 {
				return false
			}

		}
		kk := k
		_ = kk

		if base > 0 {
			for j := 1; j < m && k > 0; j += 2 {
				i := 0
				if (i+j/2)&1 == 0 {
					ans[i][j-1] = 'a'
					ans[i][j] = 'a'
				} else {
					ans[i][j-1] = 'b'
					ans[i][j] = 'b'
				}

				k--
			}
		}

		for j := 1; j < m && k > 0; j += 2 {
			i := 0
			if base > 0 {
				i = 1
			}
			for ; i < n && k > 0; i++ {
				if (i+j/2)&1 == 0 {
					ans[i][j-1] = 'a'
					ans[i][j] = 'a'
				} else {
					ans[i][j-1] = 'b'
					ans[i][j] = 'b'
				}

				k--
			}
		}

		for j := 0; j < m; j++ {
			i := 0
			for ; i < n && ans[i][j] > 0; i++ {
			}
			for ; i < n; i += 2 {
				if (i/2+j)&1 == 0 {
					ans[i][j] = 'c'
					ans[i+1][j] = 'c'
				} else {
					ans[i][j] = 'd'
					ans[i+1][j] = 'd'
				}
			}
		}

		return true
	}

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

		if solve(Case) {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
			continue
		}

		for _, r := range ans {
			Fprintln(out, string(r))
		}
	}

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

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := 0; i < n; i++ {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j] = c
				ans[n-1][j+1] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < n; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[j][m-1] = c
				ans[j+1][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			Fprintf(out, "%s\n", ans[i])
		}
	}
}

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

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := range ans {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 || k&1 > 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 1; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j-1] = c
				ans[n-1][j] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for i := 1; i < n; i += 2 {
				c := 'f' ^ byte(i/2&1)
				ans[i-1][m-1] = c
				ans[i][m-1] = c
			}
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k--
					c := 'b' ^ byte(j/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c
					ans[i][j-1] = c ^ 1
					ans[i][j] = c ^ 1
				} else {
					c := 'd' ^ byte(i/2&1)
					ans[i-1][j-1] = c
					ans[i-1][j] = c ^ 1
					ans[i][j-1] = c
					ans[i][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for _, r := range ans {
			Fprintf(out, "%s\n", r)
		}
	}
}

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

package main

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

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

	var T, n, m, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m, &k)
		ans := make([][]byte, n)
		for i := 0; i < n; i++ {
			ans[i] = make([]byte, m)
		}
		if n&1 > 0 {
			k -= m / 2
			if k < 0 {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < m; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[n-1][j] = c
				ans[n-1][j+1] = c
			}
		} else if m&1 > 0 {
			if k > m/2*n {
				Fprintln(out, "NO")
				continue
			}
			for j := 0; j < n; j += 2 {
				c := 'f' ^ byte(j/2&1)
				ans[j][m-1] = c
				ans[j+1][m-1] = c
			}
		}
		if k&1 > 0 {
			Fprintln(out, "NO")
			continue
		}
		for i := 1; i < n; i += 2 {
			for j := 1; j < m; j += 2 {
				if k > 0 {
					k -= 2
					c := 'b' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				} else {
					c := 'd' ^ byte(j/2&1)
					ans[i][j-1] = c
					ans[i][j] = c
					ans[i-1][j-1] = c ^ 1
					ans[i-1][j] = c ^ 1
				}
			}
		}
		Fprintln(out, "YES")
		for i := 0; i < n; i++ {
			Fprintf(out, "%s/n", ans[i])
		}
	}
}

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


package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < n; i++ {
		s, _ := reader.ReadString('\n')
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}
//	for i := 0; i < n; i++ {
//		for j := 0; j < m; j++ {
//			fmt.Print(a[i][j], " ")
//		}
//		fmt.Println()
//	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn+1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[j][i] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[j][i]]++
			if maxw < a[j][i] {
				maxw = a[j][i]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn + 1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var n, m int
	fmt.Scan(&n, &m)
	a := make([][]int, m+1)
	for i := range a {
		a[i] = make([]int, n+1)
	}
	scan := bufio.NewScanner(os.Stdin)
	scan.Scan()
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[j][i] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := make([]int, m+1)
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[j][i]]++
			if maxw < a[j][i] {
				maxw = a[j][i]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	const maxn = 5010
	var (
		n, m int
		a    [maxn][maxn]int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	scan := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scan.Scan()
		s := scan.Text()
		d := 0
		for j := 0; j < m; j++ {
			if s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	bucket := make([]int, maxn+1)
	for j := 0; j < m; j++ {
		for i := 0; i <= m; i++ {
			bucket[i] = 0
		}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	const maxn = 5010
	var (
		n, m int
		a [maxn][maxn]int
	)
	fmt.Scanf("%d %d", &n, &m)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s", &s)
		d := 0
		for j := 0; j < m; j++ {
			if j < len(s) && s[j] == '1' {
				d++
			} else {
				d = 0
			}
			a[i][j] = d
		}
	}
//	for i := 0; i < n; i++ {
//		for j := 0; j < m; j++ {
//			fmt.Print(a[i][j], " ")
//		}
//		fmt.Println()
//	}

	ans := 0
	update := func(a int) {
		if ans < a {
			ans = a
		}
	}

	for j := 0; j < m; j++ {
		bucket := [maxn+1]int{}
		maxw := 0
		for i := 0; i < n; i++ {
			bucket[a[i][j]]++
			if maxw < a[i][j] {
				maxw = a[i][j]
			}
		}
		rows := 0
		for w := maxw; w >= 1; w-- {
			rows += bucket[w]
			update(rows * w)
		}
	}
	fmt.Println(ans)
}