// Arup Guha
// 5/1/2019
// Solution to 2019 Codejam Round 1B Problem: Manhattan

import java.util.*;

public class Solution {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();

		// Process all cases.
		for (int loop=1; loop<=nC; loop++) {

			int n = stdin.nextInt();
			int len = stdin.nextInt();
			
			// Separate lists into NS and EW.
			ArrayList<event> NSlist = new ArrayList<event>();
			ArrayList<event> EWlist = new ArrayList<event>();
			for (int i=0; i<n; i++) {
				
				// Read stuff.
				int x = stdin.nextInt();
				int y = stdin.nextInt();
				char c = stdin.next().charAt(0);
				
				// Create event and add to appropriate list.
				if (c == 'N')
					NSlist.add(new event(y+1, true));
				if (c == 'S')
					NSlist.add(new event(y, false));
				if (c == 'E')
					EWlist.add(new event(x+1, true));
				if (c == 'W')
					EWlist.add(new event(x, false));
			}
			
			// Sort and solve.
			Collections.sort(NSlist);
			Collections.sort(EWlist);
			int x = solve(EWlist);
			int y = solve(NSlist);
			System.out.println("Case #"+loop+": "+x+" "+y);
		}
	}
	
	// Sweep to find the min value with most items "in" it.
	public static int solve(ArrayList<event> list) {
		
		int cur = 0, max = 0, maxX = 0;
		
		// Sweep through.
		for (int i=0; i<list.size(); i++) {
			
			// Interval is turning on.
			if (list.get(i).on) {
				cur++;
				
				// Update if this is better than anything before.
				if (cur > max) {
					max = cur;
					maxX = list.get(i).x;
				}
			}
			
			// Interval is closing.
			else
				cur--;
		}
		
		// This was our best answer.
		return maxX;
	}
}

class event implements Comparable<event> {
	
	public int x;
	public boolean on;
	
	public event(int item, boolean ison) {
		x = item;
		on = ison;
	}
	
	// Sort by x and we want turn off events to precede turn on events.
	public int compareTo(event other) {
		if (this.x != other.x)
			return this.x - other.x;
		if (this.on && !other.on) return 1;
		if (!this.on && other.on) return -1;
		return 0;
	}
}