package main

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

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

	type pair struct{ u, v int}

	T:= 0
	for Fscan(in, &T); T > 0; T-- {
		n,m :=0,0
		Fscan(in, &n, &m)
		undirected := make([] pair,0)
		e := make([][]int, n)
		deg := make([]int, n)
		for i:=0;i<m;i++{
			t,u,v :=0,0,0
			Fscan(in, &t, &u , &v)
			// Fprintln(out,t,u,v)
			u,v=u-1,v-1
			// Fprintln(out,t,u,v)
			if t==1 {
				e[u]=append(e[u],v)
				deg[v]++
				// Fprintln(out,"dr",u,v)
			} else {
				undirected = append(undirected,pair{u,v})
			}
		}

		topo := make([]int,0,n)
		pos := make([]int,n)
		for i:=0;i<n;i++{
			if deg[i]==0{
				topo=append(topo,i)
			}
		}

		fl:=true

		for i:=0;i<n;i++{
			if len(topo) == i{
				fl=false;
				break
			}
			u:=topo[i]
			pos[u]=i
			for _,v := range(e[u]){
				deg[v]--
				if deg[v]==0{
					topo=append(topo,v)
				}
			}
		}

		// Fprintln(out,deg)
		// Fprintln(out,undirected)
		// Fprintln(out,e)
		if !fl {
			Fprintln(out,"NO")
			continue
		}

		Fprintln(out,"YES")
		for u:=0;u<n;u++{
			for _,v := range(e[u]){
				Fprintln(out,u+1,v+1)
			}
		}
		// Fprintln(out,topo)
		for _,d := range(undirected){
			u,v := d.u,d.v
			if pos[u]<pos[v]{
				Fprintln(out,u+1,v+1)
			} else {
				Fprintln(out,v+1,u+1)
			}
		}
	}
}

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

package main

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

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

	type edge struct {
		t, v int
	}

	for t := io.nextInt(); t > 0; t-- {
		n, m := io.nextInt(), io.nextInt()
		g := make([][]edge, n+1)
		in := make([]int, n+1)
		for i := 0; i < m; i++ {
			typ, u, v := io.nextInt(), io.nextInt(), io.nextInt()
			g[u] = append(g[u], edge{typ, v})
			if typ == 1 {
				in[v]++
			} else {
				g[v] = append(g[v], edge{typ, u})
			}
		}

		var q []int
		for u := 1; u <= n; u++ {
			if in[u] == 0 {
				q = append(q, u)
			}
		}

		var topo []int
		for len(q) > 0 {
			u := q[0]
			q = q[1:]
			topo = append(topo, u)
			for _, e := range g[u] {
				if e.t == 1 {
					in[e.v]--
					if in[e.v] == 0 {
						q = append(q, e.v)
					}
				}
			}
		}

		if len(topo) < n {
			io.println("NO")
		} else {
			io.println("YES")
			vis := make([]bool, n+1)
			for _, u := range topo {
				vis[u] = true
				for _, e := range g[u] {
					if !vis[e.v] {
						io.println(u, e.v)
					}
				}
			}
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) next() string {
	f.Read(f.p)
	for f.p[0] <= ' ' {
		f.Read(f.p)
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p)
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

package main

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

type Queue struct {
    size int
    data []int
}

func QueueNew() *Queue {
    return &Queue{
        size: 0,
        data: make([]int, 0),
    }
}

func (q *Queue) Push(e int) {
    q.size++
    q.data = append(q.data, e)
}

func (q *Queue) Pop() int {
    rv := q.data[0]
    q.size--
    q.data = q.data[1:]
    return rv
}

func (q *Queue) Empty() bool {
    return q.size == 0
}

type IntVector struct {
    size int
    data []int
}

func IntVectorNew(size int) *IntVector {
    rv := &IntVector{
        size: size,
        data: make([]int, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = 0
    }
    return rv
}

func (v *IntVector) Push(e int) {
    v.size++
    v.data = append(v.data, e)
}

func (v *IntVector) Size() int {
    return v.size
}

func (v *IntVector) At(idx int) *int {
    return &v.data[idx]
}

type Pair struct {
    first int
    second int
}

type PairVector struct {
    size int
    data []Pair
}

func PairVectorNew(size int) *PairVector {
    rv := &PairVector{
        size: size,
        data: make([]Pair, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = Pair{first: 0, second: 0}
    }
    return rv
}

func (v *PairVector) Push(e Pair) {
    v.size++
    v.data = append(v.data, e)
}

func (v *PairVector) Size() int {
    return v.size
}

func (v *PairVector) At(idx int) *Pair {
    return &v.data[idx]
}

type VectorVector struct {
    size int
    data []*IntVector
}

func VectorVectorNew(size int) *VectorVector {
    rv := &VectorVector{
        size: size,
        data: make([]*IntVector, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = IntVectorNew(0)
    }
    return rv
}

func (v *VectorVector) Push(e *IntVector) {
    v.size++
    v.data = append(v.data, e)
}

func (v *VectorVector) Size() int {
    return v.size
}

func (v *VectorVector) At(idx int) *IntVector {
    return v.data[idx]
}

type Task struct {
    nedges int
    nvertices int
    directed *VectorVector
    undirected *PairVector
    position *IntVector
}

func TaskNew() *Task {
    return &Task{
        nedges: 0,
        nvertices: 0,
        directed: nil,
        undirected: PairVectorNew(0),
        position: nil,
    }
}

func (task *Task) ReadInput(stdin *bufio.Scanner) {
    stdin.Scan()
    fmt.Sscanf(stdin.Text(), "%d %d\n", &task.nvertices, &task.nedges)
    task.directed = VectorVectorNew(task.nvertices + 1)
    task.position = IntVectorNew(task.nvertices + 1)

    for i := 0; i < task.nedges; i++ {
        var t, from, to int
        stdin.Scan()
        fmt.Sscanf(stdin.Text(), "%d %d %d\n", &t, &from, &to)

        if 1 == t {
            task.directed.At(from).Push(to)
        } else {
            task.undirected.Push(Pair{first: from, second: to})
        }
    }
}

func (task *Task) WriteOutput() {
    if task.Topsort() == false {
        fmt.Println("NO")
        return
    }

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            if *task.position.At(u) >= *task.position.At(v) {
                fmt.Println("NO")
                return
            }
        }
    }

    fmt.Println("YES")

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            fmt.Println(u, v)
        }
    }

    for i := 0; i < task.undirected.Size(); i++ {
        u := task.undirected.At(i).first
        v := task.undirected.At(i).second
        if *task.position.At(u) < *task.position.At(v) {
            fmt.Println(u, v)
        } else {
            fmt.Println(v, u)
        }
    }
}

func (task *Task) Topsort() bool {
    queue := QueueNew()
    ideg := IntVectorNew(task.nvertices + 1)
    position := 1

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            *ideg.At(v)++
        }
    }

    for u := 1; u <= task.nvertices; u++ {
        if *ideg.At(u) == 0 {
            queue.Push(u)
        }
    }

    if queue.Empty() {
        return false
    }

    for queue.Empty() == false {
        u := queue.Pop()
        *task.position.At(u) = position
        position++

        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            *ideg.At(v)--
            if *ideg.At(v) == 0 {
                queue.Push(v)
            }
        }
    }

    return true
}

func main() {
    stdin := bufio.NewScanner(os.Stdin)
    stdin.Scan()

    var ntests int
    fmt.Sscanf(stdin.Text(), "%d\n", &ntests)

    for n := 0; n < ntests; n++ {
        task := TaskNew()
        task.ReadInput(stdin)
        task.WriteOutput()
    }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ to, tp int }

	var t, n, m, tp, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		g := make([][]pair, n)
		deg := make([]int, n)
		for ; m > 0; m-- {
			Fscan(in, &tp, &v, &w)
			v--
			w--
			g[v] = append(g[v], pair{w, tp})
			if tp == 0 {
				g[w] = append(g[w], pair{v, tp})
			} else {
				deg[w]++
			}
		}
		vis := make([]bool, n)
		used := make([]bool, n)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				vis[i] = true
				q = append(q, i)
			}
		}
		c := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			c++
			for i, e := range g[v] {
				w := e.to
				if e.tp == 0 {
					if !used[w] {
						g[v][i].tp = 1
					}
				} else {
					deg[w]--
				}
				if deg[w] == 0 && !vis[w] {
					vis[w] = true
					q = append(q, w)
				}
			}
			used[v] = true //
		}
		if c < n {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		for v, es := range g {
			for _, e := range es {
				if e.tp == 1 {
					Fprintln(out, v+1, e.to+1)
				}
			}
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ to, tp int }

	var t, n, m, tp, v, w int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		g := make([][]pair, n)
		deg := make([]int, n)
		for ; m > 0; m-- {
			Fscan(in, &tp, &v, &w)
			v--
			w--
			g[v] = append(g[v], pair{w, tp})
			if tp == 0 {
				g[w] = append(g[w], pair{v, tp})
			} else {
				deg[w]++
			}
		}
		vis := make([]int8, n)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				vis[i] = 1
				q = append(q, i)
			}
		}
		c := 0
		for len(q) > 0 {
			v, q = q[0], q[1:]
			c++
			for i, e := range g[v] {
				w := e.to
				if e.tp == 0 {
					if vis[w] < 2 {
						g[v][i].tp = 1
					}
				} else {
					deg[w]--
				}
				if deg[w] == 0 && vis[w] == 0 {
					vis[w] = 1
					q = append(q, w)
				}
			}
			vis[v] = 2
		}
		if c < n {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		for v, es := range g {
			for _, e := range es {
				if e.tp == 1 {
					Fprintln(out, v+1, e.to+1)
				}
			}
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385E(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	type pair struct{ to, tp int }

	for t := r(); t > 0; t-- {
		n, m := r(), r()
		g := make([][]pair, n)
		deg := make([]int, n)
		for ; m > 0; m-- {
			tp, v, w := r(), r()-1, r()-1
			g[v] = append(g[v], pair{w, tp})
			if tp == 0 {
				g[w] = append(g[w], pair{v, tp})
			} else {
				deg[w]++
			}
		}
		vis := make([]int8, n)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				vis[i] = 1
				q = append(q, i)
			}
		}
		c := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			c++
			for i, e := range g[v] {
				w := e.to
				if e.tp == 0 {
					if vis[w] < 2 {
						g[v][i].tp = 1
					}
				} else {
					deg[w]--
				}
				if deg[w] == 0 && vis[w] == 0 {
					vis[w] = 1
					q = append(q, w)
				}
			}
			vis[v] = 2
		}
		if c < n {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		for v, es := range g {
			for _, e := range es {
				if e.tp != 0 {
					Fprintln(out, v+1, e.to+1)
				}
			}
		}
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"runtime/debug"
)

func init() {
	debug.SetGCPercent(-1)
}

// github.com/EndlessCheng/codeforces-go
func CF1385E(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := [4096]byte{}
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf[:])
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	type pair struct{ to, tp int }

	for t := r(); t > 0; t-- {
		n, m := r(), r()
		g := make([][]pair, n)
		deg := make([]int, n)
		for ; m > 0; m-- {
			tp, v, w := r(), r()-1, r()-1
			g[v] = append(g[v], pair{w, tp})
			if tp == 0 {
				g[w] = append(g[w], pair{v, tp})
			} else {
				deg[w]++
			}
		}
		vis := make([]int8, n)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				vis[i] = 1
				q = append(q, i)
			}
		}
		c := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			c++
			for i, e := range g[v] {
				w := e.to
				if e.tp == 0 {
					if vis[w] < 2 {
						g[v][i].tp = 1
					}
				} else {
					deg[w]--
				}
				if deg[w] == 0 && vis[w] == 0 {
					vis[w] = 1
					q = append(q, w)
				}
			}
			vis[v] = 2
		}
		if c < n {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		for v, es := range g {
			for _, e := range es {
				if e.tp != 0 {
					Fprintln(out, v+1, e.to+1)
				}
			}
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1385E(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := [4096]byte{}
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf[:])
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}
	type pair struct{ to, tp int }

	for t := r(); t > 0; t-- {
		n, m := r(), r()
		g := make([][]pair, n)
		deg := make([]int, n)
		for ; m > 0; m-- {
			tp, v, w := r(), r()-1, r()-1
			g[v] = append(g[v], pair{w, tp})
			if tp == 0 {
				g[w] = append(g[w], pair{v, tp})
			} else {
				deg[w]++
			}
		}
		vis := make([]int8, n)
		q := []int{}
		for i, d := range deg {
			if d == 0 {
				vis[i] = 1
				q = append(q, i)
			}
		}
		c := 0
		for len(q) > 0 {
			v := q[0]
			q = q[1:]
			c++
			for i, e := range g[v] {
				w := e.to
				if e.tp == 0 {
					if vis[w] < 2 {
						g[v][i].tp = 1
					}
				} else {
					deg[w]--
				}
				if deg[w] == 0 && vis[w] == 0 {
					vis[w] = 1
					q = append(q, w)
				}
			}
			vis[v] = 2
		}
		if c < n {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		for v, es := range g {
			for _, e := range es {
				if e.tp != 0 {
					Fprintln(out, v+1, e.to+1)
				}
			}
		}
	}
}

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

package main

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

type Age struct {
	x, y int
}

var color []int
var g [][]int
var gOr [][]int

var hasCycle bool
var ans []Age
var used []bool

func dfs(v int) {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}

	if hasCycle {
		return
	}

	for _, to := range gOr[v] {
		if !used[to] {
			g[to] = append(g[to], v)
			ans = append(ans, Age{to, v})
		}
	}

	used[v] = true
	color[v] = 2
}

func dfs2(v int)  {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs2(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}
	color[v] = 2
}

func main() {
	defer writer.Flush()
	tests := NextInt()
	for tests > 0 {
		tests--
		n, m := NextInt(), NextInt()
		g = make([][]int, n+1)
		gOr = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			g[i] = make([]int, 0)
			gOr[i] = make([]int, 0)
		}

		ans = make([]Age, 0)
		for i := 0; i < m; i++ {
			t, x, y := NextInt(), NextInt(), NextInt()
			if t == 1 {
				ans = append(ans, Age{x, y})
				g[x] = append(g[x], y)
			} else {
				gOr[x] = append(gOr[x], y)
				gOr[y] = append(gOr[y], x)
			}
		}

		color = make([]int, n+1)
		hasCycle = false
		used = make([]bool, n+1)

		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs(i)
			}
		}

		color = make([]int, n+1)
		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs2(i)
			}
		}

		if hasCycle {
			Println("NO")
		} else {
			Println("YES")
			for _, age := range ans {
				Print(age.x)
				Print(" ")
				Println(age.y)
			}
		}
	}
}

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

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

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

	type edge struct {
		t, v int
	}

	for t := io.nextInt(); t > 0; t-- {
		n, m := io.nextInt(), io.nextInt()
		g := make([][]edge, n+1)
		in := make([]int, n+1)
		for i := 0; i < m; i++ {
			typ, u, v := io.nextInt(), io.nextInt(), io.nextInt()
			g[u] = append(g[u], edge{typ, v})
			if typ == 1 {
				in[v]++
			} else {
				g[v] = append(g[v], edge{typ, u})
			}
		}

		var q []int
		for u := 1; u <= n; u++ {
			if in[u] == 0 {
				q = append(q, u)
			}
		}

		var topo []int
		for len(q) > 0 {
			u := q[0]
			q = q[1:]
			topo = append(topo, u)
			for _, e := range g[u] {
				if e.t == 1 {
					in[e.v]--
					if in[e.v] == 0 {
						fmt.Println("push", e.v)
						q = append(q, e.v)
					}
				}
			}
		}

		if len(topo) < n {
			io.println("NO")
		} else {
			io.println("YES")
			vis := make([]bool, n+1)
			for _, u := range topo {
				vis[u] = true
				for _, e := range g[u] {
					if !vis[e.v] {
						io.println(u, e.v)
					}
				}
			}
		}
	}
}

type fastIO struct {
	*bufio.Reader
	*bufio.Writer
	p []byte
}

func newFastIO(r io.Reader, w io.Writer) fastIO {
	return fastIO{bufio.NewReader(r), bufio.NewWriter(w), make([]byte, 1)}
}

func (f *fastIO) nextInt() int {
	f.Read(f.p)
	for !('0' <= f.p[0] && f.p[0] <= '9') {
		f.Read(f.p)
	}
	n := 0
	for '0' <= f.p[0] && f.p[0] <= '9' {
		n = n*10 + int(f.p[0]) - '0'
		f.Read(f.p)
	}
	return n
}

func (f *fastIO) next() string {
	f.Read(f.p)
	for f.p[0] <= ' ' {
		f.Read(f.p)
	}
	var s []byte
	for f.p[0] > ' ' {
		s = append(s, f.p[0])
		f.Read(f.p)
	}
	return string(s)
}

func (f *fastIO) println(a ...interface{}) {
	fmt.Fprintln(f.Writer, a...)
}

func (f *fastIO) print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

package main

import (
    "fmt"
)

type Queue struct {
    size int
    data []int
}

func QueueNew() *Queue {
    return &Queue{
        size: 0,
        data: make([]int, 0),
    }
}

func (q *Queue) Push(e int) {
    q.size++
    q.data = append(q.data, e)
}

func (q *Queue) Pop() int {
    rv := q.data[0]
    q.size--
    q.data = q.data[1:]
    return rv
}

func (q *Queue) Empty() bool {
    return q.size == 0
}

type IntVector struct {
    size int
    data []int
}

func IntVectorNew(size int) *IntVector {
    rv := &IntVector{
        size: size,
        data: make([]int, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = 0
    }
    return rv
}

func (v *IntVector) Push(e int) {
    v.size++
    v.data = append(v.data, e)
}

func (v *IntVector) Size() int {
    return v.size
}

func (v *IntVector) At(idx int) *int {
    return &v.data[idx]
}

type Pair struct {
    first int
    second int
}

type PairVector struct {
    size int
    data []Pair
}

func PairVectorNew(size int) *PairVector {
    rv := &PairVector{
        size: size,
        data: make([]Pair, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = Pair{first: 0, second: 0}
    }
    return rv
}

func (v *PairVector) Push(e Pair) {
    v.size++
    v.data = append(v.data, e)
}

func (v *PairVector) Size() int {
    return v.size
}

func (v *PairVector) At(idx int) *Pair {
    return &v.data[idx]
}

type VectorVector struct {
    size int
    data []*IntVector
}

func VectorVectorNew(size int) *VectorVector {
    rv := &VectorVector{
        size: size,
        data: make([]*IntVector, size),
    }
    for i := 0; i < rv.size; i++ {
        rv.data[i] = IntVectorNew(0)
    }
    return rv
}

func (v *VectorVector) Push(e *IntVector) {
    v.size++
    v.data = append(v.data, e)
}

func (v *VectorVector) Size() int {
    return v.size
}

func (v *VectorVector) At(idx int) *IntVector {
    return v.data[idx]
}

type Task struct {
    nedges int
    nvertices int
    directed *VectorVector
    undirected *PairVector
    position *IntVector
}

func TaskNew() *Task {
    return &Task{
        nedges: 0,
        nvertices: 0,
        directed: nil,
        undirected: PairVectorNew(0),
        position: nil,
    }
}

func (task *Task) ReadInput() {
    fmt.Scanf("%d %d\n", &task.nvertices, &task.nedges)
    task.directed = VectorVectorNew(task.nvertices + 1)
    task.position = IntVectorNew(task.nvertices + 1)

    for i := 0; i < task.nedges; i++ {
        var t, from, to int
        fmt.Scanf("%d %d %d\n", &t, &from, &to)

        if 1 == t {
            task.directed.At(from).Push(to)
        } else {
            task.undirected.Push(Pair{first: from, second: to})
        }
    }
}

func (task *Task) WriteOutput() {
    if task.Topsort() == false {
        fmt.Println("NO")
        return
    }

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            if *task.position.At(u) >= *task.position.At(v) {
                fmt.Println("NO")
                return
            }
        }
    }

    fmt.Println("YES")

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            if *task.position.At(u) >= *task.position.At(v) {
                fmt.Println(u, v)
            } else {
                fmt.Println(v, u)
            }
        }
    }

    for i := 0; i < task.undirected.Size(); i++ {
        u := task.undirected.At(i).first
        v := task.undirected.At(i).second
        if *task.position.At(u) < *task.position.At(v) {
            fmt.Println(u, v)
        } else {
            fmt.Println(v, u)
        }
    }
}

func (task *Task) Topsort() bool {
    queue := QueueNew()
    ideg := IntVectorNew(task.nvertices + 1)
    position := 1

    for u := 1; u <= task.nvertices; u++ {
        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            *ideg.At(v)++
        }
    }

    for u := 1; u <= task.nvertices; u++ {
        if *ideg.At(u) == 0 {
            queue.Push(u)
        }
    }

    if queue.Empty() {
        return false
    }

    for queue.Empty() == false {
        u := queue.Pop()
        *task.position.At(u) = position
        position++

        for vidx := 0; vidx < task.directed.At(u).Size(); vidx++ {
            v := *task.directed.At(u).At(vidx)
            *ideg.At(v)--
            if *ideg.At(v) == 0 {
                queue.Push(v)
            }
        }
    }

    return true
}

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

    for n := 0; n < ntests; n++ {
        task := TaskNew()
        task.ReadInput()
        task.WriteOutput()
    }
}

package main

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

type Age struct {
	x, y int
}

var color []int
var g [][]int
var gOr [][]int

var hasCycle bool
var ans []Age
var used []bool

func dfs(v int) {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs(to)
		} else if color[to] == 1 {
			hasCycle = true
		}
	}
	for _, to := range gOr[v] {
		if !used[to] {
			ans = append(ans, Age{to, v})
		}
	}

	used[v] = true
	color[v] = 2
}

func main() {
	defer writer.Flush()
	tests := NextInt()
	for tests > 0 {
		tests--
		n, m := NextInt(), NextInt()
		g = make([][]int, n+1)
		gOr = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			g[i] = make([]int, 0)
			gOr[i] = make([]int, 0)
		}

		ans = make([]Age, 0)
		for i := 0; i < m; i++ {
			t, x, y := NextInt(), NextInt(), NextInt()
			if t == 1 {
				ans = append(ans, Age{x, y})
				g[x] = append(g[x], y)
			} else {
				gOr[x] = append(g[x], y)
				gOr[y] = append(g[y], x)
			}
		}

		color = make([]int, n+1)
		hasCycle = false

		used = make([]bool, n+1)
		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs(i)
			}
		}
		if hasCycle {
			Println("NO")
		} else {
			Println("YES")
			for _, age := range ans {
				Print(age.x)
				Print(" ")
				Println(age.y)
			}
		}
	}
}

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

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

type Age struct {
	x, y int
}

var color []int
var g [][]int
var gOr [][]int

var hasCycle bool
var ans []Age
var used []bool

func dfs(v int) {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}

	if hasCycle {
		return
	}

	for _, to := range gOr[v] {
		if !used[to] {
			g[to] = append(g[to], v)
			ans = append(ans, Age{to, v})
		}
	}

	used[v] = true
	color[v] = 2
}

func dfs2(v int)  {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs2(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}
	color[v] = 2
}
func main() {
	defer writer.Flush()
	tests := NextInt()
	for tests > 0 {
		tests--
		n, m := NextInt(), NextInt()
		g = make([][]int, n+1)
		gOr = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			g[i] = make([]int, 0)
			gOr[i] = make([]int, 0)
		}

		ans = make([]Age, 0)
		for i := 0; i < m; i++ {
			t, x, y := NextInt(), NextInt(), NextInt()
			if t == 1 {
				ans = append(ans, Age{x, y})
				g[x] = append(g[x], y)
			} else {
				gOr[x] = append(g[x], y)
				gOr[y] = append(g[y], x)
			}
		}

		color = make([]int, n+1)
		hasCycle = false
		used = make([]bool, n+1)

		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs(i)
			}
		}

		color = make([]int, n+1)
		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs2(i)
			}
		}

		if hasCycle {
			Println("NO")
		} else {
			Println("YES")
			for _, age := range ans {
				Print(age.x)
				Print(" ")
				Println(age.y)
			}
		}
	}
}

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

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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

package main

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

type Age struct {
	x, y int
}

var color []int
var g [][]int
var gOr [][]int

var hasCycle bool
var ans []Age
var used []bool

func dfs(v int) {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}

	if hasCycle {
		return
	}

	for _, to := range gOr[v] {
		if !used[to] {
			g[to] = append(g[to], v)
			ans = append(ans, Age{to, v})
		}
	}

	used[v] = true
	color[v] = 2
}

func dfs2(v int)  {
	color[v] = 1
	for _, to := range g[v] {
		if color[to] == 0 {
			dfs(to)
		} else if color[to] == 1 {
			hasCycle = true
			break
		}
	}
	color[v] = 2
}
func main() {
	defer writer.Flush()
	tests := NextInt()
	for tests > 0 {
		tests--
		n, m := NextInt(), NextInt()
		g = make([][]int, n+1)
		gOr = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			g[i] = make([]int, 0)
			gOr[i] = make([]int, 0)
		}

		ans = make([]Age, 0)
		for i := 0; i < m; i++ {
			t, x, y := NextInt(), NextInt(), NextInt()
			if t == 1 {
				ans = append(ans, Age{x, y})
				g[x] = append(g[x], y)
			} else {
				gOr[x] = append(g[x], y)
				gOr[y] = append(g[y], x)
			}
		}

		color = make([]int, n+1)
		hasCycle = false
		used = make([]bool, n+1)

		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs(i)
			}
		}

		color = make([]int, n+1)
		for i := 1; i <= n; i++ {
			if color[i] == 0 {
				dfs2(i)
			}
		}

		if hasCycle {
			Println("NO")
		} else {
			Println("YES")
			for _, age := range ans {
				Print(age.x)
				Print(" ")
				Println(age.y)
			}
		}
	}
}

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

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func Println(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v\n", data))
}

func Print(data interface{}) {
	writer.WriteString(fmt.Sprintf("%v", data))
}

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

func NextInt() int {
	i, err := strconv.Atoi(Next())
	if err != nil {
		panic(err)
	}
	return i
}

func NextInt64() int64 {
	i64, err := strconv.ParseInt(Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i64
}

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


package main

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

type CF1722B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1722B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1722B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1722B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1722B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1722B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1722B
Date: 31/08/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1722/B
Problem: CF1722B
**/
func (in *CF1722B) Run() {
	mapa := make(map[uint8]uint8)
	mapa['B'] = 'G'
	mapa['G'] = 'B'
	mapa['R'] = 'R'
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		a := in.NextString()
		b := in.NextString()

		equals := true
		for i := 0; i < n; i++ {
			if a[i] == b[i] || (a[i] == 'G' && b[i] == 'B') || (a[i] == 'B' && b[i] == 'G') {
				continue
			} else {
				equals = false
			}
		}

		if equals {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func NewCF1722B(r *bufio.Reader) *CF1722B {
	return &CF1722B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1722B(bufio.NewReader(os.Stdin)).Run()
}

package main

import "fmt"

func findAns(input1, input2 string, n int) {
	// fmt.Println(input1, "   ", input2)
	for i := 0; i < n; i++ {
		if input1[i] != input2[i] && !((string(input1[i]) == "G" && string(input2[i]) == "B") || (string(input1[i]) == "B" && string(input2[i]) == "G")) {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	t, n := 0, 0
	input1, input2 := "", ""
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&input1)
		fmt.Scan(&input2)
		findAns(input1, input2, n)
		t--
	}
}

package main

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

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

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

func main() {

	defer writer.Flush()

	var t int
	scanws(&t)

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

		var n int
		scanws(&n)

		var s1 string
		var s2 string

		scanws(&s1)
		scanws(&s2)

		gb := "GB"

		f := 0

		for j := 0; j < len(s1); j++ {

			if (s1[j] == gb[0] || s1[j] == gb[1]) && (s2[j] == gb[0] || s2[j] == gb[1]) {

				continue
			} else {
				if (s1[j] != s2[j]) {
					printf("NO\n")
					f = 1
					break
				}
			}

		}

		if f == 0 {
			printf("YES\n")
		}

	}
}

package main

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

func main() {
	var (
		t      int
		n      int
		str1   string
		str2   string
		strsl1 []string
		strsl2 []string
		c      int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		strsl1, strsl2, c = nil, nil, 0
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		str1 = scanner.Text()
		scanner.Scan()
		str2 = scanner.Text()
		strsl1, strsl2 = strings.Split(str1, ""), strings.Split(str2, "")
		for j := 0; j < n; j++ {
			if strsl1[j] == strsl2[j] {
				c++
			} else if (strsl1[j] == "B" || strsl1[j] == "G") && (strsl2[j] == "B" || strsl2[j] == "G") {
				c++
			}
		}
		if c == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var a,b string
		fmt.Scan(&a,&b)
		for j:=0;j<n;j++{
			if string(a[j]) == "R" {
				if string(b[j]) != "R" {
					fmt.Println("NO")
					goto out
				}
			} else {
				if string(b[j]) == "R" {
					fmt.Println("NO")
					goto out
				}
			}
		}
		fmt.Println("YES")
		out:
	}
}

package main

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(cin, &n)
		var first_row, second_row string
		fmt.Fscan(cin, &first_row, &second_row)
		same := true
		for j := 0; j < n; j++ {
			if first_row[j] != second_row[j] {
				if first_row[j] == 'R' || second_row[j] == 'R' {
					same = false
					break
				}
			}
		}
		if same {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int
	var N int
	var flag bool
	var S string
	var S2 string
	fmt.Scan(&T)
	for T > 0 {
		fmt.Scan(&N)
		fmt.Scan(&S)
		fmt.Scan(&S2)
		flag = true
		for i := 0; i < N; i++ {
			if S[i] != S2[i] && (S[i] == 'R' || S2[i] == 'R') {
				flag = false
				break
			}
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		T--
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	nrTests, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < nrTests; i++ {
		scanner.Scan()
		nrSym, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		line1 := scanner.Text()
		scanner.Scan()
		line2 := scanner.Text()
		same := true
		for j := 0; j < nrSym; j++ {
			if line1[j] != line2[j] {
				if (string(line1[j]) == "G" && string(line2[j]) == "B") || (string(line1[j]) == "B" && string(line2[j]) == "G") {
				} else {
					same = false
					break
				}
			}
		}
		if same {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import "fmt"

func RGB(A, B string, n int) bool {

	ret := true
	for i := 0; i < n; i++ {
		if A[i] == 'R' {
			if B[i] != 'R' {
				ret = false

			}
		}
		if A[i] != 'R' {
			if B[i] == 'R' {
				ret = false
			}
		}
	}

	return ret
}

func main() {

	var tc int

	fmt.Scanln(&tc)
	for t := 1; t <= tc; t++ {
		var n int
		fmt.Scanln(&n)
		var A, B string
		fmt.Scanln(&A)
		fmt.Scanln(&B)

		check := RGB(A, B, n)
		if check == true {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func inArray(x byte, arr []byte) bool {
	for i := range arr {
		if x == arr[i] {
			return true
		}
	}
	return false
}

func equal(x, y byte) bool {
	return (x == 'R' && y == 'R') || (inArray(x, []byte{'G', 'B'}) && inArray(y, []byte{'G', 'B'}))
}

func solve(n int, p, q string) string {
	for i := 0; i < n; i++ {
		if !equal(p[i], q[i]) {
			return "NO"
		}
	}
	return "YES"
}

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

package main

import (
	"fmt"
	"regexp"
	"sort"
)

type runes []rune

func (s runes) Less(i, j int) bool {
	return s[i] < s[j]
}

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

func (s runes) Len() int {
	return len(s)
}

func SortString(s string) string {
	r := []rune(s)
	sort.Sort(runes(r))
	return string(r)
}

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	r := regexp.MustCompile(`([G|B])`)
	for t > 0 {
		t--
		var n int
		var r1, r2 string
		fmt.Scanf("%d\n", &n)
		fmt.Scanf("%s\n %s\n", &r1, &r2)
		r1 = r.ReplaceAllString(r1, "X")
		r2 = r.ReplaceAllString(r2, "X")
		ok := true
		for i := range r1 {
			if r1[i] != r2[i] {
				ok = false
				break
			}
		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// https://codeforces.com/contest/1722/problem/B
// 将第一行字符中的所有'B'全部替换为字符'C'，然后比较两个字符是否一致

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		//fmt.Scanf("%d\n", &n)
		fmt.Scan(&n)
		var str1, str2 string
		//fmt.Scanf("%s\n", &str1)
		fmt.Scan(&str1)
		b1 := []byte(str1)
		//fmt.Scanf("%s\n", &str2)
		fmt.Scan(&str2)
		b2 := []byte(str2)
		for j := 0; j < n; j++ {
			if b1[j] == 'B' {
				b1[j] = 'G'
			}
			if b2[j] == 'B' {
				b2[j] = 'G'
			}
		}
		str1 = string(b1)
		str2 = string(b2)
		//fmt.Println(str)
		//fmt.Println(str2)
		if str2 == str1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
)

func Solve_1722B() {
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n)
		flag := true
		var s1, s2 string
		fmt.Scan(&s1)
		fmt.Scan(&s2)
		ss1 := []byte(s1)
		ss2 := []byte(s2)
		for i, _ := range ss1 {
			if ss1[i] == ss2[i] || ss1[i] == 'G' && ss2[i] == 'B' || ss1[i] == 'B' && ss2[i] == 'G' {
				continue
			}
			flag = false
			break
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func main() {
  Solve_1722B()
}

package main

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

func main() {
	r := readerStdin()
	cases := readInt(r)

	for cases != 0 {
		lenField := readInt(r)
		first, second := readString(r), readString(r)

		for pointer := 0; pointer < lenField; pointer++ {
			if first[pointer] == 'R' && second[pointer] != 'R' || first[pointer] != 'R' && second[pointer] == 'R' {
				fmt.Println("NO")
				goto Next
			}
		}

		fmt.Println("YES")
	Next:
		cases--
	}
}

func readerStdin() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

func readString(r *bufio.Reader) (s string) {
	s, _ = r.ReadString('\n')
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return
}
func readInt(r *bufio.Reader) (i int) {
	str := readString(r)
	i, _ = strconv.Atoi(str)
	return
}

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

func main() {
	defer writer.Flush()
	var t, n uint32
	var colors1, colors2 string

	scanws(&t)

	for ; t > 0; t-- {
		scanws(&n)
		scanws(&colors1)
		scanws(&colors2)
		printf("%s\n", yesNoMap(compColorStrings(colors1, colors2)))
	}
}

func compColorStrings(s1, s2 string) bool {
	for i := range s1 {
		if s1[i] == 'R' && s2[i] != 'R' || s1[i] != 'R' && s2[i] == 'R' {
			return false
		}
	}
	return true
}

func yesNoMap(tf bool) string {
	return map[bool]string{false: "NO", true: "YES"}[tf]
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanws(a ...interface{}) { fmt.Fscan(reader, a...) }

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	res := true
	var rs1, rs2 []rune

	n := make([]int, t)
	s1 := make([]string, t)
	s2 := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n[i])
		fmt.Scan(&s1[i])
		fmt.Scan(&s2[i])
	}
	for i := 0; i < t; i++ {
		rs1 = []rune(s1[i])
		rs2 = []rune(s2[i])
		for j := 0; j < n[i]; j++ {
			if rs1[j] == rs2[j] {
				continue
			} else {
				if rs1[j] == 'G' && rs2[j] == 'B' || rs1[j] == 'B' && rs2[j] == 'G' {
					continue
				} else {
					res = false
				}
			}
		}
		if !res {
			res = true
			fmt.Println("NO")
		} else {
			res = true
			fmt.Println("YES")
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

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

out:
	for i := 0; i < n; i++ {
		var length int
		var str1 string
		var str2 string

		fmt.Scanln(&length)
		fmt.Scanln(&str1)
		fmt.Scanln(&str2)

		for j := 0; j < length; j++ {
			str1 = strings.Replace(str1, "G", "B", -1)
			str2 = strings.Replace(str2, "G", "B", -1)

			if string(str1[j]) != string(str2[j]) {
				fmt.Println("No")
				continue out
			}
		}
		fmt.Println("Yes")

	}

}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for j := 0; j < t; j++ {
		var n int
		fmt.Scan(&n)
		var s1, s2 string
		fmt.Scan(&s1)
		fmt.Scan(&s2)
		//fmt.Printf("%v %v \n",s1,s2)
		flag := 1
		for i := 0; i < n; i++ {
			if s1[i] != s2[i] {
				if (s1[i] == 'B' && s2[i] == 'G') || (s1[i] == 'G' && s2[i] == 'B') {
					continue
				} else {
					flag = 0
					break
				}
			}
		}
		if flag == 1 {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

var (
	in     *bufio.Reader = bufio.NewReader(os.Stdin)
	t, n   int
	s1, s2 string
)

func main() {
	fmt.Fscan(in, &t)
	for t > 0 {
		fmt.Fscan(in, &n, &s1, &s2)
		solve()
		t--
	}
}

func solve() {
	for i := 0; i < n; i++ {
		if s1[i] == s2[i] || s1[i] == 'G' && s2[i] == 'B' || s1[i] == 'B' && s2[i] == 'G' {
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
}

package main

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

type float = float32
type double = float64
type long = int64
type ulong = uint64

type Readable interface {
	bool | int | uint64 | int64 | double | float | byte
}

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

func print(arg ...interface{})            { fmt.Fprint(out, arg...) }
func println(arg ...interface{})          { fmt.Fprintln(out, arg...) }
func printf(f string, arg ...interface{}) { fmt.Fprintf(out, f, arg...) }
func scanf(f string, arg ...interface{})  { fmt.Fscanf(in, f, arg...) }

func readLn() string {
	ln, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}

	return strings.Trim(ln, " \n\r")
}

func readString() string {
	return readLn()
}

func readStrings() []string {
	return strings.Split(readLn(), " ")
}

func read[T Readable](f func(string) (T, error), input ...string) T {
	if len(input) == 0 {
		input = []string{readLn()}
	}

	res, err := f(input[0])
	if err != nil {
		panic(err)
	}

	return res
}

func readMany[T Readable](f func(...string) T) []T {
	input := readStrings()
	arr := make([]T, len(input))
	for i := 0; i < len(arr); i++ {
		arr[i] = f(input[i])
	}

	return arr
}

func readBool(input ...string) bool {
	return read(strconv.ParseBool, input...)
}

func readInt(input ...string) int {
	return read(strconv.Atoi, input...)
}

func readByte(input ...string) byte {
	return byte(read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 8)
	}, input...))
}

func readDouble(input ...string) double {
	return read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 64)
	}, input...)
}

func readFloat(input ...string) float {
	return float32(read(func(s string) (float64, error) {
		return strconv.ParseFloat(s, 32)
	}, input...))
}

func readLong(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 10, 64)
	}, input...)
}

func readULong(input ...string) ulong {
	return read(func(s string) (uint64, error) {
		return strconv.ParseUint(s, 10, 64)
	}, input...)
}

func readBinary(input ...string) long {
	return read(func(s string) (int64, error) {
		return strconv.ParseInt(s, 2, 64)
	}, input...)
}

func readBools() []bool {
	return readMany(readBool)
}

func readInts() []int {
	return readMany(readInt)
}

func readBytes() []byte {
	return readMany(readByte)
}

func readDoubles() []double {
	return readMany(readDouble)
}

func readFloats() []float {
	return readMany(readFloat)
}

func readLongs() []long {
	return readMany(readLong)
}

func readULongs() []ulong {
	return readMany(readULong)
}

func main() {
	defer out.Flush()

	// solution
	t := readInt()
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n := readInt()
		s1 := readString()
		s2 := readString()
		f := true
		for j := 0; j < n; j++ {
			if s1[j] == s2[j] || s1[j] == 'G' && s2[j] == 'B' || s1[j] == 'B' && s2[j] == 'G' {
				continue
			}
			f = false
			break
		}
		if f {
			ans[i] = "YES"
		} else {
			ans[i] = "NO"
		}
	}
	for i := 0; i < t; i++ {
		println(ans[i])
	}
}

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

	return x
}

func max(x, y long) long {
	if x > y {
		return x
	}

	return y
}

func min(x, y long) long {
	if x > y {
		return y
	}

	return x
}

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

		f := true
		for i := range s1 {
			if s1[i] == 'R' && s2[i] != 'R' {
				f = false
				break
			} else if (s1[i] == 'G' || s1[i] == 'B') && s2[i] == 'R' {
				f = false
				break
			}
		}
		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}
}

package main

import "fmt"

func findAns(input1, input2 string, n int) {
	// fmt.Println(input1, "   ", input2)
	for i := 0; i < n; i++ {
		if (input1[i] != input2[i]) || (string(input1[i]) != "G" && string(input2[i]) != "B") && (string(input1[i]) != "B" && string(input2[i]) != "G") {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func main() {
	t, n := 0, 0
	input1, input2 := "", ""
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&input1)
		fmt.Scan(&input2)
		findAns(input1, input2, n)
		t--
	}
}

package main

import "fmt"

func findAns(input1, input2 string, n int) {
	// fmt.Println(input1, "   ", input2)
	for i := 0; i < n; i++ {
		// fmt.Println(string(input1[i]), "   ", string(input2[i]))
		if input1[i] != input2[i] {
			if (string(input1[i]) != "G" && string(input2[i]) != "B") && (string(input1[i]) != "B" && string(input2[i]) != "G") {
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

func main() {
	t, n := 0, 0
	input1, input2 := "", ""
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&input1)
		fmt.Scan(&input2)
		findAns(input1, input2, n)
		t--
	}
}

package main

import "fmt"

func findAns(input1, input2 string, n int) {
	// fmt.Println(input1, "   ", input2)
	for i := 0; i < n; i++ {
		fmt.Println(string(input1[i]), "   ", string(input2[i]))
		if input1[i] != input2[i] {
			if (string(input1[i]) != "G" && string(input2[i]) != "B") && (string(input1[i]) != "B" && string(input2[i]) != "G") {
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

func main() {
	t, n := 0, 0
	input1, input2 := "", ""
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&n)
		fmt.Scan(&input1)
		fmt.Scan(&input2)
		findAns(input1, input2, n)
		t--
	}
}

package main

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

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

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

func main() {

	defer writer.Flush()

	var t int
	scanws(&t)

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

		var n int
		scanws(&n)

		var s1 string
		var s2 string

		scanws(&s1)
		scanws(&s2)

		gb := "GB"

		f := 0

		for j := 0; j < len(s1); j++ {

			fmt.Println(s1[j], s2[j])

			if (s1[j] == gb[0] || s1[j] == gb[1]) && (s2[j] == gb[0] || s2[j] == gb[1]) {

				continue
			} else {
				if (s1[j] != s2[j]) {
					printf("NO\n")
					f = 1
					break
				}
			}

		}

		if f == 0 {
			printf("YES\n")
		}

	}
}