#include <iostream>
#include <map>

using namespace std;

int work(){
	int n, l, r, m;
	int money[2];
	int player = 0;
	map<string, int> owners;
	string s;
	bool endgame = false;
	int loser;

	// n: money at the beginning
	// l: land cost
	// r: land rent
	// m: number of moves
	cin >> n >> l >> r >> m >> ws;

	money[0] = n;
	money[1] = n;

	for (int i=0; i<m; ++i){
		getline(cin, s);
		// if the land is not owned
		if (owners.find(s)==owners.end()){
			// if the player have enough money to buy 
			if (money[player]>=l){
				owners[s] = player;
				money[player]-=l;
			}
		} else if (owners[s] != player){ // if the land is owned by the other player, pay rent 
			if (money[player]>=r){
				money[player]-=r;
				money[1-player]+=r;
			} else {
				// someone goes backrupt
				endgame = true;
				loser = player;
				//remove remaininig steps
				for( int j=i+1; j<m; ++j ){
				     getline(cin, s);
				     cout << s << endl;
				}
				break;
			}
		}
		// switch player
		player = 1-player;
	}

	if (endgame){
		cout << "Yes" << endl;
		if (loser == 0)  // Output the name of the player who goes bankrupt
			cout << "Randel" << endl;
		else 
			cout << "Ted" << endl;
				
	} else {
		cout << "No" << endl;
		cout << money[0] << endl;
		cout << money[1] << endl;
	}
	return 0;
}

int main(){
    int n;
    cin >> n;
    for( int i=0; i<n; i++ ){
         work();
    }
}
