Power Station of Art
시간 제한3초메모리 제한512 MB
하나의 무방향 그래프와 두 개의 숫자·색 배치가 주어질 때, 간선 양 끝의 숫자를 바꾸고 같은 색이면 두 색을 뒤집는 연산으로 두 배치를 같게 만들 수 있는지 판정한다.
문제
As a modern art lover, Nocriz loves going to the Power Station of Art.
Currently, art pieces of a modern genre of art called "red-black graphs" are exhibited in the Power Station of Art. Every red-black graph art piece is an undirected labeled graph with numbers and colors associated with each vertex. Each vertex is either red or black.
It is possible to modify a graph in the following way: choose an edge and swap the numbers written on the corresponding vertices. In addition, if the colors of the two vertices are the same, the colors of both vertices are changed (from red to black or from black to red). Otherwise, the colors of the two vertices remain unchanged.
Now, Nocriz is studying two art pieces. The graphs are the same but the numbers and colors may be different. Is it possible to make some (possibly zero) modifications to the art pieces to make them be the same?
입력
The first line contains an integer (), the number of test cases. Then test cases follow.
The first line of each test case contains two integers and (, ), the number of vertices and edges.
Then lines follow, each of them contains two integers and (, ) representing an edge. It is guaranteed that there are no multiple edges in the input, and the graph may be unconnected.
Then numbers and colors of the two graphs follow. For each graph:
The first line contains integers, the -th integer () representing the number written on the -th vertex of the graph.
The second line contains characters. If the -th character is 'R', the -th vertex is red. If the -th character is 'B', the -th vertex is black.
It is guaranteed that and .
출력
For each test case, output a single line containing "YES" if it is possible to make some (possibly zero) modifications to the art pieces to make them be the same, or "NO" otherwise.