import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* @file: 扑克游戏
* @author: Ash
* @date: 2019/9/1 15:15
* @description:
* 3
* 123
* 3
* 123
* 321
* 45
* 67
*
* {
* d d l
* d d r
* }
* {
* l l l
* r l l
* }
* {
* }
* @since:
*/
public class 扑克游戏 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int s = Integer.parseInt(in.nextLine());
for (int i = 0; i < s; i++) {
String str1 = in.nextLine();
String str2 = in.nextLine();
int n = str1.length();
System.out.println("{");
List<String> res = new ArrayList<>();
dfs("", str2, str1, 0, n, "", res);
for (String st : res) {
System.out.println(st.trim());
}
System.out.println("}");
}
}
in.close();
}
private static void dfs(String cmd, String goal, String ori, int depth, int n, String s, List<String> res) {
if (depth == n && !goal.equals(s) || depth > n || s.length() > goal.length()) {
return;
}
if (depth == n && goal.equals(s)) {
res.add(cmd);
} else {
// d
dfs(cmd + " " + "d", goal, ori, depth + 1, n, s, res);
// l
dfs(cmd + " " + "l", goal, ori, depth + 1, n, ori.charAt(depth) + s, res);
// r
dfs(cmd + " " + "r", goal, ori, depth + 1, n, s + ori.charAt(depth), res);
}
}
}