#graph502. One-Way Streets

One-Way Streets

One-Way Streets

Problem Source

CEOI 2017

Problem Description

You are given an undirected graph with nn vertices and mm edges. You want to assign a direction to every edge, turning the graph into a directed one.

There are pp constraints; the ii-th constraint is a pair (xi,yi)(x_i, y_i), meaning that in the resulting directed graph, xix_i must be able to reach yiy_i by following some directed edges.

Determine, for each edge, whether its direction is forced (uniquely determined), and if so, report that direction. A solution is guaranteed to exist.

Input Format

The first line contains two space-separated positive integers nn and mm.

The next mm lines each contain two space-separated positive integers ai,bia_i, b_i, indicating an edge between aia_i and bib_i.

The next line contains one integer pp, the number of constraints.

The next pp lines each contain two space-separated positive integers xi,yix_i, y_i, describing a constraint (xi,yi)(x_i, y_i).

For all test cases, 1≤n,m,p≤100 0001 \le n, m, p \le 100\,000, and 1≤ai,bi,xi,yi≤n1 \le a_i, b_i, x_i, y_i \le n.

Output Format

Output a single line containing a string of length mm, the answer for each edge:

  • If the ii-th edge must be directed from aia_i to bib_i, the ii-th character should be R;
  • If the ii-th edge must be directed from bib_i to aia_i, the ii-th character should be L;
  • Otherwise, if the ii-th edge's direction cannot be uniquely determined, the ii-th character should be B.

Sample Input

5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3

Sample Output

BBRBBL