Berland Music is a music streaming service built specifically to support Berland local artist. Its developers are currently working on a song recommendation module.So imagine Monocarp got recommended $$$n$$$ songs, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th song had its predicted rating equal to $$$p_i$$$, where $$$1 \le p_i \le n$$$ and every integer from $$$1$$$ to $$$n$$$ appears exactly once. In other words, $$$p$$$ is a permutation.After listening to each of them, Monocarp pressed either a like or a dislike button. Let his vote sequence be represented with a string $$$s$$$, such that $$$s_i=0$$$ means that he disliked the $$$i$$$-th song, and $$$s_i=1$$$ means that he liked it.Now the service has to re-evaluate the song ratings in such a way that:  the new ratings $$$q_1, q_2, \dots, q_n$$$ still form a permutation ($$$1 \le q_i \le n$$$; each integer from $$$1$$$ to $$$n$$$ appears exactly once);  every song that Monocarp liked should have a greater rating than every song that Monocarp disliked (formally, for all $$$i, j$$$ such that $$$s_i=1$$$ and $$$s_j=0$$$, $$$q_i>q_j$$$ should hold). Among all valid permutations $$$q$$$ find the one that has the smallest value of $$$\sum\limits_{i=1}^n |p_i-q_i|$$$, where $$$|x|$$$ is an absolute value of $$$x$$$.Print the permutation $$$q_1, q_2, \dots, q_n$$$. If there are multiple answers, you can print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of songs. The second line of each testcase contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$) — the permutation of the predicted ratings. The third line contains a single string $$$s$$$, consisting of $$$n$$$ characters. Each character is either a $$$0$$$ or a $$$1$$$. $$$0$$$ means that Monocarp disliked the song, and $$$1$$$ means that he liked it. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print a permutation $$$q$$$ — the re-evaluated ratings of the songs. If there are multiple answers such that $$$\sum\limits_{i=1}^n |p_i-q_i|$$$ is minimum possible, you can print any of them.

NoteIn the first testcase, there exists only one permutation $$$q$$$ such that each liked song is rating higher than each disliked song: song $$$1$$$ gets rating $$$2$$$ and song $$$2$$$ gets rating $$$1$$$. $$$\sum\limits_{i=1}^n |p_i-q_i|=|1-2|+|2-1|=2$$$.In the second testcase, Monocarp liked all songs, so all permutations could work. The permutation with the minimum sum of absolute differences is the permutation equal to $$$p$$$. Its cost is $$$0$$$.

package main

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

type Node struct {
	idx  int
	like uint8
	val  int
}

type Nodes []Node

//Len()
func (s Nodes) Len() int {
	return len(s)
}

//Less()
func (s Nodes) Less(i, j int) bool {
	if s[i].like == s[j].like {
		return s[i].val > s[j].val
	}
	return s[i].like > s[j].like
}

//Swap()
func (s Nodes) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	n := 0

	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)

	m := 0
	fmt.Fscan(f, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(f, &m)
		var res = make([]int, m, m)
		var arr = make(Nodes, m, m)
		for j := 0; j < m; j++ {
			arr[j].idx = j
			fmt.Fscan(f, &arr[j].val)
		}
		like := ""
		fmt.Fscan(f, &like)

		for j := 0; j < m; j++ {
			arr[j].like = like[j]
		}
		sort.Sort(arr)
		cnt := m
		for k := 0; k < m; k++ {
			res[arr[k].idx] = cnt
			cnt--
		}
		fmt.Fprint(w, res[0])
		for k := 1; k < m; k++ {
			fmt.Fprintf(w, " %v", res[k])
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

package main

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

func solve(P []int, s string) []int {
	n := len(P)
	// sum(abs(P[i] - Q[i])) min
	// 需要把大值分配给喜欢的部分
	var A []Pair
	var B []Pair

	for i := 0; i < n; i++ {
		if s[i] == '0' {
			A = append(A, Pair{P[i], i})
		} else {
			B = append(B, Pair{P[i], i})
		}
	}

	sort.Slice(A, func(i, j int) bool {
		return A[i].Less(A[j])
	})

	sort.Slice(B, func(i, j int) bool {
		return B[i].Less(B[j])
	})

	Q := make([]int, n)
	cur := n

	for i := 0; i < len(B); i++ {
		Q[B[i].second] = cur
		cur--
	}

	for i := 0; i < len(A); i++ {
		Q[A[i].second] = cur
		cur--
	}

	return Q
}

type Pair struct {
	first, second int
}

func (this Pair) Less(that Pair) bool {
	return this.first > that.first
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := readNNums(reader, n)
		s, _ := reader.ReadString('\n')
		res := solve(P, s)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

package main

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

type marker struct {
	Priority int
	Position int
}

func CF1622B(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		var n int
		fmt.Fscan(in, &n)

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

		fmt.Fscanln(in)
		var ratings string
		fmt.Fscanln(in, &ratings)

		likedSongs, dislikedSongs := gatherMarkers(ps, ratings)
		sort.SliceStable(likedSongs, func(i, j int) bool {
			return likedSongs[i].Priority < likedSongs[j].Priority
		})
		sort.SliceStable(dislikedSongs, func(i, j int) bool {
			return dislikedSongs[i].Priority < dislikedSongs[j].Priority
		})

		result := make([]int, n)
		for i := 0; i < len(dislikedSongs); i++ {
			result[dislikedSongs[i].Position] = i + 1
		}
		for i := 0; i < len(likedSongs); i++ {
			result[likedSongs[i].Position] = i + 1 + len(dislikedSongs)
		}
		for i := 0; i < len(result); i++ {
			fmt.Fprintf(out, "%d ", result[i])
		}
		fmt.Fprintln(out)
	}
}

func gatherMarkers(ps []int, ratings string) ([]marker, []marker) {
	likedSongs := make([]marker, 0, len(ps))
	dislikedSongs := make([]marker, 0, len(ps))
	for i := 0; i < len(ps); i++ {
		if string(ratings[i]) == "1" {
			likedSongs = append(likedSongs, marker{Position: i, Priority: ps[i]})
		} else {
			dislikedSongs = append(dislikedSongs, marker{Position: i, Priority: ps[i]})
		}
	}
	return likedSongs, dislikedSongs
}

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

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

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 n int
		fmt.Fscan(reader, &n)
		p := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i])
		}
		var s string
		fmt.Fscan(reader, &s)
		count := strings.Count(s, "0")
		wrong_ones := make([]int, 0)
		wrong_zeros := make([]int, 0)
		for i := 0; i < n; i++ {
			if s[i] == '0' && p[i] > count {
				wrong_zeros = append(wrong_zeros, i)
			}
			if s[i] == '1' && p[i] <= count {
				wrong_ones = append(wrong_ones, i)

			}
		}
		// fmt.Println(count, wrong_ones, wrong_zeros)
		for i := 0; i < len(wrong_ones); i++ {
			p[wrong_ones[i]], p[wrong_zeros[i]] = p[wrong_zeros[i]], p[wrong_ones[i]]
		}
		for i := 0; i < n; i++ {
			write_int(f, p[i])
			if i == n-1 {
				write_string(f, "\n")
			} else {
				write_string(f, " ")
			}
		}

	}
}

package main

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

type song struct {
	id     int
	rating int
	liked  int
}

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 n int
		fmt.Fscan(in, &n)

		songs := make([]song, n)
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)
			songs[i] = song{i, v, 0}
		}

		var s string
		fmt.Fscan(in, &s)

		for i, ch := range s {
			if ch == '1' {
				songs[i].liked = 1
			}
		}

		sort.SliceStable(songs, func(i, j int) bool {
			if songs[i].liked == songs[j].liked {
				return songs[i].rating < songs[j].rating
			}
			return songs[i].liked < songs[j].liked
		})

		ratings := make([]int, n)
		for i, song := range songs {
			ratings[song.id] = i + 1
		}

		for _, v := range ratings {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		p := readArrayInt(reader)
		s := readString(reader)

		var x []int
		var y []int

		for i := 0; i < n; i++ {
			if s[i] == '0' {
				x = append(x, p[i])
			} else {
				y = append(y, p[i])
			}
		}

		sort.Ints(x)
		sort.Ints(y)

		q := make([]int, n+1)

		for i, v := range x {
			q[v] = i + 1
		}

		for i, v := range y {
			q[v] = i + len(x) + 1
		}

		for i := 0; i < n; i++ {
			fmt.Fprint(writer, q[p[i]], " ")
		}
		fmt.Fprintln(writer)

		t--
	}

	writer.Flush()
}

func sum(a1 int64, n int64) int64 {
	return (2*a1 + (n-1)*4) * n / 2
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

type song struct {
	id   int
	rate int
	like int
}

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

func solve(n int, p []int, s string) string {
	songs := make([]song, n)
	for i := 0; i < n; i++ {
		songs[i] = song{i, p[i], int(s[i] - '0')}
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].rate < songs[j].rate
	})
	sort.SliceStable(songs, func(i, j int) bool {
		return songs[i].like < songs[j].like
	})
	result := make([]string, n)
	for i := range songs {
		result[songs[i].id] = fmt.Sprint(i + 1)
	}
	return strings.Join(result, " ")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		p := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &p[i])
		}
		fmt.Fscan(reader, &s)
		fmt.Println(solve(n, p, s))
	}
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)

	var p = make([]int, n)
	for i := range p {
		scan(&p[i])
	}

	var s string
	scan(&s)

	var liked, disliked = make([]int, 0), make([]int, 0)
	for i := range s {
		if s[i] == '0' {
			disliked = append(disliked, i)
		} else {
			liked = append(liked, i)
		}
	}

	sort.Slice(liked, func(i, j int) bool { return p[liked[i]] < p[liked[j]] })
	sort.Slice(disliked, func(i, j int) bool { return p[disliked[i]] < p[disliked[j]] })

	var (
		q   = make(map[int]int)
		num = 0
	)
	for _, i := range disliked {
		num++
		q[p[i]] = num
	}
	for _, i := range liked {
		num++
		q[p[i]] = num
	}

	for _, i := range p {
		printf("%v ", q[i])
	}
	printf("\n")
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	err = bufio.NewWriter(os.Stderr)
)

type Song struct {
	Id      int
	Rating  int
	LikeIdx int // 0: dislike, 1: like
}

func solve(t int) {
	n := readInt()
	songs := make([]Song, n)
	for i := 0; i < n; i++ {
		songs[i] = Song{
			Id:     i + 1,
			Rating: readInt(),
		}
	}
	s := readString()
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			songs[i].LikeIdx = 1
		}
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].LikeIdx < songs[j].LikeIdx ||
			(songs[i].LikeIdx == songs[j].LikeIdx && songs[i].Rating < songs[j].Rating)
	})
	for i := 0; i < n; i++ {
		songs[i].Rating = i + 1
	}
	sort.Slice(songs, func(i, j int) bool {
		return songs[i].Id < songs[j].Id
	})
	for i := 0; i < n; i++ {
		print(songs[i].Rating, " ")
	}
	println()
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve(i)
	}
}

// READ
func readInt() int {
	var res int
	fmt.Fscan(in, &res)
	return res
}

func readInt64() int64 {
	var res int64
	fmt.Fscan(in, &res)
	return res
}

func readString() string {
	var res string
	fmt.Fscan(in, &res)
	return res
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"os"
)

type pair struct {
	idx int
	val int
}

type myHeap []pair

func (h *myHeap) Less(i, j int) bool {
	return (*h)[i].val > (*h)[j].val
}

func (h *myHeap) Swap(i, j int) {
	(*h)[i], (*h)[j] = (*h)[j], (*h)[i]
}

func (h *myHeap) Len() int {
	return len(*h)
}

func (h *myHeap) Pop() (v interface{}) {
	*h, v = (*h)[:h.Len()-1], (*h)[h.Len()-1]
	return
}

func (h *myHeap) Push(v interface{}) {
	*h = append(*h, v.(pair))
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &arr[i])
	}
	var s string
	Fscan(in, &s)
	one := new(myHeap)
	zero := new(myHeap)
	cur := n
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			heap.Push(one, pair{i, arr[i]})
		}
	}
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			heap.Push(zero, pair{i, arr[i]})
		}
	}
	ans := make([]int, n)
	for cur != 0 {
		if one.Len() != 0 {
			pop := heap.Pop(one).(pair)
			ans[pop.idx] = cur
		} else {
			pop := heap.Pop(zero).(pair)
			ans[pop.idx] = cur
		}
		cur--
	}
	for i := 0; i < n; i++ {
		Fprintf(out, "%d ", ans[i])
	}
	Fprintln(out)
}

func main() {

	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 0
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

type E struct {
	val, ind int
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		n, s, o, p := 0, "", map[int]int{}, 0
		fmt.Fscan(f, &n)
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o[j] = p
		}
		fmt.Fscan(f, &s)
		a, b, c, k := []E{}, []E{}, make([]int, n), n
		for j := 0; j < len(s); j++ {
			if string(s[j]) == "1" {
				a = append(a, E{val: o[j], ind: j})
			} else {
				b = append(b, E{val: o[j], ind: j})
			}
		}
		sort.Slice(a, func(i, j int) bool { return a[i].val > a[j].val })
		sort.Slice(b, func(i, j int) bool { return b[i].val > b[j].val })
		for j := 0; j < len(a); j++ {
			c[a[j].ind] = k
			k--
		}
		for j := 0; j < len(b); j++ {
			c[b[j].ind] = k
			k--
		}
		for j := 0; j < len(c); j++ {
			fmt.Fprint(w, c[j], " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		var n int
		fmt.Fscan(in, &n)
		var p []int = make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &p[i])
		}
		var liked string
		var count0 = 0
		fmt.Fscan(in, &liked)
		for i := 0; i < n; i++ {
			if liked[i] == '0' {
				count0++
			}
		}

		var order []int = make([]int, n)
		for i := 0; i < n; i++ {
			order[i] = i
		}
		// fmt.Fprintf(out, "order = %v\n", order)
		sort.Slice(order, func(i, j int) bool {
			return p[order[i]] < p[order[j]]
		})
		var cur0 = 1
		var cur1 = count0 + 1
		var ans []int = make([]int, n)
		for _, i := range order {
			if liked[i] == '0' {
				ans[i] = cur0
				cur0++
			} else {
				ans[i] = cur1
				cur1++
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprintf(out, "%d ", ans[i])
		}
		fmt.Fprintln(out)
	}
	out.Flush()
}

package main

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

type marker struct {
	Priority int
	Position int
}

func CF1622B(rawIn io.Reader, rawOut io.Writer) {
	in := bufio.NewReader(rawIn)
	out := bufio.NewWriter(rawOut)
	defer out.Flush()

	var cases int
	fmt.Fscan(in, &cases)
	for cc := 0; cc < cases; cc++ {
		var n int
		fmt.Fscan(in, &n)

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

		fmt.Fscanln(in)
		var ratings string
		fmt.Fscanln(in, &ratings)

		likedSongs, dislikedSongs := gatherMarkers(ps, ratings)
		sort.SliceStable(likedSongs, func(i, j int) bool {
			return likedSongs[i].Priority < likedSongs[j].Priority
		})
		sort.SliceStable(dislikedSongs, func(i, j int) bool {
			return dislikedSongs[i].Priority < dislikedSongs[j].Priority
		})
		fmt.Println(likedSongs)
		fmt.Println(dislikedSongs)

		result := make([]int, n)
		for i := 0; i < len(dislikedSongs); i++ {
			result[dislikedSongs[i].Position] = i + 1
		}
		for i := 0; i < len(likedSongs); i++ {
			result[likedSongs[i].Position] = i + 1 + len(dislikedSongs)
		}
		for i := 0; i < len(result); i++ {
			fmt.Fprintf(out, "%d ", result[i])
		}
		fmt.Fprintln(out)
	}
}

func gatherMarkers(ps []int, ratings string) ([]marker, []marker) {
	likedSongs := make([]marker, 0, len(ps))
	dislikedSongs := make([]marker, 0, len(ps))
	for i := 0; i < len(ps); i++ {
		if string(ratings[i]) == "1" {
			likedSongs = append(likedSongs, marker{Position: i, Priority: ps[i]})
		} else {
			dislikedSongs = append(dislikedSongs, marker{Position: i, Priority: ps[i]})
		}
	}
	return likedSongs, dislikedSongs
}

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


John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are $$$n$$$ students, each of them has a unique id (from $$$1$$$ to $$$n$$$). Thomas's id is $$$1$$$. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids. Please help John find out the rank of his son.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of students. Each of the next $$$n$$$ lines contains four integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$, and $$$d_i$$$ ($$$0\leq a_i, b_i, c_i, d_i\leq 100$$$) — the grades of the $$$i$$$-th student on English, German, Math, and History. The id of the $$$i$$$-th student is equal to $$$i$$$.

Print the rank of Thomas Smith. Thomas's id is $$$1$$$.

NoteIn the first sample, the students got total scores: $$$398$$$, $$$400$$$, $$$398$$$, $$$379$$$, and $$$357$$$. Among the $$$5$$$ students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is $$$2$$$.In the second sample, the students got total scores: $$$369$$$, $$$240$$$, $$$310$$$, $$$300$$$, $$$300$$$, and $$$0$$$. Among the $$$6$$$ students, Thomas got the highest score, so his rank is $$$1$$$.

// A. The Rank
/*
John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.

There are 𝑛 students, each of them has a unique id (from 1 to 𝑛). Thomas's id is 1. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.

In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.

Please help John find out the rank of his son.

Input
The first line contains a single integer 𝑛 (1≤𝑛≤1000) — the number of students.

Each of the next 𝑛 lines contains four integers 𝑎𝑖, 𝑏𝑖, 𝑐𝑖, and 𝑑𝑖 (0≤𝑎𝑖,𝑏𝑖,𝑐𝑖,𝑑𝑖≤100) — the grades of the 𝑖-th student on English, German, Math, and History. The id of the 𝑖-th student is equal to 𝑖.

Output
Print the rank of Thomas Smith. Thomas's id is 1.

Examples
Input
5
100 98 100 100
100 100 100 100
100 100 99 99
90 99 90 100
100 98 60 99

Output
2

Input
6
100 80 90 99
60 60 60 60
90 60 100 60
60 100 60 80
100 100 0 100
0 0 0 0

Output
1

Note
In the first sample, the students got total scores: 398, 400, 398, 379, and 357. Among the 5 students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is 2.

In the second sample, the students got total scores: 369, 240, 310, 300, 300, and 0. Among the 6 students, Thomas got the highest score, so his rank is 1.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	t, ans := 0, 1
	for i := 0; i < n; i++ {
		input2, _ := reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(input2), " ")

		e, _ := strconv.Atoi(arr[0])
		g, _ := strconv.Atoi(arr[1])
		m, _ := strconv.Atoi(arr[2])
		h, _ := strconv.Atoi(arr[3])

		s := e + g + m + h
		if i == 0 {
			t = s
		}
		if t < s {
			ans++
		}
	}
	fmt.Print(ans)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	tomScore := a + b + c + d
	tomRank := 1
	for i := 1; i < n; i++ {
		fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
		otherScore := a + b + c + d
		if otherScore > tomScore {
			tomRank++
		}
	}
	fmt.Println(tomRank)
}

package main

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

func main()  {

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)

	var tom, rank, s1, s2, s3, s4 int
	fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)

	rank = 1
	tom = s1 + s2 + s3 + s4

	for i := 1; i < n; i++ {
		fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
		if tom < s1 + s2 + s3 + s4 {
			rank++
		}

	}

	fmt.Fprintln(out, rank)

}

package main

import "fmt"

func main() {
	var n, thomas int
	fmt.Scan(&n)

	ans := 1
	for i := range make([]struct{}, n) {
		score := 0
		for range make([]struct{}, 4) {
			var a int
			fmt.Scan(&a)
			score += a
		}
		if i == 0 {
			thomas = score
		}
		if score > thomas {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

import (
    "fmt"
    "sort"
)

type Pair struct {
    sum int
    id int
}

type Pairs []Pair

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

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

func (arr Pairs) Less(i, j int) bool {
    if arr[i].sum != arr[j].sum {
        return arr[i].sum < arr[j].sum
    }
    return arr[i].id > arr[j].id
}

func main() {
    var n int
    fmt.Scan(&n)
    arr := make([]Pair, n)
    for iter := 0; iter < n; iter++ {
        var a, b, c, d int
        fmt.Scan(&a, &b, &c, &d)
        arr[iter].id = iter
        arr[iter].sum = a + b + c + d
    }
    sort.Sort(Pairs(arr))
    for iter := 0; iter < n; iter++ {
        if arr[iter].id == 0 {
            fmt.Println(n - iter)
        }
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := 0
	s1, s2, s3, s4 := 0, 0, 0, 0
	fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
	a = s1 + s2 + s3 + s4
	rank := 1
	for i := 1; i < n; i++ {
		fmt.Fscanf(in, "%d %d %d %d\n", &s1, &s2, &s3, &s4)
		b := s1 + s2 + s3 + s4
		if b > a {
			rank++
		}
	}
	fmt.Fprintf(out, "%d\n", rank)
	return
}

package main

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

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

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

type student struct {
	id, score int
}

func main() {
	var n, a, b, c, d int
	scanf("%d\n", &n)
	students := make([]*student, n)
	for i := 0; i < n; i++ {
		scanf("%d %d %d %d\n", &a, &b, &c, &d)
		students[i] = &student{id: i, score: a + b + c + d}
	}

	sort.Slice(students, func(i, j int) bool {
		if students[i].score != students[j].score {
			return students[i].score > students[j].score
		}
		return students[i].id < students[j].id
	})

	for i, s := range students {
		if s.id == 0 {
			printf("%d\n", i+1)
			break
		}
	}

	writer.Flush()
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreTomas, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		if i == 0 {
		   scoreTomas = a + b + c + d;
		} else {
		   score = a + b + c + d;
		   if score > scoreTomas {
		   		student ++
		   }
		}
	}

	fmt.Printf("%d", student + 1)
}

package main

import "fmt"

func main() {
	var n, a, b, c, d, smith, rank int
	fmt.Scan(&n)
	rank = 1
	smith = -1
	for ; n > 0; n-- {
		fmt.Scan(&a, &b, &c, &d)
		if smith == -1 {
			smith = a + b + c + d
		}
		if a+b+c+d > smith {
			rank++
		}

	}
	fmt.Println(rank)
}

package main

import (
	"fmt"
)

type pair struct {
	first  int
	second int
}

func main() {
	var n int

	fmt.Scan(&n)

	a := [1000][5]int{}
	sum := [1000]pair{}

	for i := 0; i < n; i++ {
		for j := 0; j < 4; j++ {
			fmt.Scan(&a[i][j])
			sum[i].first += a[i][j]
		}
		sum[i].second = i + 1
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n-i-1; j++ {
			if sum[j].first < sum[j+1].first {
				sum[j], sum[j+1] = sum[j+1], sum[j]
			}
		}
	}

	for i := 0; i < n; i++ {
		if sum[i].second == 1 {
			fmt.Println(i + 1)
			break
		}
	}

}

package main

import (
  "fmt"
  )

func main(){
  var n,m,r int
  fmt.Scan(&n)
  for i:=0;i<n;i++ {
    o := make([]int,4)
    fmt.Scan(&o[0],&o[1],&o[2],&o[3])
    x := o[0]+o[1]+o[2]+o[3]
    if i ==0 {
      r = x
      m++
      } else {
      if x > r {
        m++
        }
      }
    }
  fmt.Println(m)

  }

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	tomScore := a + b + c + d
	tomRank := 1
	for i := 1; i < n; i++ {
		fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
		otherScore := a + b + c + d
		if otherScore > tomScore {
			tomRank++
		}
	}
	fmt.Println(tomRank)
}

package main

import "fmt"

func main() {
	var n, ans, cntMx int
	fmt.Scan(&n)

	for i := range make([]struct{}, n) {
		cnt := 0
		for range make([]struct{}, 4) {
			var a int
			fmt.Scan(&a)
			cnt += a
		}
		if cnt > cntMx {
			ans = i + 1
			cntMx = cnt
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreMax, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		score = a + b + c + d

		if score >= scoreMax {
			scoreMax = score
			student = i
		}
	}

	fmt.Printf("%d", student + 1)
}

package main

import (
	"fmt"
	)

func main() {
	var students, score, scoreMax, student int

	fmt.Scan(&students)
	for i:=0; i<students; i++ {
		var a, b, c, d int
		fmt.Scan(&a, &b, &c, &d)

		score = a + b + c + d;
		if score >= scoreMax {
			scoreMax = score
			student = i
		}
	}

	fmt.Printf("%d", student + 1)
}