Bottle Arrangements
시간 제한2초메모리 제한2048 MB
길이 n의 R/W 문자열에서 각 비평가 i마다 길이 r_i+w_i인 어떤 연속 구간에 빨간 병이 정확히 r_i개 있도록 배열을 만들거나, 불가능하면 IMPOSSIBLE을 출력한다.
문제
Gabriella has been instructed to organize a renowned wine tasting event which will be attended by critics. On display, there will be different varieties of wine, each of which can either be a red wine or a white wine.
The wines will come in bottles arranged in a line on the table, and, for convenience, each critic will sip from a contiguous interval of bottles: that is, he/she will taste exactly the bottles at position , , , for some . The interval depends on the critic, who will select it on the spot according to their preferences. In fact, the -th critic () has requested that he/she wants to taste exactly red wines and white wines.
Gabriella has yet to choose how many bottles of red wine and white wine there will be, and in what order they will appear. Help her find an arrangement (that is, a sequence of bottles of either red or white wine) that satisfies the requests of all the critics, or state that no such arrangement exists.
입력
Each test contains multiple test cases. The first line contains an integer () — the number of test cases. The descriptions of the test cases follow.
The first line of each test case contains two integers and (, ) — the number of bottles of wine and the number of critics.
Each of the next lines contains two integers and (, ) — the number of red and white wines that the -th critic wants to taste.
출력
For each test case, if at least one solution exists, print a string of length made up of the characters R and W, where the -th character () denotes the type of the wine in the -th bottle of the arrangement (R for red and W for white).
If there are multiple solutions, print any. If no solution exists, print the string IMPOSSIBLE.