You are given a string $$$s$$$ consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'. Note that each of the characters '?' is replaced independently from the others.A string $$$t$$$ of length $$$n$$$ is called a palindrome if the equality $$$t[i] = t[n-i+1]$$$ is true for all $$$i$$$ ($$$1 \le i \le n$$$).For example, if $$$s=$$$"01?????0", $$$a=4$$$ and $$$b=4$$$, then you can replace the characters '?' in the following ways:   "01011010";  "01100110". For the given string $$$s$$$ and the numbers $$$a$$$ and $$$b$$$, replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 2 \cdot 10^5$$$, $$$a + b \ge 1$$$). The second line of each test case contains the string $$$s$$$ of length $$$a+b$$$, consisting of the characters '0', '1', and '?'. It is guaranteed that the sum of the string lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output:    "-1", if you can't replace all the characters '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and that it contains exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1';  the string that is obtained as a result of the replacement, otherwise.  If there are several suitable ways to replace characters, you can output any.

package main

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

func main() {
	/*rand.Seed(time.Now().Unix())

	for k := 0; k < 100; k++ {
		a := 1 + rand.Intn(10)
		b := 1 + rand.Intn(10)

		bts := make([]byte, a + b)

		s := "10?"

		for p := 0 ; p < len(bts); p++ {
			r := rand.Intn(3)
			bts[p] = s[r]
		}

		fmt.Printf("a == %d, b == %d, arr = %s", a, b , string(bts))
		fmt.Println()

		ans := solve(string(bts), a, b)

		if ans == "-1" {
			fmt.Println("-1")

		} else {
			var aCount int
			var bCount int

			n := len(ans)

			for j := 0; j < len(ans)/2; j++ {
				if ans[j] == '1' {
					if ans[n - j - 1] != '1' {
						panic("wrong")
					} else {
						bCount +=2
					}
				} else if ans[j] == '0' {
					if ans[n - j - 1] != '0' {
						panic("wring")
					} else {
						aCount +=2
					}
				} else {
					panic("wrong")
				}
			}

			if n % 2 == 1 {
				if ans[n/2] == '1' {
					bCount++
				} else if ans[n/2] == '0' {
					aCount++
				} else {
					panic("wrong")
				}
			}
			if aCount > a || bCount > b {
				panic("wrong")
			}
		}
	}*/

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	aInit := a
	bInit := b

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}
	if a < 0 || b < 0 {
		return "-1"
	}

	var count int

	for i := 0; i < n/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}

			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
			}
			bts[i] = '1'
			bts[n - i - 1] = '1'

		} else if s[i] == '?' {
			if s[n - i - 1] == '1' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
				bts[i] = '1'
				bts[n - i - 1] = '1'

			} else if s[n - i - 1] == '0' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}
				bts[i] = '0'
				bts[n - i - 1] = '0'

			} else if s[n - i - 1] == '?' {
				count++
				bts[i] = '?'
				bts[n - i - 1] = '?'

			} else {
				panic("unkown2")
			}

		} else {
			panic("unknown")
		}
	}

	if n % 2 == 1 {
		if s[n/2] == '?' {
			if aInit % 2 == 1 && a > 0 {
				a--
				bts[n/2] = '0'
			} else if bInit % 2 == 1 && b > 0 {
				b--
				bts[n/2] = '1'
			}
		} else {
			bts[n/2] = s[n/2]
		}
	}

	if a + b >= 2 * count {

		for i := 0; i < n/2; i++ {
			if bts[i] == '?' {
				if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a-=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b-=2
				} else {
					return "-1"
				}
			}
		}

	} else {
		return "-1"
	}

	return string(bts)
}

package main

import (
	"fmt"
	"strings"
)

func genPalindrome(str string, nOnes, nZeros int) string {
	left, right := 0, len(str)-1
	arr := make([]byte, len(str))
	for left <= right {
		if str[right] != str[left] {
			if str[left] == '?' {
				arr[left] = str[right]
				arr[right] = str[right]
			} else if str[right] == '?' {
				arr[left] = str[left]
				arr[right] = str[left]
			} else {
				return "-1"
			}
		} else {
			arr[left] = str[left]
			arr[right] = str[right]
		}
		if arr[left] == '1' {
			if left != right {
				nOnes -= 2
			} else {
				nOnes--
			}
		} else if arr[left] == '0' {
			if left != right {
				nZeros -= 2
			} else {
				nZeros--
			}
		}
		left++
		right--
	}
	left, right = 0, len(str)-1
	for left < right {
		if arr[left] == '?' {
			if nOnes > nZeros {
				arr[left] = '1'
				arr[right] = '1'
				nOnes -= 2
			} else {
				arr[left] = '0'
				arr[right] = '0'
				nZeros -= 2
			}
		}
		if nOnes < 0 || nZeros < 0 {
			return "-1"
		}
		left++
		right--
	}
	if left == right && arr[left] == '?' {
		if nOnes > nZeros {
			nOnes--
			arr[left] = '1'
		} else {
			nZeros--
			arr[left] = '0'
		}
	}
	if nZeros != 0 || nOnes != 0 {
		return "-1"
	}
	var sb strings.Builder
	for _, v := range arr {
		sb.WriteByte(v)
	}
	return sb.String()

}

func main() {
	var nTests int
	fmt.Scanf("%d\n", &nTests)
	for i := 0; i < nTests; i++ {
		var nZeros, nOnes int
		fmt.Scanf("%d %d\n", &nZeros, &nOnes)
		var str string
		fmt.Scanf("%s\n", &str)
		str = genPalindrome(str, nOnes, nZeros)
		fmt.Println(str)
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)
		var sb string
		fmt.Fscan(reader, &sb)

		s := []byte(sb)
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				b--
			} else if s[i] == '0' {
				a--
			}
		}
		ok := true
		i := 0
		j := len(sb) - 1
		for i <= j {
			if s[i] != '?' && s[j] != '?' {
				if s[i] != s[j] {
					ok = false
					break
				}
			}
			i++
			j--
		}
		i = 0
		j = len(sb) - 1
		if ok {
			for i <= j {
				if (s[i] == '?' || s[j] == '?') && (s[i] != s[j]) {
					if s[i] == '?' {
						s[i] = s[j]
						if s[j] == '1' {
							b -= 1
						} else {
							a -= 1
						}
					} else {
						s[j] = s[i]
						if s[j] == '1' {
							b -= 1
						} else {
							a -= 1
						}
					}

				}
				i++
				j--
			}
		}
		i = 0
		j = len(sb) - 1
		if ok {
			for i <= j {
				if s[i] == '?' && s[j] == '?' {
					if i == j {
						if a > 0 {
							s[i] = '0'
							a--
						} else if b > 0 {
							s[i] = '1'
							b--
						}
					} else {
						if a > 1 {
							s[i] = '0'
							s[j] = '0'
							a -= 2
						} else if b > 1 {
							s[i] = '1'
							s[j] = '1'
							b -= 2
						}
					}
				}
				i++
				j--
			}
		}
		if a != 0 || b != 0 {
			ok = false
		}
		if ok {
			write(f, string(s), "\n")
		} else {
			write(f, "-1\n")
		}
	}
}

package main

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

func Solve() {
	var n, m int
	scan(&n, &m)
	var s string
	scan(&s)
	t := []rune(s)
	l, r := 0, n+m-1
	for l < r {
		if t[l] != t[r] {
			if t[l] != '?' && t[r] != '?' {
				println(-1)
				return
			} else {
				if t[l] == '?' {
					t[l] = t[r]
				} else {
					t[r] = t[l]
				}
			}
		}
		l++
		r--
	}
	//println(string(t))
	l, r = 0, n+m-1
	for l <= r {
		switch {
		case t[l] == '0':
			n--
		case t[l] == '1':
			m--
		}
		if l != r {
			switch {
			case t[r] == '0':
				n--
			case t[r] == '1':
				m--
			}
		}
		l++
		r--
	}
	//println(n, m)
	l, r = 0, len(t)-1
	for l <= r {
		if t[l] == '?' {
			if l == r {
				if n >= m {
					t[l] = '0'
					n -= 1
				} else {
					t[l] = '1'
					m -= 1
				}
			} else {
				if n >= m {
					t[l] = '0'
					t[r] = '0'
					n -= 2
				} else {
					t[l] = '1'
					t[r] = '1'
					m -= 2
				}
			}
		}
		l++
		r--
	}
	//println(n, m)
	if n == 0 && m == 0 {
		println(string(t))
	} else {
		println(-1)
	}
}

func main() {
	T := 0
	in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	if T == 0 {
		scan(&T)
	}
	for t := 0; t < T; t++ {
		Solve()
	}
	out.Flush()
}

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

func scan(a ...interface{})    { Fscan(in, a...) }
func print(a ...interface{})   { Fprint(out, a...) }
func println(a ...interface{}) { Fprintln(out, a...) }

package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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
}

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	var n, m int
	fmt.Scan(&n, &m)
	var s string
	fmt.Scan(&s)
	t := []rune(s)
	l, r := 0, n+m-1
	for l < r {
		if t[l] != t[r] {
			if t[l] != '?' && t[r] != '?' {
				fmt.Println(-1)
				return
			} else {
				if t[l] == '?' {
					t[l] = t[r]
				} else {
					t[r] = t[l]
				}
			}
		}
		l++
		r--
	}
	//fmt.Println(string(t))
	l, r = 0, n+m-1
	for l <= r {
		switch {
		case t[l] == '0':
			n--
		case t[l] == '1':
			m--
		}
		if l != r {
			switch {
			case t[r] == '0':
				n--
			case t[r] == '1':
				m--
			}
		}
		l++
		r--
	}
	//fmt.Println(n, m)
	l, r = 0, len(t)-1
	for l <= r {
		if t[l] == '?' {
			if l == r {
				if n >= m {
					t[l] = '0'
					n -= 1
				} else {
					t[l] = '1'
					m -= 1
				}
			} else {
				if n >= m {
					t[l] = '0'
					t[r] = '0'
					n -= 2
				} else {
					t[l] = '1'
					t[r] = '1'
					m -= 2
				}
			}
		}
		l++
		r--
	}
	//fmt.Println(n, m)
	if n == 0 && m == 0 {
		fmt.Println(string(t))
	} else {
		fmt.Println(-1)
	}
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}
//114514 1919810

package main

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

type pos struct {
	i int
	j int
}

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

	solve := func() {
		var a, b int
		Fscan(in, &a, &b)
		var str []byte
		var cnt [2]int
		var empty_num []pos
		var unique_num []pos
		Fscan(in, &str)

		for l, r := 0, len(str)-1; l <= r; l, r = l+1, r-1 {
			if str[l] == '?' && str[r] == '?' {
				if l != r {
					empty_num = append(empty_num, pos{l, r})
				} else {
					unique_num = append(unique_num, pos{l, r})
				}

			} else {
				if str[l] == '?' {
					str[l] = str[r]
				} else if str[r] == '?' {
					str[r] = str[l]
				}
				if str[l] != str[r] {
					Fprintln(out, -1)
					return
				} else {
					cnt[str[l]-'0']++
					if l != r {
						cnt[str[r]-'0']++
					}
				}
			}
		}
		// Fprint(out, cnt[0], cnt[1])
		if cnt[0] > a || cnt[1] > b {
			Fprintln(out, -1)
		} else {
			for i := 0; i < (a-cnt[0])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '0'
				str[v] = '0'
				empty_num = empty_num[:len(empty_num)-1]
			}
			for i := 0; i < (b-cnt[1])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '1'
				str[v] = '1'
				empty_num = empty_num[:len(empty_num)-1]
			}
			if len(unique_num) == 1 {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					if (a-cnt[0])%2 == 1 {
						str[len(str)/2] = '0'
					} else {
						str[len(str)/2] = '1'
					}

					Fprintln(out, string(str))
				}
			} else {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					Fprintln(out, string(str))
				}
			}
		}

	}

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

}

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func replace(str []byte, a int, b int) string {
	N := len(str)
	l := 0
	r := N - 1
	for l < r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if str[r] == '0' {
			a--
		} else if str[r] == '1' {
			b--
		}
		if str[l] == '?' && str[r] != '?' {
			if str[r] == '0' {
				str[l] = '0'
				a--
			} else {
				str[l] = '1'
				b--
			}
		} else if str[l] != '?' && str[r] == '?' {
			if str[l] == '0' {
				str[r] = '0'
				a--
			} else {
				str[r] = '1'
				b--
			}
		}
		if a < 0 || b < 0 || str[l] != str[r] {
			return "-1"
		}
		l++
		r--
	}
	if l == r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if a < 0 || b < 0 {
			return "-1"
		}
	}

	l = 0
	r = N - 1
	for l < r {
		if str[l] == '?' {
			if a >= 2 {
				str[l] = '0'
				str[r] = '0'
				a -= 2
			} else {
				str[l] = '1'
				str[r] = '1'
				b -= 2
			}
		}
		if a < 0 || b < 0 {
			return "-1"
		}
		l++
		r--
	}
	if l == r && str[l] == '?' {
		if a > 0 {
			str[l] = '0'
			a--
		} else if b > 0 {
			str[l] = '1'
			b--
		} else {
			return "-1"
		}
	}
	if a > 0 || b > 0 {
		return "-1"
	}
	return string(str)
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.nextInt()
		b := sc.nextInt()
		str := []byte(sc.next())
		ans := replace(str, a, b)
		fmt.Fprintln(wr, ans)
	}

}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var a, b int
		var s string
		fmt.Fscan(in, &a, &b, &s)

		n := a + b
		m := make([]rune, n)
		f := true
		for i := 0; i < n/2; i++ {
			if s[i] != '?' {
				m[i] = rune(s[i])
				if s[i] == '0' {
					a--
				} else {
					b--
				}
			}

			if s[n-i-1] != '?' {
				m[n-i-1] = rune(s[n-i-1])
				if s[n-i-1] == '0' {
					a--
				} else {
					b--
				}
			}

			if s[i] != '?' && s[n-1-i] != '?' && s[i] != s[n-1-i] {
				f = false
				break
			}

			if s[i] != '?' && s[n-i-1] == '?' {
				if s[i] == '0' {
					m[n-i-1] = '0'
					a--
				} else {
					m[n-i-1] = '1'
					b--
				}
			} else if s[i] == '?' && s[n-i-1] != '?' {
				if s[n-i-1] == '0' {
					m[i] = '0'
					a--
				} else {
					m[i] = '1'
					b--
				}
			}

			if a < 0 || b < 0 {
				f = false
				break
			}
		}

		for i := 0; i < n/2; i++ {
			if m[i] == 0 {
				if a > b {
					m[i], m[n-i-1] = '0', '0'
					a -= 2
				} else {
					m[i], m[n-i-1] = '1', '1'
					b -= 2
				}
			}

			if a < 0 || b < 0 {
				f = false
				break
			}
		}

		if n%2 != 0 {
			mid := n / 2

			if s[mid] != '?' {
				m[mid] = rune(s[mid])
				if s[mid] == '0' {
					a--
				} else {
					b--
				}
			} else {
				if a > 0 {
					m[mid] = '0'
					a--
				} else {
					m[mid] = '1'
					b--
				}
			}
		}

		if !f || (a != 0 && b != 0) {
			fmt.Fprintln(out, -1)
		} else {
			for _, ch := range m {
				fmt.Fprintf(out, "%c", ch)
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

/*

 */

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

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

	for ; t > 0; t-- {
		var a, b int
		scanf("%d %d\n", &a, &b)

		runeToCnt := make(map[rune]int)
		runeToCnt['0'] = a
		runeToCnt['1'] = b

		var s string
		scanf("%s\n", &s)

		for _, r := range s {
			if r != '?' {
				runeToCnt[r]--
			}
		}

		res := []rune(s)

		for i := 0; i < len(res)/2; i++ {
			lr := res[i]

			j := len(res) - i - 1
			rr := res[j]

			switch {
			case lr != '?' && rr == '?':
				res[j] = lr
				runeToCnt[lr]--
			case lr == '?' && rr != '?':
				res[i] = rr
				runeToCnt[rr]--
			}
		}

		for i := 0; i < len(s)/2; i++ {
			if res[i] == '?' {
				filler := rune(0)
				if runeToCnt['0'] > 1 {
					filler = '0'
				} else if runeToCnt['1'] > 1 {
					filler = '1'
				} else {
					break
				}

				res[i] = filler
				res[len(s)-i-1] = filler

				runeToCnt[filler] -= 2
			}
		}

		midIdx := (len(res) - 1) / 2

		if len(res)%2 != 0 {
			if res[midIdx] == '?' {
				if runeToCnt['0'] == 1 {
					res[midIdx] = '0'
				} else if runeToCnt['1'] == 1 {
					res[midIdx] = '1'
				}
			}
		}

		isPalindrome := true
		zeroCnt := 0
		oneCnt := 0

		for i := range res {
			if res[i] == '0' {
				zeroCnt++
			} else if res[i] == '1' {
				oneCnt++
			}

			j := len(res) - i - 1
			if res[i] == '?' || res[i] != res[j] {
				isPalindrome = false
				break
			}
		}

		if isPalindrome && zeroCnt == a && oneCnt == b {
			fmt.Fprintln(writer, string(res))
		} else {
			fmt.Fprintln(writer, -1)
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

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

//goland:noinspection GoUnusedFunction
func max(nums ...int64) int64 {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var num [2]int
		Fscan(in, &num[0], &num[1])
		s := make([]byte, num[0] + num[1])
		Fscan(in, &s)

		solve := func() {
			left, right := 0, len(s) - 1
			for left <= right {
				if s[left] == s[right] && s[left] == '?' {
					left++; right--
					continue
				}
				if s[left] == '?' {
					s[left] = s[right]
				} else if s[right] == '?' {
					s[right] = s[left]
				} else if s[left] != s[right] {
					Fprintln(out, -1)
					return
				}
				num[int(s[left] - '0')] -= 2
				if left == right {
					num[int(s[left] - '0')]++
				}
				if num[int(s[left] - '0')] < 0 {
					Fprintln(out, -1)
					return
				}
				left++; right--
			}
			left, right = 0, len(s) - 1
			for left <= right {
				if left == right && s[left] == '?' {
					if num[0] == 1 {
						num[0]--
						s[left] = '0'
					} else if num[1] == 1 {
						num[1]--
						s[left] = '1'
					} else {
						Fprintln(out, -1)
						return
					}
				}
				if left != right && s[left] == '?' && s[right] == '?' {
					if num[0] >= 2 {
						num[0] -= 2
						s[left], s[right] = '0', '0'
					} else if num[1] >= 2 {
						num[1] -= 2
						s[left], s[right] = '1', '1'
					} else {
						Fprintln(out, -1)
						return
					}
				}
				left++; right--
			}
			Fprintln(out, string(s))
		}
		solve()
	}
}

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

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

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

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

package main

import (
	"fmt"
)

func solve() string {
	var a, b int
	fmt.Scanf("%d%d\n", &a, &b)
	var s string
	fmt.Scanf("%s\n", &s)
	l := a + b
	arr := []byte(s)

	for i := 0; i < l/2; i++ {
		j := l - i - 1
		if arr[i] == 48 || arr[j] == 48 {
			if arr[j] == 49 || arr[i] == 49 {
				return "-1"
			}
			arr[i], arr[j] = 48, 48
			a -= 2
		} else if arr[i] == 49 || arr[j] == 49 {
			if arr[j] == 48 || arr[i] == 48 {
				return "-1"
			}
			arr[i], arr[j] = 49, 49
			b -= 2
		}
	}

	if l&1 == 1 {
		if arr[l/2] == 48 {
			a--
		} else if arr[l/2] == 49 {
			b--
		}
	}

	if a < 0 || b < 0 {
		return "-1"
	}

	for i := 0; i < l/2; i++ {
		j := l - i - 1
		if arr[i] == 63 {
			if a >= 2 {
				arr[i], arr[j] = 48, 48
				a -= 2
			} else if b >= 2 {
				arr[i], arr[j] = 49, 49
				b -= 2
			} else {
				return "-1"
			}
		}
	}

	if l&1 == 1 {
		if arr[l/2] == 63 {
			if a > 0 {
				arr[l/2] = 48
				a--
			} else {
				arr[l/2] = 49
				b--
			}
		}
	}

	if a != 0 && b != 0 {
		return "-1"
	}

	return string(arr)

}

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

	for ; t > 0; t-- {
		fmt.Println(solve())
	}

}

package main

import (
	"bufio"
	"bytes"
	. "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 a, b int
		var s []byte
		Fscan(in, &a, &b, &s)
		n := len(s)
		for i, j := 0, n-1; i < j; i++ {
			if s[i] != '?' || s[j] != '?' {
				if s[i] == '?' {
					s[i] = s[j]
				} else if s[j] == '?' {
					s[j] = s[i]
				} else if s[i] != s[j] {
					Fprintln(out, -1)
					return
				}
			}
			j--
		}
		c0, c1 := bytes.Count(s, []byte{'0'}), bytes.Count(s, []byte{'1'})
		if c0 > a || c1 > b {
			Fprintln(out, -1)
			return
		}
		for i, j := 0, n-1; i < j; i++ {
			if s[i] == '?' {
				if c0+2 <= a {
					s[i] = '0'
					s[j] = '0'
					c0 += 2
				} else if c1+2 <= b {
					s[i] = '1'
					s[j] = '1'
					c1 += 2
				} else {
					Fprintln(out, -1)
					return
				}
			}
			j--
		}
		if n&1 > 0 && s[n/2]=='?' {
			if c0 < a {
				s[n/2] = '0'
			} else if c1 < b {
				s[n/2] = '1'
			} else {
				Fprintln(out, -1)
				return
			}
		}
		c0, c1 = bytes.Count(s, []byte{'0'}), bytes.Count(s, []byte{'1'})
		if c0 != a || c1 != b {
			Fprintln(out, -1)
			return
		}
		Fprintln(out, string(s))
	}

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

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

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

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	aInit := a
	bInit := b

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}
	if a < 0 || b < 0 {
		return "-1"
	}

	var count int

	for i := 0; i < n/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}

			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
			}
			bts[i] = '1'
			bts[n - i - 1] = '1'

		} else if s[i] == '?' {
			if s[n - i - 1] == '1' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
				bts[i] = '1'
				bts[n - i - 1] = '1'

			} else if s[n - i - 1] == '0' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}
				bts[i] = '0'
				bts[n - i - 1] = '0'

			} else if s[n - i - 1] == '?' {
				count++
				bts[i] = '?'
				bts[n - i - 1] = '?'

			} else {
				panic("unkown2")
			}

		} else {
			panic("unknown")
		}
	}

	if n % 2 == 1 {
		if s[n/2] == '?' {
			if aInit % 2 == 1 && a > 0 {
				a--
				bts[n/2] = '0'
			} else if bInit % 2 == 1 && b > 0 {
				b--
				bts[n/2] = '1'
			}
		} else {
			bts[n/2] = s[n/2]
		}
	}

	if a + b >= 2 * count {

		for i := 0; i < n/2; i++ {
			if bts[i] == '?' {
				if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a-=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b-=2
				}
			}
		}

	} else {
		return "-1"
	}

	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	if n % 2 == 1 {
		if s[n/2] == '?' {
			if a % 2 == 1 && a > 0 {
				a--
				bts[n/2] = '0'
			} else if b % 2 == 1 && b > 0 {
				b--
				bts[n/2] = '1'
			}
		} else {
			bts[n/2] = s[n/2]
		}
	}

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}
	if a < 0 || b < 0 {
		return "-1"
	}

	var count int

	for i := 0; i < n/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}

			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
			}
			bts[i] = '1'
			bts[n - i - 1] = '1'

		} else if s[i] == '?' {
			if s[n - i - 1] == '1' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
				bts[i] = '1'
				bts[n - i - 1] = '1'

			} else if s[n - i - 1] == '0' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}
				bts[i] = '0'
				bts[n - i - 1] = '0'

			} else if s[n - i - 1] == '?' {
				count++
				bts[i] = '?'
				bts[n - i - 1] = '?'

			} else {
				panic("unkown2")
			}

		} else {
			panic("unknown")
		}
	}

	if a + b >= 2 * count {

		for i := 0; i < n/2; i++ {
			if bts[i] == '?' {
				if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a-=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b-=2
				}
			}
		}

	} else {
		return "-1"
	}

	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}
	if a < 0 || b < 0 {
		return "-1"
	}

	var count int

	for i := 0; i < n/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}

			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
			}
			bts[i] = '1'
			bts[n - i - 1] = '1'

		} else if s[i] == '?' {
			if s[n - i - 1] == '1' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
				bts[i] = '1'
				bts[n - i - 1] = '1'

			} else if s[n - i - 1] == '0' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}
				bts[i] = '0'
				bts[n - i - 1] = '0'

			} else if s[n - i - 1] == '?' {
				count++
				bts[i] = '?'
				bts[n - i - 1] = '?'

			} else {
				panic("unkown2")
			}

		} else {
			panic("unknown")
		}
	}

	if n % 2 == 1 {
		if s[n/2] == '?' {
			if a % 2 == 1 && a > 0 {
				a--
				bts[n/2] = '0'
			} else if b % 2 == 1 && b > 0 {
				b--
				bts[n/2] = '1'
			}
		} else {
			bts[n/2] = s[n/2]
		}
	}

	if a + b >= 2 * count {

		for i := 0; i < n/2; i++ {
			if bts[i] == '?' {
				if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a-=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b-=2
				}
			}
		}

	} else {
		return "-1"
	}

	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}
	if a < 0 || b < 0 {
		return "-1"
	}

	var count int

	for i := 0; i < n/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}

			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
			}
			bts[i] = '1'
			bts[n - i - 1] = '1'

		} else if s[i] == '?' {
			if s[n - i - 1] == '1' {
				if b > 0 {
					b--
				} else {
					return "-1"
				}
				bts[i] = '1'
				bts[n - i - 1] = '1'

			} else if s[n - i - 1] == '0' {
				if a > 0 {
					a--
				} else {
					return "-1"
				}
				bts[i] = '0'
				bts[n - i - 1] = '0'

			} else if s[n - i - 1] == '?' {
				count++
				bts[i] = '?'
				bts[n - i - 1] = '?'

			} else {
				panic("unkown2")
			}

		} else {
			panic("unknown")
		}
	}

	if n % 2 == 1 {
		if s[n/2] == '?' {
			if a % 2 == 1 && a > 0 {
				a--
				bts[n/2] = '0'
			} else if b % 2 == 1 && b > 0 {
				b--
				bts[n/2] = '1'
			}
		} else {
			bts[n/2] = s[n/2]
		}
	}

	if a + b >= 2 * count {

		for i := 0; i < n/2; i++ {
			if bts[i] == '?' {
				if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
				}
			}
		}

	} else {
		return "-1"
	}

	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	if a % 2 == 1 {
		if s[n/2] == '1'{
			return "-1"
		} else if s[n/2] == '?' {
			a--
		}
		bts[n/2] = '0'

	} else if b % 2 == 1 {
		if s[n/2] == '0'{
			return "-1"
		} else if s[n/2] == '?' {
			b--
		}
		bts[n/2] = '1'
	}

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}

	for i := 0; i < len(s)/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				a--
			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				b--
			}
			bts[n - i - 1] = '1'
			bts[i] = '1'

		} else if s[i] == '?' {

			if s[n - i - 1] == '0' && a >= 1 {
				bts[i] = '0'
				bts[n - i - 1] = '0'
				a --
			} else if s[n - i - 1] == '1' && b >= 1 {
				bts[i] = '1'
				bts[n - i - 1] = '1'
				b --

			 } else if s[n - i - 1] == '?' {
			 	if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a -=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b -= 2
				} else {
					return "-1"
				}

			 } else {
			 	return "-1"
			}

		} else {
			panic("asd")
		}
	}
	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	if a % 2 == 1 {
		if s[n/2] == '1'{
			return "-1"
		} else if s[n/2] == '?' {
			a--
		}
		bts[n/2] = '0'

	} else if b % 2 == 1 {
		if s[n/2] == '0'{
			return "-1"
		} else if s[n/2] == '?' {
			b--
		}
		bts[n/2] = '1'
	}

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			a--
		} else if s[i] == '1' {
			b--
		}
	}

	for i := 0; i < len(s)/2; i++ {
		if s[i] == '0' {
			if s[n - i - 1] == '1' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				a--
			}
			bts[n - i - 1] = '0'
			bts[i] = '0'

		} else if s[i] == '1' {
			if s[n - i - 1] == '0' {
				return "-1"
			} else if s[n - i - 1] == '?' {
				b--
			}
			bts[n - i - 1] = '1'
			bts[i] = '1'

		} else if s[i] == '?' {

			if s[n - i - 1] == '0' && a >= 2 {
				bts[i] = '0'
				bts[n - i - 1] = '0'
				a --
			} else if s[n - i - 1] == '1' && b >= 2 {
				bts[i] = '1'
				bts[n - i - 1] = '1'
				b --

			 } else if s[n - i - 1] == '?' {
			 	if a >= 2 {
					bts[i] = '0'
					bts[n - i - 1] = '0'
					a -=2
				} else if b >= 2 {
					bts[i] = '1'
					bts[n - i - 1] = '1'
					b -= 2
				} else {
					return "-1"
				}

			 } else {
			 	return "-1"
			}

		} else {
			panic("asd")
		}
	}
	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	if a % 2 == 1 {
		bts[n/2] = '0'
		a--

	} else if b % 2 == 1 {
		bts[n/2] = '1'
		b--
	}

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			bts[n - i - 1] = '0'
			bts[i] = '0'
			a-=2
		} else if s[i] == '1' {
			bts[n - i - 1] = '1'
			bts[i] = '1'
			b-=2
		} else if s[i] == '?' {
			if b >= 2 {
				bts[i] = '1'
				bts[n - i - 1] = '1'
				b -= 2

			} else if a >= 2 {
				bts[i] = '0'
				bts[n - i - 1] = '0'
				a -=2
			}

		} else {
			panic("asd")
		}
	}
	return string(bts)
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for t1 := 0; t1 < t; t1++ {

		var a, b int

		fmt.Fscan(r, &a, &b)

		var s string

		fmt.Fscan(r, &s)

		ans := solve(s, a, b)

		fmt.Println(ans)
	}
}

func solve(s string, a, b int) string {
	if a % 2 == 1 && b % 2 == 1 {
		return "-1"
	}
	n := len(s)
	bts := make([]byte, n)

	if a % 2 == 1 {
		bts[n/2] = '0'
		a--

	} else if b % 2 == 1 {
		bts[n/2] = '1'
		b--
	}

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			bts[n - i - 1] = '0'
			bts[i] = '0'
			a--
		} else if s[i] == '1' {
			bts[n - i - 1] = '1'
			bts[i] = '1'
			b--
		} else if s[i] == '?' {
			if b >= 2 {
				bts[i] = '1'
				bts[n - i - 1] = '1'
				b -= 2

			} else if a >= 2 {
				bts[i] = '0'
				bts[n - i - 1] = '0'
				a -=2
			}

		} else {
			panic("asd")
		}
	}
	return string(bts)
}

package main

import "fmt"

func genPalindrome(str string, nOnes, nZeros int) (bool, string) {
	lastPos := len(str) - 1
	if nOnes < 0 || nZeros < 0 {
		return false, ""
	}
	if len(str) == 0 {
		if nOnes == 0 && nZeros == 0 {
			return true, ""
		} else {
			return false, ""
		}
	}
	if str[0] != str[lastPos] {
		return false, ""
	}
	if len(str) == 1 {
		if nOnes == 1 && nZeros == 0 && (str[0] == '?' || str[0] == '1') {
			return true, "1"
		} else if nZeros == 1 && nOnes == 0 && (str[0] == '?' || str[0] == '0') {
			return true, "0"
		}
		return false, ""
	}
	if str[0] == '?' {
		if nZeros > nOnes {
			if ok, zeros := genPalindrome(str[1:len(str)-1], nOnes, nZeros-2); ok {
				return true, "0" + zeros + "0"
			}
		} else {
			if ok, ones := genPalindrome(str[1:len(str)-1], nOnes-2, nZeros); ok {
				return true, "1" + ones + "1"
			}
		}

	} else if str[0] == '1' {
		if ok, ones := genPalindrome(str[1:len(str)-1], nOnes, nZeros); ok {
			return true, "1" + ones + "1"
		}
	} else {
		if ok, zeros := genPalindrome(str[1:len(str)-1], nOnes, nZeros); ok {
			return true, "0" + zeros + "0"
		}
	}
	return false, ""
}

func fixString(str string) string {
	if len(str) < 2 {
		return str
	}
	lastPos := len(str) - 1
	start, end := string(str[0]), string(str[lastPos])
	if str[0] == '?' {
		return end + fixString(str[1:lastPos]) + end
	}
	if str[len(str)-1] == '?' {
		return start + fixString(str[1:lastPos]) + start
	}
	return start + fixString(str[1:lastPos]) + end
}

func possibleWildcards(nOnes, nZeros int, str string) (int, int) {
	for _, v := range str {
		if v == '0' {
			nZeros--
		} else if v == '1' {
			nOnes--
		}
	}
	return nOnes, nZeros
}

func main() {
	var nTests int
	fmt.Scanf("%d\n", &nTests)
	for i := 0; i < nTests; i++ {
		var nZeros, nOnes int
		fmt.Scanf("%d %d\n", &nZeros, &nOnes)
		var str string
		fmt.Scanf("%s\n", &str)
		str = fixString(str)
		ok, palindrome := genPalindrome(str, nOnes, nZeros)
		if !ok {
			palindrome = "-1"
		}
		fmt.Println(palindrome)
	}
}

package main

import "fmt"

func genPalindrome(str string, nOnes, nZeros int) (bool, string) {
	if len(str) == 0 {
		if nOnes == 0 && nZeros == 0 {
			return true, ""
		} else {
			return false, ""
		}
	}
	if len(str) == 1 {
		if nOnes == 1 && nZeros == 0 && (str[0] == '?' || str[0] == '1') {
			return true, "1"
		} else if nZeros == 1 && nOnes == 0 && (str[0] == '?' || str[0] == '1') {
			return true, "0"
		}
		return false, ""
	}
	if str[0] != '?' && str[len(str)-1] != '?' && str[0] != str[len(str)-1] {
		return false, ""
	}
	if str[0] == '?' {
		if str[len(str)-1] == '?' {
			if ok, zeros := genPalindrome(str[1:len(str)-1], nOnes, nZeros-2); ok {
				return true, "0" + zeros + "0"
			}
			if ok, ones := genPalindrome(str[1:len(str)-1], nOnes-2, nZeros); ok {
				return true, "1" + ones + "1"
			}
		} else {
			if str[len(str)-1] == '1' {
				if ok, ones := genPalindrome(str[1:len(str)-1], nOnes-2, nZeros); ok {
					return true, "1" + ones + "1"
				}
			} else {
				if ok, zeros := genPalindrome(str[1:len(str)-1], nOnes, nZeros-2); ok {
					return true, "0" + zeros + "0"
				}
			}
		}
	} else if str[0] == '1' {
		if ok, ones := genPalindrome(str[1:len(str)-1], nOnes-2, nZeros); ok {
			return true, "1" + ones + "1"
		}
	} else {
		if ok, zeros := genPalindrome(str[1:len(str)-1], nOnes, nZeros-2); ok {
			return true, "0" + zeros + "0"
		}
	}
	return false, ""
}

func main() {
	var nTests int
	fmt.Scanf("%d\n", &nTests)
	for i := 0; i < nTests; i++ {
		var nZeros, nOnes int
		fmt.Scanf("%d %d\n", &nZeros, &nOnes)
		var str string
		fmt.Scanf("%s\n", &str)
		ok, palindrome := genPalindrome(str, nOnes, nZeros)
		if !ok {
			palindrome = "-1"
		}
		fmt.Println(palindrome)
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)
		var sb string
		fmt.Fscan(reader, &sb)
		if t == 42 {
			fmt.Println(sb, a, b)
		}
		s := []byte(sb)
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				b--
			} else if s[i] == '0' {
				a--
			}
		}
		ok := true
		i := 0
		j := len(sb) - 1
		for i <= j {
			if s[i] != '?' && s[j] != '?' {
				if s[i] != s[j] {
					ok = false
					break
				}

			} else if s[i] == '?' && s[j] == '?' {
				if i == j {
					if a > 0 {
						s[i] = '0'
						a--
					} else if b > 0 {
						s[i] = '1'
						b--
					}
				} else {
					if a > 1 {
						s[i] = '0'
						s[j] = '0'
						a -= 2
					} else if b > 1 {
						s[i] = '1'
						s[j] = '1'
						b -= 2
					}
				}
			} else {
				if s[i] == '?' {
					s[i] = s[j]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				} else {
					s[j] = s[i]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				}
			}
			i++
			j--
		}
		if a != 0 || b != 0 {
			ok = false
		}
		if ok {
			write(f, string(s), "\n")
		} else {
			write(f, "-1\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)
		var sb string
		fmt.Fscan(reader, &sb)
		if t == 42 {
			fmt.Println(sb)
		}
		s := []byte(sb)
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				b--
			} else if s[i] == '0' {
				a--
			}
		}
		ok := true
		i := 0
		j := len(sb) - 1
		for i <= j {
			if s[i] != '?' && s[j] != '?' {
				if s[i] != s[j] {
					ok = false
					break
				}

			} else if s[i] == '?' && s[j] == '?' {
				if i == j {
					if a > 0 {
						s[i] = '0'
						a--
					} else if b > 0 {
						s[i] = '1'
						b--
					}
				} else {
					if a > 1 {
						s[i] = '0'
						s[j] = '0'
						a -= 2
					} else if b > 1 {
						s[i] = '1'
						s[j] = '1'
						b -= 2
					}
				}
			} else {
				if s[i] == '?' {
					s[i] = s[j]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				} else {
					s[j] = s[i]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				}
			}
			i++
			j--
		}
		if a != 0 || b != 0 {
			ok = false
		}
		if ok {
			write(f, string(s), "\n")
		} else {
			write(f, "-1\n")
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var a, b int
		fmt.Fscan(reader, &a, &b)
		var sb string
		fmt.Fscan(reader, &sb)
		s := []byte(sb)
		for i := 0; i < len(s); i++ {
			if s[i] == '1' {
				b--
			} else if s[i] == '0' {
				a--
			}
		}
		ok := true
		i := 0
		j := len(sb) - 1
		for i <= j {
			if s[i] != '?' && s[j] != '?' {
				if s[i] != s[j] {
					ok = false
					break
				}

			} else if s[i] == '?' && s[j] == '?' {
				if i == j {
					if a > 0 {
						s[i] = '0'
						a--
					} else if b > 0 {
						s[i] = '1'
						b--
					}
				} else {
					if a > 1 {
						s[i] = '0'
						s[j] = '0'
						a -= 2
					} else if b > 1 {
						s[i] = '1'
						s[j] = '1'
						b -= 2
					}
				}
			} else {
				if s[i] == '?' {
					s[i] = s[j]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				} else {
					s[j] = s[i]
					if s[j] == '1' {
						b -= 1
					} else {
						a -= 1
					}
				}
			}
			i++
			j--
		}
		if a != 0 || b != 0 {
			ok = false
		}
		if ok {
			write(f, string(s), "\n")
		} else {
			write(f, "-1\n")
		}
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func ri() int {
	var x int
	c, _ := reader.ReadByte()
	for c < '0' || c > '9' {
		c, _ = reader.ReadByte()
	}
	for '0' <= c && c <= '9' {
		x = (x << 3) + (x << 1) + int(c) - '0'
		c, _ = reader.ReadByte()
	}
	return x
}

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
}

const MAXN = 2e5 + 5

type Node struct {
	x, y int
}

func Solve() {
	var n, m int
	fmt.Scan(&n, &m)
	var s string
	fmt.Scan(&s)
	t := []rune(s)
	l, r := 0, n+m-1
	for l < r {
		if t[l] != t[r] {
			if t[l] != '?' && t[r] != '?' {
				fmt.Println(-1)
				return
			} else {
				if t[l] == '?' {
					t[l] = t[r]
				} else {
					t[r] = t[l]
				}
			}
		}
		l++
		r--
	}
	l, r = 0, n+m-1
	for l <= r {
		switch {
		case t[l] == '0':
			n--
		case t[l] == '1':
			m--
		}
		if l != r {
			switch {
			case t[r] == '0':
				n--
			case t[r] == '1':
				m--
			}
		}
		l++
		r--
	}
	l, r = 0, len(t)-1
	for l <= r {
		if t[l] == '?' {
			if l == r {
				if n != 0 {
					t[l] = '0'
					n -= 1
				} else {
					t[l] = '1'
					m -= 1
				}
			} else {
				if n != 0 {
					t[l] = '0'
					t[r] = '0'
					n -= 2
				} else {
					t[l] = '1'
					t[r] = '1'
					m -= 2
				}
			}
		}
		l++
		r--
	}
	if n == 0 && m == 0 {
		fmt.Println(string(t))
	} else {
		fmt.Println(-1)
	}
}

func main() {
	var T = 0
	if T == 0 {
		fmt.Scan(&T)
	}
	for t := 1; t <= T; t++ {
		Solve()
	}
}

package main

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

type pos struct {
	i int
	j int
}

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

	solve := func() {
		var a, b int
		Fscan(in, &a, &b)
		var str []byte
		var cnt [2]int
		var empty_num []pos
		var unique_num []pos
		Fscan(in, &str)

		for l, r := 0, len(str)-1; l <= r; l, r = l+1, r-1 {
			if str[l] == '?' && str[r] == '?' {
				if l != r {
					empty_num = append(empty_num, pos{l, r})
				} else {
					unique_num = append(unique_num, pos{l, r})
				}

			} else {
				if str[l] == '?' {
					str[l] = str[r]
				} else if str[r] == '?' {
					str[r] = str[l]
				}
				if str[l] != str[r] {
					Fprintln(out, -1)
					return
				} else {
					cnt[str[l]-'0']++
					if l != r {
						cnt[str[r]-'0']++
					}
				}
			}
		}
		// Fprint(out, cnt[0], cnt[1])
		if cnt[0] > a || cnt[1] > b {
			Fprintln(out, -1)
		} else {
			for i := 0; i < (a-cnt[0])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '0'
				str[v] = '0'
				empty_num = empty_num[:len(empty_num)-1]
			}
			for i := 0; i < (b-cnt[1])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '1'
				str[v] = '1'
				empty_num = empty_num[:len(empty_num)-1]
			}
			if len(unique_num) == 1 {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					if (a-cnt[0])%2 == 1 {
						str[len(str)-1] = '0'
					} else {
						str[len(str)-1] = '1'
					}

					Fprintln(out, string(str))
				}
			} else {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					Fprintln(out, string(str))
				}
			}
		}

	}

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

}

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

package main

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

type pos struct {
	i int
	j int
}

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

	solve := func() {
		var a, b int
		Fscan(in, &a, &b)
		var str []byte
		var cnt [2]int
		var empty_num []pos
		var unique_num []pos
		Fscan(in, &str)

		for l, r := 0, len(str)-1; l <= r; l, r = l+1, r-1 {
			if str[l] == '?' && str[r] == '?' {
				if l != r {
					empty_num = append(empty_num, pos{l, r})
				} else {
					unique_num = append(unique_num, pos{l, r})
				}

			} else {
				if str[l] == '?' {
					str[l] = str[r]
				} else if str[r] == '?' {
					str[r] = str[l]
				}
				if str[l] != str[r] {
					Fprintln(out, -1)
					return
				} else {
					cnt[str[l]-'0']++
					if l != r {
						cnt[str[r]-'0']++
					}
				}
			}
		}
		if cnt[0] > a && cnt[1] > b {
			Fprintln(out, -1)
		} else {
			for i := 0; i < (a-cnt[0])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '0'
				str[v] = '0'
				empty_num = empty_num[:len(empty_num)-1]
			}
			for i := 0; i < (b-cnt[1])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '1'
				str[v] = '1'
				empty_num = empty_num[:len(empty_num)-1]
			}
			if len(unique_num) == 1 {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					if (a-cnt[0])%2 == 1 {
						str[len(str)-1] = '0'
					} else {
						str[len(str)-1] = '1'
					}

					Fprintln(out, string(str))
				}
			} else {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					Fprintln(out, string(str))
				}
			}
		}

	}

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

}

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

package main

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

type pos struct {
	i int
	j int
}

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

	solve := func() {
		var a, b int
		Fscan(in, &a, &b)
		var str []byte
		var cnt [2]int
		var empty_num []pos
		var unique_num []pos
		Fscan(in, &str)

		for l, r := 0, len(str)-1; l <= r; l, r = l+1, r-1 {
			if str[l] == '?' && str[r] == '?' {
				if l != r {
					empty_num = append(empty_num, pos{l, r})
				} else {
					unique_num = append(unique_num, pos{l, r})
				}

			} else {
				if str[l] == '?' {
					str[l] = str[r]
				} else if str[r] == '?' {
					str[r] = str[l]
				}
				if str[l] != str[r] {
					Fprintln(out, -1)
					return
				} else {
					cnt[str[l]-'0']++
					cnt[str[r]-'0']++
				}
			}
		}
		if cnt[0] > a && cnt[1] > b {
			Fprintln(out, -1)
		} else {
			for i := 0; i < (a-cnt[0])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '0'
				str[v] = '0'
				empty_num = empty_num[:len(empty_num)-1]
			}
			for i := 0; i < (b-cnt[1])/2; i++ {
				u := empty_num[len(empty_num)-1].i
				v := empty_num[len(empty_num)-1].j
				str[u] = '1'
				str[v] = '1'
				empty_num = empty_num[:len(empty_num)-1]
			}
			if len(unique_num) == 1 {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					if (a-cnt[0])%2 == 1 {
						str[len(str)-1] = '0'
					} else {
						str[len(str)-1] = '1'
					}

					Fprintln(out, string(str))
				}
			} else {
				if len(empty_num) > 0 {
					Fprintln(out, -1)
				} else {
					Fprintln(out, string(str))
				}
			}
		}

	}

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

}

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func replace(str []byte, a int, b int) string {
	N := len(str)
	l := 0
	r := N - 1
	for l < r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if str[r] == '0' {
			a--
		} else if str[r] == '1' {
			b--
		}
		if str[l] == '?' && str[r] != '?' {
			if str[r] == '0' {
				str[l] = '0'
				a--
			} else {
				str[l] = '1'
				b--
			}
		} else if str[l] != '?' && str[r] == '?' {
			if str[l] == '0' {
				str[r] = '0'
				a--
			} else {
				str[r] = '1'
				b--
			}
		}
		if a < 0 || b < 0 || str[l] != str[r] {
			return "-1"
		}
		l++
		r--
	}
	if l == r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if a < 0 || b < 0 {
			return "-1"
		}
	}

	l = 0
	r = N - 1
	for l < r {
		if str[l] == '?' {
			if a > 0 {
				str[l] = '0'
				str[r] = '0'
				a -= 2
			} else {
				str[l] = '1'
				str[r] = '1'
				b -= 2
			}
		}
		if a < 0 || b < 0 {
			return "-1"
		}
		l++
		r--
	}
	if l == r && str[l] == '?' {
		if a > 0 {
			str[l] = '0'
			a--
		} else if b > 0 {
			str[l] = '1'
			b--
		} else {
			return "-1"
		}
	}
	if a > 0 || b > 0 {
		return "-1"
	}
	return string(str)
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.nextInt()
		b := sc.nextInt()
		str := []byte(sc.next())
		ans := replace(str, a, b)
		fmt.Fprintln(wr, ans)
	}

}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func replace(str []byte, a int, b int) string {
	N := len(str)
	l := 0
	r := N - 1
	for l < r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if str[r] == '0' {
			a--
		} else if str[r] == '1' {
			b--
		}
		if str[l] == '?' && str[r] != '?' {
			if str[r] == '0' {
				str[l] = '0'
				a--
			} else {
				str[l] = '1'
				b--
			}
		} else if str[l] != '?' && str[r] == '?' {
			if str[l] == '0' {
				str[r] = '0'
				a--
			} else {
				str[r] = '1'
				b--
			}
		}
		if a < 0 || b < 0 || str[l] != str[r] {
			return "-1"
		}
		l++
		r--
	}
	if l == r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if a < 0 || b < 0 {
			return "-1"
		}
	}

	l = 0
	r = N - 1
	for l < r {
		if str[l] == '?' {
			if a > 0 {
				str[l] = '0'
				str[r] = '0'
				a -= 2
			} else {
				str[l] = '1'
				str[r] = '1'
				b -= 2
			}
		}
		if a < 0 || b < 0 {
			return "-1"
		}
		l++
		r--
	}
	if l == r && str[l] == '?' {
		if a > 0 {
			str[l] = '0'
			a--
		} else if b > 0 {
			str[l] = '1'
			b--
		} else {
			return "-1"
		}
	}
	return string(str)
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.nextInt()
		b := sc.nextInt()
		str := []byte(sc.next())
		ans := replace(str, a, b)
		fmt.Fprintln(wr, ans)
	}

}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func replace(str []byte, a int, b int) string {
	N := len(str)
	l := 0
	r := N - 1
	for l < r {
		if str[l] == '0' {
			a--
		} else if str[l] == '1' {
			b--
		}
		if str[r] == '0' {
			a--
		} else if str[r] == '1' {
			b--
		}
		if str[l] == '?' && str[r] != '?' {
			if str[r] == '0' {
				str[l] = '0'
				a--
			} else {
				str[l] = '1'
				b--
			}
		} else if str[l] != '?' && str[r] == '?' {
			if str[l] == '0' {
				str[r] = '0'
				a--
			} else {
				str[r] = '1'
				b--
			}
		}
		if a < 0 || b < 0 || str[l] != str[r] {
			return "-1"
		}
		l++
		r--
	}

	l = 0
	r = N - 1
	for l < r {
		if str[l] == '?' {
			if a > 0 {
				str[l] = '0'
				str[r] = '0'
				a -= 2
			} else {
				str[l] = '1'
				str[r] = '1'
				b -= 2
			}
		}
		if a < 0 || b < 0 {
			return "-1"
		}
		l++
		r--
	}
	if l == r && str[l] == '?' {
		if a > 0 {
			str[l] = '0'
			a--
		} else if b > 0 {
			str[l] = '1'
			b--
		} else {
			return "-1"
		}
	}
	return string(str)
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		a := sc.nextInt()
		b := sc.nextInt()
		str := []byte(sc.next())
		ans := replace(str, a, b)
		fmt.Fprintln(wr, ans)
	}

}


There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated:   Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting).  When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end.  When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements.  The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction. You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.  The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.

Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.

NoteConsider one of the voting scenarios for the first sample:   Employee 1 denies employee 5 to vote.  Employee 2 denies employee 3 to vote.  Employee 3 has no right to vote and skips his turn (he was denied by employee 2).  Employee 4 denies employee 2 to vote.  Employee 5 has no right to vote and skips his turn (he was denied by employee 1).  Employee 1 denies employee 4.  Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

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

func solve(n int) {
	var s string
	I(&s, "\n")
	var R, D []int
	for i, c := range s {
		if c == 'R' {
			R = append(R, i)
		} else if c == 'D' {
			D = append(D, i)
		}
	}
	for len(D) > 0 && len(R) > 0 {
		if D[0] < R[0] {
			D = append(D[1:], D[0]+n)
			R = R[1:]
		} else {
			R = append(R[1:], R[0]+n)
			D = D[1:]
		}
	}
	if len(D) > 0 {
		O("D", "\n")
	} else {
		O("R", "\n")
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	var n int
	var str string
	fmt.Fscanf(r, "%d\n", &n)
	fmt.Fscanf(r, "%s", &str)

	cntd, cntr := 0, 0

	for i := 0; i < len(str); i++ {
		if str[i] == 'D' {
			cntd++
		} else if str[i] == 'R' {
			cntr++
		}
	}

	//fmt.Printf("cntd = %d cntr = %d\n", cntd, cntr)

	cd, cr := 0, 0

	vis := make([]bool, n+1)

	for cntd > 0 && cntr > 0 {
		for i := 0; i < len(str); i++ {
			if str[i] == 'D' && !vis[i] {
				if cd <= 0 {
					cntr = cntr - 1
					cr++
				} else {
					cd = cd - 1
					vis[i] = true
				}
			} else if str[i] == 'R' && !vis[i] {
				if cr <= 0 {
					cntd = cntd - 1
					cd++
				} else {
					cr = cr - 1
					vis[i] = true
				}
			}
			if cntd <= 0 || cntr <= 0 {
				break
			}
		}
	}

	if cntr > 0 {
		fmt.Printf("R\n")
	} else {
		fmt.Printf("D\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

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

func solve(n int) {
	var s string
	I(&s, "\n")
	var R, D []int
	for i, c := range s {
		if c == 'R' {
			R = append(R, i)
		} else if c == 'D' {
			D = append(D, i)
		}
	}
	o := 0
	for len(D) > 0 && len(R) > 0 {
		if D[0] < R[0] {
			o++
		} else if D[0] > R[0] {
			o--
		}
		R = R[1:]
		D = D[1:]
	}
	o += len(D)
	o -= len(R)
	if o > 0 {
		O("D", "\n")
	} else {
		O("R", "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

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

func solve(n int) {
	var s string
	I(&s, "\n")
	var R, D []int
	for i, c := range s {
		if c == 'R' {
			R = append(R, i)
		} else if c == 'D' {
			D = append(D, i)
		}
	}
	o := 0
	for len(D) > 0 && len(R) > 0 {
		if D[0] < R[0] {
			o++
		} else if D[0] > R[0] {
			o--
		}
		R = R[1:]
		D = D[1:]
	}
	o += len(D) - len(R)
	if o > 0 || (len(D) > 0 && o == 0) {
		O("D", "\n")
	} else {
		O("R", "\n")
	}
}

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

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

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

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

func solve(n int) {
	var s string
	I(&s, "\n")
	var R, D int
	for _, c := range s {
		if c == 'D' {
			D++
			if D > 0 {
				R--
			}
		} else if c == 'R' {
			R++
			if R > 0 {
				D--
			}
		}
	}
	if R > D {
		O("R", "\n")
	} else {
		O("D", "\n")
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	var n int
	var str string
	fmt.Fscanf(r, "%d\n", &n)
	fmt.Fscanf(r, "%s", &str)

	cntd, cntr := 0, 0

	for i := 0; i < len(str); i++ {
		if str[i] == 'D' {
			cntd++
		} else if str[i] == 'R' {
			cntr++
		}
	}

	//fmt.Printf("cntd = %d cntr = %d\n", cntd, cntr)

	cd, cr := 0, 0

	for cntd > 0 && cntr > 0 {
		for i := 0; i < len(str); i++ {
			if str[i] == 'D' {
				if cd <= 0 {
					cntr = cntr - 1
					cr++
				} else {
					cd = cd - 1
				}
			} else if str[i] == 'R' {
				if cr <= 0 {
					cntd = cntd - 1
					cd++
				} else {
					cr = cr - 1
				}
			}
		}
	}

	if cntr > 0 {
		fmt.Printf("R\n")
	} else {
		fmt.Printf("D\n")
	}
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	var n int
	var str string
	fmt.Fscanf(r, "%d\n", &n)
	fmt.Fscanf(r, "%s", &str)

	cntd, cntr := 0, 0

	for i := 0; i < len(str); i++ {
		if str[i] == 'D' {
			cntd++
		} else if str[i] == 'R' {
			cntr++
		}
	}

	//fmt.Printf("cntd = %d cntr = %d\n", cntd, cntr)

	cd, cr := 0, 0

	for cntd > 0 && cntr > 0 {
		for i := 0; i < len(str); i++ {
			if str[i] == 'D' {
				if cd <= 0 {
					cntr = cntr - 1
					cr++
				} else {
					cd = cd - 1
				}
			} else if str[i] == 'R' {
				if cr <= 0 {
					cntd = cntd - 1
					cd++
				} else {
					cr = cr - 1
				}
			}
			if cntd <= 0 || cntr <= 0 {
				break
			}
		}
	}

	if cntr > 0 {
		fmt.Printf("R\n")
	} else {
		fmt.Printf("D\n")
	}
}


Alexey recently held a programming contest for students from Berland. n students participated in a contest, i-th of them solved ai problems. Now he wants to award some contestants. Alexey can award the students with diplomas of three different degrees. Each student either will receive one diploma of some degree, or won't receive any diplomas at all. Let cntx be the number of students that are awarded with diplomas of degree x (1 ≤ x ≤ 3). The following conditions must hold:  For each x (1 ≤ x ≤ 3) cntx > 0;  For any two degrees x and y cntx ≤ 2·cnty. Of course, there are a lot of ways to distribute the diplomas. Let bi be the degree of diploma i-th student will receive (or  - 1 if i-th student won't receive any diplomas). Also for any x such that 1 ≤ x ≤ 3 let cx be the maximum number of problems solved by a student that receives a diploma of degree x, and dx be the minimum number of problems solved by a student that receives a diploma of degree x. Alexey wants to distribute the diplomas in such a way that:  If student i solved more problems than student j, then he has to be awarded not worse than student j (it's impossible that student j receives a diploma and i doesn't receive any, and also it's impossible that both of them receive a diploma, but bj < bi);  d1 - c2 is maximum possible;  Among all ways that maximize the previous expression, d2 - c3 is maximum possible;  Among all ways that correspond to the two previous conditions, d3 - c - 1 is maximum possible, where c - 1 is the maximum number of problems solved by a student that doesn't receive any diploma (or 0 if each student is awarded with some diploma). Help Alexey to find a way to award the contestants!

The first line contains one integer number n (3 ≤ n ≤ 3000). The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 5000).

Output n numbers. i-th number must be equal to the degree of diploma i-th contestant will receive (or  - 1 if he doesn't receive any diploma). If there are multiple optimal solutions, print any of them. It is guaranteed that the answer always exists.

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

func MinInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func MaxInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res < v {
			res = v
		}
	}
	return res
}

func log2(n int) uint {
	i := uint(0)
	for t := 1; t * 2 <= n; t *= 2 {
		i++
	}
	return i
}

type Student struct {
	id, value int
}

type StudentArray []Student

func (a StudentArray) Len() int { return len(a) }
func (a StudentArray) Less(i, j int) bool {
	return a[i].value > a[j].value
}
func (a StudentArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var n int
var s [3000]Student
// diff[i] = s[i].value - s[i+1].value
var diff [3000]int
// rangeMin[j][i] = pos of max(diff[i]..diff[i+(1<<j) - 1])
var rangeMax [12][3000]int
var res[3000]int

func preprocessRangeMax() {
	for i := 0; i < n; i++ {
		rangeMax[0][i] = i
	}
	maxJ := log2(n)
	for j := uint(1); j <= maxJ; j++ {
		for i := 0; i < n; i++ {
			t := rangeMax[j-1][i]
			if i + (1<<(j-1)) < n {
				t2 := rangeMax[j-1][i + (1<<(j-1))]
				if diff[t2] > diff[t] {
					t = t2
				}
			}
			rangeMax[j][i] = t
		}
	}
}

func getRangeMaxPos(start, end int) int {
	level := log2(end - start + 1)
	t1 := rangeMax[level][start]
	t2 := rangeMax[level][end - (1<<level)+1]
	if diff[t1] > diff[t2] {
		return t1
	}
	return t2
}

func isAllowed(a, b, maxC int) bool {
	maxVal := MinInt(a, b, maxC) * 2
	return a <= maxVal && b <= maxVal
}

func getMaxB(a int) int {
	low := ceilDiv(a, 2)
	high := MinInt(a * 2, 2 * (n - a) / 3)
	for low + 1 < high {
		mid := (low + high) / 2
		if isAllowed(a, mid, n - a - mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowed(a, high, n - a - high) {
		return high
	}
	return low
}

func isAllowedA(a int) bool {
	left := n - a
	half := left / 2
	return half * 2 >= a
}

func getMaxA() int {
	low := 1
	high := n / 2
	for low + 1 < high {
		mid := (low + high) / 2
		if isAllowedA(mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowedA(high) {
		return high
	}
	return low
}

func ceilDiv(a, b int) int {
	res := a / b
	if res * b < a {
		res++
	}
	return res
}

func main() {
	defer stdout.Flush()
	if false {
		f, _ := os.Create("profile")
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			s[i].id = i
			scan(&s[i].value)
		}
		sort.Sort(StudentArray(s[0:n]))
		for i := 0; i < n - 1; i++ {
			diff[i] = s[i].value - s[i+1].value
		}
		diff[n-1] = s[n-1].value
		preprocessRangeMax()
		// a is length of level 1
		// b is length of level 2
		// c is length of level 3
		bestA := -1
		bestB := -1
		bestC := -1
		bestDiffAB := -1
		bestDiffBC := -1
		bestDiffCD := -1
		maxA := getMaxA()
		bestDiffAB = diff[getRangeMaxPos(0, maxA - 1)]
		for a := 1; a <= maxA; a++ {
			diffAB := diff[a-1]
			if diffAB < bestDiffAB {
				continue
			}
			minB := ceilDiv(a, 2)
			maxB := getMaxB(a)
			//printf("a = %d, n = %d, maxB = %d\n", a, n, maxB)
			tmpBestDiffBC := diff[getRangeMaxPos(a + minB - 1, a + maxB - 1)]
			/*
			printf("a = %d, tmpBestDiffBC = %d, bestDiffBC = %d\n", a, tmpBestDiffBC,
				bestDiffBC)
			printf("minB %d, maxB %d, pos = %d\n", minB, maxB,
				getRangeMaxPos(a + minB - 1, a + maxB - 1))
			*/
			if bestDiffBC > tmpBestDiffBC {
				continue
			}
			for b := minB; b <= maxB; b++ {
				diffBC := diff[a + b - 1]
				if diffBC < tmpBestDiffBC {
					continue
				}
				minC := MaxInt(ceilDiv(a, 2), ceilDiv(b, 2))
				maxC := MinInt(a * 2, b * 2, n - a - b)
				//printf("minC %d, maxC %d\n", minC, maxC)
				pos := getRangeMaxPos(a + b + minC - 1, a + b + maxC - 1)
				c := pos + 1 - a - b
				diffCD := diff[pos]
				if diffBC > bestDiffBC || diffCD > bestDiffCD {
					bestA = a
					bestB = b
					bestC = c
					bestDiffBC = diffBC
					bestDiffCD = diffCD
				}
			}
		}
		/*
		printf("diff: ")
		for i := 0; i < n; i++ {
			printf("%d ", diff[i])
		}
		printf("\n")
		printf("bestA %d, b %d c %d, diffAB %d BC %d CD %d\n",
			bestA, bestB, bestC, bestDiffAB, bestDiffBC, bestDiffCD)
		*/

		for i := 0; i < n; i++ {
			id := s[i].id
			level := -1
			if i < bestA {
				level = 1
			} else if i < bestA + bestB {
				level = 2
			} else if i < bestA + bestB + bestC {
				level = 3
			}
			res[id] = level
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				printf(" ")
			}
			printf("%d", res[i])
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

func MinInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func MaxInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res < v {
			res = v
		}
	}
	return res
}

func log2(n int) uint {
	i := uint(0)
	for t := 1; t * 2 <= n; t *= 2 {
		i++
	}
	return i
}

type Student struct {
	id, value int
}

type StudentArray []Student

func (a StudentArray) Len() int { return len(a) }
func (a StudentArray) Less(i, j int) bool {
	return a[i].value > a[j].value
}
func (a StudentArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var n int
var s [3000]Student
// diff[i] = s[i].value - s[i+1].value
var diff [3000]int
// rangeMin[j][i] = pos of max(diff[i]..diff[i+(1<<j) - 1])
var rangeMax [12][3000]int
var res[3000]int

func preprocessRangeMax() {
	for i := 0; i < n; i++ {
		rangeMax[0][i] = i
	}
	maxJ := log2(n)
	for j := uint(1); j <= maxJ; j++ {
		for i := 0; i < n; i++ {
			t := rangeMax[j-1][i]
			if i + (1<<(j-1)) < n {
				t2 := rangeMax[j-1][i + (1<<(j-1))]
				if diff[t2] > diff[t] {
					t = t2
				}
			}
			rangeMax[j][i] = t
		}
	}
}

func getRangeMaxPos(start, end int) int {
	level := log2(end - start + 1)
	t1 := rangeMax[level][start]
	t2 := rangeMax[level][end - (1<<level)+1]
	if diff[t1] > diff[t2] {
		return t1
	}
	return t2
}

func isAllowed(a, b, maxC int) bool {
	maxVal := MinInt(a, b, maxC) * 2
	return a < maxVal && b < maxVal
}

func getMaxB(a int) int {
	low := (a + 2) / 2
	high := MinInt(a * 2 - 1, 2 * (n - a) / 3)
	for low + 1 < high {
		/*
		if a == 5 {
			printf("getMaxB(low %d, high %d)\n", low, high)
		}
		*/
		mid := (low + high) / 2
		if isAllowed(a, mid, n - a - mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowed(a, high, n - a - high) {
		return high
	}
	return low
}

func main() {
	defer stdout.Flush()
	if false {
		f, _ := os.Create("profile")
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			s[i].id = i
			scan(&s[i].value)
		}
		sort.Sort(StudentArray(s[0:n]))
		for i := 0; i < n - 1; i++ {
			diff[i] = s[i].value - s[i+1].value
		}
		diff[n-1] = s[n-1].value
		preprocessRangeMax()
		// a is length of level 1
		// b is length of level 2
		// c is length of level 3
		bestA := -1
		bestB := -1
		bestC := -1
		bestDiffAB := -1
		bestDiffBC := -1
		bestDiffCD := -1
		maxA := n / 2
		bestDiffAB = diff[getRangeMaxPos(0, maxA - 1)]
		for a := 1; a <= maxA; a++ {
			diffAB := diff[a-1]
			if diffAB < bestDiffAB {
				continue
			}
			minB := (a + 2) / 2
			maxB := getMaxB(a)
			tmpBestDiffBC := diff[getRangeMaxPos(a + minB - 1, a + maxB - 1)]
			/*
			printf("a = %d, tmpBestDiffBC = %d, bestDiffBC = %d\n", a, tmpBestDiffBC,
				bestDiffBC)
			printf("minB %d, maxB %d, pos = %d\n", minB, maxB,
				getRangeMaxPos(a + minB - 1, a + maxB - 1))
			*/
			if bestDiffBC > tmpBestDiffBC {
				continue
			}
			for b := minB; b <= maxB; b++ {
				diffBC := diff[a + b - 1]
				if diffBC < tmpBestDiffBC {
					continue
				}
				minC := MaxInt((a + 2) / 2, (b + 2) / 2)
				maxC := MinInt(a * 2 - 1, b * 2 - 1, n - a - b)
				pos := getRangeMaxPos(a + b + minC - 1, a + b + maxC - 1)
				c := pos + 1 - a - b
				diffCD := diff[pos]
				if diffBC > bestDiffBC || diffCD > bestDiffCD {
					bestA = a
					bestB = b
					bestC = c
					bestDiffBC = diffBC
					bestDiffCD = diffCD
				}
			}
		}
		/*
		printf("diff: ")
		for i := 0; i < n; i++ {
			printf("%d ", diff[i])
		}
		printf("\n")
		printf("bestA %d, b %d c %d, diffAB %d BC %d CD %d\n",
			bestA, bestB, bestC, bestDiffAB, bestDiffBC, bestDiffCD)
		*/

		for i := 0; i < n; i++ {
			id := s[i].id
			level := -1
			if i < bestA {
				level = 1
			} else if i < bestA + bestB {
				level = 2
			} else if i < bestA + bestB + bestC {
				level = 3
			}
			res[id] = level
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				printf(" ")
			}
			printf("%d", res[i])
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

func MinInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func MaxInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res < v {
			res = v
		}
	}
	return res
}

func log2(n int) uint {
	i := uint(0)
	for t := 1; t * 2 <= n; t *= 2 {
		i++
	}
	return i
}

type Student struct {
	id, value int
}

type StudentArray []Student

func (a StudentArray) Len() int { return len(a) }
func (a StudentArray) Less(i, j int) bool {
	return a[i].value > a[j].value
}
func (a StudentArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var n int
var s [3000]Student
// diff[i] = s[i].value - s[i+1].value
var diff [3000]int
// rangeMin[j][i] = pos of max(diff[i]..diff[i+(1<<j) - 1])
var rangeMax [12][3000]int
var res[3000]int

func preprocessRangeMax() {
	for i := 0; i < n; i++ {
		rangeMax[0][i] = i
	}
	maxJ := log2(n)
	for j := uint(1); j <= maxJ; j++ {
		for i := 0; i < n; i++ {
			t := rangeMax[j-1][i]
			if i + (1<<(j-1)) < n {
				t2 := rangeMax[j-1][i + (1<<(j-1))]
				if diff[t2] > diff[t] {
					t = t2
				}
			}
			rangeMax[j][i] = t
		}
	}
}

func getRangeMaxPos(start, end int) int {
	level := log2(end - start + 1)
	t1 := rangeMax[level][start]
	t2 := rangeMax[level][end - (1<<level)+1]
	if diff[t1] > diff[t2] {
		return t1
	}
	return t2
}

func isAllowed(a, b, c int) bool {
	maxVal := MinInt(a, b, c) * 2
	return a < maxVal && b < maxVal && c < maxVal
}

func getMaxB(a int) int {
	low := (a + 2) / 2
	high := MinInt(a * 2, 2 * (n - a) / 3)
	for low + 1 < high {
		mid := (low + high) / 2
		if isAllowed(a, mid, n - a - mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowed(a, high, n - a - high) {
		return high
	}
	return low
}

func main() {
	defer stdout.Flush()
	if false {
		f, _ := os.Create("profile")
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			s[i].id = i
			scan(&s[i].value)
		}
		sort.Sort(StudentArray(s[0:n]))
		for i := 0; i < n - 1; i++ {
			diff[i] = s[i].value - s[i+1].value
		}
		diff[n-1] = s[n-1].value
		preprocessRangeMax()
		// a is length of level 1
		// b is length of level 2
		// c is length of level 3
		bestA := -1
		bestB := -1
		bestC := -1
		bestDiffAB := -1
		bestDiffBC := -1
		bestDiffCD := -1
		maxA := n / 2
		bestDiffAB = diff[getRangeMaxPos(0, maxA - 1)]
		for a := 1; a <= maxA; a++ {
			diffAB := diff[a-1]
			if diffAB < bestDiffAB {
				continue
			}
			minB := (a + 2) / 2
			maxB := getMaxB(a)
			tmpBestDiffBC := diff[getRangeMaxPos(a + minB - 1, a + maxB - 1)]
			if bestDiffBC > tmpBestDiffBC {
				continue
			}
			for b := minB; b <= maxB; b++ {
				diffBC := diff[a + b - 1]
				if diffBC < tmpBestDiffBC {
					continue
				}
				minC := MaxInt((a + 2) / 2, (b + 2) / 2)
				maxC := MinInt(a * 2 - 1, b * 2 - 1, n - a - b)
				pos := getRangeMaxPos(a + b + minC - 1, a + b + maxC - 1)
				c := pos + 1 - a - b
				diffCD := diff[pos]
				if diffBC > bestDiffBC || diffCD > bestDiffCD {
					bestA = a
					bestB = b
					bestC = c
					bestDiffBC = diffBC
					bestDiffCD = diffCD
				}
			}
		}

		for i := 0; i < n; i++ {
			id := s[i].id
			level := -1
			if i < bestA {
				level = 1
			} else if i < bestA + bestB {
				level = 2
			} else if i < bestA + bestB + bestC {
				level = 3
			}
			res[id] = level
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				printf(" ")
			}
			printf("%d", res[i])
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

func MinInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func MaxInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res < v {
			res = v
		}
	}
	return res
}

func log2(n int) uint {
	i := uint(0)
	for t := 1; t * 2 <= n; t *= 2 {
		i++
	}
	return i
}

type Student struct {
	id, value int
}

type StudentArray []Student

func (a StudentArray) Len() int { return len(a) }
func (a StudentArray) Less(i, j int) bool {
	return a[i].value > a[j].value
}
func (a StudentArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var n int
var s [3000]Student
// diff[i] = s[i].value - s[i+1].value
var diff [3000]int
// rangeMin[j][i] = pos of max(diff[i]..diff[i+(1<<j) - 1])
var rangeMax [12][3000]int
var res[3000]int

func preprocessRangeMax() {
	for i := 0; i < n; i++ {
		rangeMax[0][i] = i
	}
	maxJ := log2(n)
	for j := uint(1); j <= maxJ; j++ {
		for i := 0; i < n; i++ {
			t := rangeMax[j-1][i]
			if i + (1<<(j-1)) < n {
				t2 := rangeMax[j-1][i + (1<<(j-1))]
				if diff[t2] > diff[t] {
					t = t2
				}
			}
			rangeMax[j][i] = t
		}
	}
}

func getRangeMaxPos(start, end int) int {
	level := log2(end - start + 1)
	t1 := rangeMax[level][start]
	t2 := rangeMax[level][end - (1<<level)+1]
	if diff[t1] > diff[t2] {
		return t1
	}
	return t2
}

func isAllowed(a, b, maxC int) bool {
	maxVal := MinInt(a, b, maxC) * 2
	return a <= maxVal && b <= maxVal
}

func getMaxB(a int) int {
	low := ceilDiv(a, 2)
	high := MinInt(a * 2, 2 * (n - a) / 3)
	for low + 1 < high {
		mid := (low + high) / 2
		if isAllowed(a, mid, n - a - mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowed(a, high, n - a - high) {
		return high
	}
	return low
}

func ceilDiv(a, b int) int {
	res := a / b
	if res * b < a {
		res++
	}
	return res
}

func main() {
	defer stdout.Flush()
	if false {
		f, _ := os.Create("profile")
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			s[i].id = i
			scan(&s[i].value)
		}
		sort.Sort(StudentArray(s[0:n]))
		for i := 0; i < n - 1; i++ {
			diff[i] = s[i].value - s[i+1].value
		}
		diff[n-1] = s[n-1].value
		preprocessRangeMax()
		// a is length of level 1
		// b is length of level 2
		// c is length of level 3
		bestA := -1
		bestB := -1
		bestC := -1
		bestDiffAB := -1
		bestDiffBC := -1
		bestDiffCD := -1
		maxA := n / 2
		bestDiffAB = diff[getRangeMaxPos(0, maxA - 1)]
		for a := 1; a <= maxA; a++ {
			diffAB := diff[a-1]
			if diffAB < bestDiffAB {
				continue
			}
			minB := ceilDiv(a, 2)
			maxB := getMaxB(a)
			//printf("a = %d, n = %d, maxB = %d\n", a, n, maxB)
			tmpBestDiffBC := diff[getRangeMaxPos(a + minB - 1, a + maxB - 1)]
			/*
			printf("a = %d, tmpBestDiffBC = %d, bestDiffBC = %d\n", a, tmpBestDiffBC,
				bestDiffBC)
			printf("minB %d, maxB %d, pos = %d\n", minB, maxB,
				getRangeMaxPos(a + minB - 1, a + maxB - 1))
			*/
			if bestDiffBC > tmpBestDiffBC {
				continue
			}
			for b := minB; b <= maxB; b++ {
				diffBC := diff[a + b - 1]
				if diffBC < tmpBestDiffBC {
					continue
				}
				minC := MaxInt(ceilDiv(a, 2), ceilDiv(b, 2))
				maxC := MinInt(a * 2, b * 2, n - a - b)
				//printf("minC %d, maxC %d\n", minC, maxC)
				pos := getRangeMaxPos(a + b + minC - 1, a + b + maxC - 1)
				c := pos + 1 - a - b
				diffCD := diff[pos]
				if diffBC > bestDiffBC || diffCD > bestDiffCD {
					bestA = a
					bestB = b
					bestC = c
					bestDiffBC = diffBC
					bestDiffCD = diffCD
				}
			}
		}
		/*
		printf("diff: ")
		for i := 0; i < n; i++ {
			printf("%d ", diff[i])
		}
		printf("\n")
		printf("bestA %d, b %d c %d, diffAB %d BC %d CD %d\n",
			bestA, bestB, bestC, bestDiffAB, bestDiffBC, bestDiffCD)
		*/

		for i := 0; i < n; i++ {
			id := s[i].id
			level := -1
			if i < bestA {
				level = 1
			} else if i < bestA + bestB {
				level = 2
			} else if i < bestA + bestB + bestC {
				level = 3
			}
			res[id] = level
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				printf(" ")
			}
			printf("%d", res[i])
		}
		printf("\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func scan(args ...interface{}) (int, error) {
	return fmt.Fscan(stdin, args...)
}

func printf(format string, args ...interface{}) {
	fmt.Fprintf(stdout, format, args...)
}

func MinInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func MaxInt(args ...int) int {
	res := 0
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res < v {
			res = v
		}
	}
	return res
}

func log2(n int) uint {
	i := uint(0)
	for t := 1; t * 2 <= n; t *= 2 {
		i++
	}
	return i
}

type Student struct {
	id, value int
}

type StudentArray []Student

func (a StudentArray) Len() int { return len(a) }
func (a StudentArray) Less(i, j int) bool {
	return a[i].value > a[j].value
}
func (a StudentArray) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

var n int
var s [3000]Student
// diff[i] = s[i].value - s[i+1].value
var diff [3000]int
// rangeMin[j][i] = pos of max(diff[i]..diff[i+(1<<j) - 1])
var rangeMax [12][3000]int
var res[3000]int

func preprocessRangeMax() {
	for i := 0; i < n; i++ {
		rangeMax[0][i] = i
	}
	maxJ := log2(n)
	for j := uint(1); j <= maxJ; j++ {
		for i := 0; i < n; i++ {
			t := rangeMax[j-1][i]
			if i + (1<<(j-1)) < n {
				t2 := rangeMax[j-1][i + (1<<(j-1))]
				if diff[t2] > diff[t] {
					t = t2
				}
			}
			rangeMax[j][i] = t
		}
	}
}

func getRangeMaxPos(start, end int) int {
	level := log2(end - start + 1)
	t1 := rangeMax[level][start]
	t2 := rangeMax[level][end - (1<<level)+1]
	if diff[t1] > diff[t2] {
		return t1
	}
	return t2
}

func isAllowed(a, b, c int) bool {
	maxVal := MinInt(a, b, c) * 2
	return a < maxVal && b < maxVal && c < maxVal
}

func getMaxB(a int) int {
	low := (a + 2) / 2
	high := MinInt(a * 2, 2 * (n - a) / 3)
	for low + 1 < high {
		mid := (low + high) / 2
		if isAllowed(a, mid, n - a - mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if low + 1 == high && isAllowed(a, high, n - a - high) {
		return high
	}
	return low
}

func main() {
	if true {
		f, _ := os.Create("profile")
		defer f.Close()
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			s[i].id = i
			scan(&s[i].value)
		}
		sort.Sort(StudentArray(s[0:n]))
		for i := 0; i < n - 1; i++ {
			diff[i] = s[i].value - s[i+1].value
		}
		diff[n-1] = 0
		preprocessRangeMax()
		// a is length of level 1
		// b is length of level 2
		// c is length of level 3
		bestA := -1
		bestB := -1
		bestC := -1
		bestDiffAB := -1
		bestDiffBC := -1
		bestDiffCD := -1
		maxA := n / 2
		bestDiffAB = diff[getRangeMaxPos(0, maxA - 1)]
		for a := 1; a <= maxA; a++ {
			diffAB := diff[a-1]
			if diffAB < bestDiffAB {
				continue
			}
			minB := (a + 2) / 2
			maxB := getMaxB(a)
			tmpBestDiffBC := diff[getRangeMaxPos(a + minB - 1, a + maxB - 1)]
			if bestDiffBC > tmpBestDiffBC {
				continue
			}
			for b := minB; b <= maxB; b++ {
				diffBC := diff[a + b - 1]
				if diffBC < tmpBestDiffBC {
					continue
				}
				minC := MaxInt((a + 2) / 2, (b + 2) / 2)
				maxC := MinInt(a * 2 - 1, b * 2 - 1, n - a - b)
				pos := getRangeMaxPos(a + b + minC - 1, a + b + maxC - 1)
				c := pos + 1 - a - b
				diffCD := diff[pos]
				if diffBC > bestDiffBC || diffCD > bestDiffCD {
					bestA = a
					bestB = b
					bestC = c
					bestDiffBC = diffBC
					bestDiffCD = diffCD
				}
			}
		}

		for i := 0; i < n; i++ {
			id := s[i].id
			level := -1
			if i < bestA {
				level = 1
			} else if i < bestA + bestB {
				level = 2
			} else if i < bestA + bestB + bestC {
				level = 3
			}
			res[id] = level
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				printf(" ")
			}
			printf("%d", res[i])
		}
		printf("\n")

		stdout.Flush()
	}
}