#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int** array_init(const int&, const int&);
void change_orientation(char&, const char&);
bool go_forward(int **, const int&, const int&, int&, int&, char&, bool&);
void show_coordinate(int&, int&, char&, bool&);

int main()
{
	int range_x, range_y;	//	upper-right coordinates of the rectangular world
	int x, y;				//	initial coordinate of robot 
	char o;					//	initail orientation of robot
	string instr;			//	instruction
	int **scent = 0;		//	robot drop coordinates

	cin >> range_x >> range_y;
	scent = array_init(range_x, range_y);

	while( cin >> x >> y >> o >> instr )
	{
		bool isdrop = false;
		for(string::size_type i = 0; i != instr.size(); ++i)
		{
			if( instr[i] == 'F' )
			{
				if( go_forward(scent, range_x, range_y, x, y, o, isdrop) == false )
					break;
			}
			else
				change_orientation(o, instr[i]);
		}
		show_coordinate(x, y, o, isdrop);
	}
}

int** array_init(const int &x, const int &y)
{
	int **a = new int*[x];
	for(int i = 0; i <= x; ++i)
		a[i] = new int[y];
	
	for(int i = 0; i <= x; ++i)
		for(int j = 0; j <= y; ++j)
			a[i][j] = 0;
	return a;
}
void change_orientation(char &o, const char &instr)
{
	char orientation[4] = {'N', 'E', 'S', 'W'};

	for(int i = 0; i != 4; ++i)
	{
		if( orientation[i] == o)
		{
			if( instr == 'R' )
				o = orientation[ (i+1)%4 ];
			else
				o = orientation[ (i+3)%4 ];
			break;
		}
	}
}
bool go_forward(int **a, const int &range_x, const int &range_y, int &x, int &y, char &o, bool &isdrop)
{
	switch(o)
	{
	case 'N':		
		if( y+1 > range_y )		//	超出範圍?
		{	
			if( a[x][y] == 0 )	//	標記?
			{
				a[x][y] = 1;
				isdrop = true;
				return false;
			}			
			else				//	有標記 -> nop
				return true;
		}
		else
		{
			y++;
			return true;
		}
	case 'E':
		if( x+1 > range_x )
		{
			if( a[x][y] == 0 )
			{
				a[x][y] = 1;
				isdrop = true;
				return false;
			}
			else
				return true;
		}
		else
		{
			x++;
			return true;
		}
	case 'S':
		if( y-1 < 0 )
		{
			if( a[x][y] == 0 )
			{
				a[x][y] = 1;
				isdrop = true;
				return false;
			}
			else
				return true;
		}
		else
		{
			y--;
			return true;
		}
	case 'W':
		if( x-1 < 0 )
		{
			if( a[x][y] == 0 )
			{
				a[x][y] = 1;
				isdrop = true;
				return false;
			}
			else
				return true;
		}
		else
		{
			x--;
			return true;
		}
	default:
		return false;
	}	
}
void show_coordinate(int &x, int &y, char &o, bool &isdrop)
{
	cout << x << ' ' << y << ' ' << o;
	if( isdrop )
		cout << " LOST";
	cout << endl;
}