#P7031. Power Station of Art
Power Station of Art
Problem Description
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?
Input
The first line contains an integer $T (1 \le T \le 30000)$ - the number of test cases. Then $T$ test cases follow.
The first line of each test case contains two integers $n, m (1\le n,m \le 10^6)$ - the number of vertices and edges.
Then $m$ lines follow, each line contains two integers $u_i,v_i(1 \leq u_i, v_i \leq n, u_i \not= v_i)$ representing an edge. It is guaranteed that there are no multiple edges in the input, and the graph $\pmb{\text{may}}$ be unconnected.
Then numbers and colors of the two graphs follow. For each graph:
The first line contains $n$ integers, the $i$-th integer $a_i (0 \le a_i \le 10^6)$ representing the number of the $i$-th node of the graph.
The second line contains $n$ characters. If the $i$-th character is `R', the $i$-th node is red. If the $i$-th character is `B', the $i$-th node is black.
It is guaranteed that $\sum n \le 10^6, \sum m \le 10^6$.
Output
For each test case, output "YES" if it is possible to make some (possibly zero) modifications to the art pieces to make them be the same, or "NO" otherwise.
3
2 1
1 2
3 4
RR
4 3
BB
3 2
1 2
2 3
1 1 1
RBR
1 1 1
BBB
3 3
1 2
2 3
3 1
1 1 1
RBR
1 1 1
BBB
YES
NO
YES