// Arup Guha
// 12/10/2019
// Solution to 2019 UCF HS Online D2 Problem: Calculator Game

import java.util.*;

public class calc {
	
	public static int start;
	public static int end;
	public static int dist;
	public static rule[] rules;
	
	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=1; loop<=nC; loop++) {
		
			// Get basic parameters.
			start = stdin.nextInt();
			end = stdin.nextInt();
			dist = stdin.nextInt();
			int numButtons = stdin.nextInt();
		
			// Read rules.
			rules = new rule[numButtons];
			for (int i=0; i<numButtons; i++) {
				
				// Read in each parameter for the button, y=-1 means no y.
				char c = stdin.next().charAt(0);
				int x = stdin.nextInt();
				int y = -1;
				y = (c == 'T') ? stdin.nextInt() : -1;
				
				// Make the rule.
				rules[i] = new rule(c, x, y);
			}
			
			// Run it!
			boolean res = bfs();
		
			if (res)
				System.out.println("Level #"+loop+": It can be done");
			else
				System.out.println("Level #"+loop+": You should give up");
		
		}
	}
	
	// Runs the bfs.
	public static boolean bfs() {
		
		HashSet<Integer> cur = new HashSet<Integer>();
		cur.add(start);
		
		// Just do in rounds.
		for (int level=0; level<dist; level++) {
			
			// Store where we can go in one more move here.
			HashSet<Integer> next = new HashSet<Integer>();
			
			// Go from everything in our current set.
			for (Integer x: cur) {
				
				// Try each rule with this number,
				for (int i=0; i<rules.length; i++) {
					Integer tmp = rules[i].getNext(x);
					if (tmp != null) next.add(tmp);
				}
			}
			
			// Just reassign cur to be this next level.
			cur = next;
		}
		
		// Ta da!
		return cur.contains(end);
	}
}

class rule {

	public char op;
	public int x;
	public int y;
	
	public rule(char myop, int myx, int myy) {
		op = myop;
		x = myx;
		y = myy;
	}
	
	// So we only do the calculator display.
	public static boolean inBounds(long val) {
		return val >= -99999999 && val <= 99999999;
	}
	
	public Integer getNext(int val) {
	
		// Add
		if (op == 'A') {
			int ret = val + x;
			if (inBounds(ret)) return ret;
			else return null;
		}
		
		// Subtract
		if (op == 'S') {
			int ret = val - x;
			if (inBounds(ret)) return ret;
			else return null;		
		}
		
		// Multiply
		if (op == 'M') {
			long ret = ((long)val)*x;
			if (inBounds(ret)) return (int)ret;
			else return null;		
		}	

		// Divide, can't go out of bounds if valid.
		if (op == 'D') {
			if (val%x == 0) return val/x;
			return null;
		}		
		
		// Append.
		if (op == 'P') {
			int ret = 10*val + x;
			if (inBounds(ret)) return ret;
			return null;
		}
		
		// This will always be valid since # of digits is preserved.
		return swap(val,x,y);
	}
	
	// Let's cheat and use String's replace All =)
	public static int swap(int n, int x, int y) {
		String s = ""+n;
		s = s.replaceAll(""+(char)(x+'0'), ""+(char)(y+'0'));
		return Integer.parseInt(s);
	}
}