#include <cstdio>
int maxx, maxy, x, y;
char dir;
bool lost;
char directions[4] = {'N','E','S','W'};
char path[101];
bool grid[51][51];
void walk()
{
for (int i = 0; i < 4; ++i)
if (directions[i] == dir)
{
dir = i;
break;
}
char * str = path;
while (str[0])
{
/*printf("%d %d %c\n", x, y, directions[dir]);*/
switch (str[0])
{
case 'R':
dir = (dir + 1) % 4;
break;
case 'L':
dir = (dir + 3) % 4;
break;
default:
switch (dir)
{
case 0:
if (y == maxy && grid[x][y])
break;
else if (y == maxy)
{
lost = true;
grid[x][y] = true;
return;
}
++y;
break;
case 1:
if (x == maxx && grid[x][y])
break;
else if (x == maxx)
{
lost = true;
grid[x][y] = true;
return;
}
++x;
break;
case 2:
if (y == 0 && grid[x][y])
break;
else if (y == 0)
{
lost = true;
grid[x][y] = true;
return;
}
--y;
break;
default:
if (x == 0 && grid[x][y])
break;
else if (x == 0)
{
lost = true;
grid[x][y] = true;
return;
}
--x;
}
}
++str;
}
}
int main()
{
// create grid
scanf("%d %d", &maxx, &maxy);
for (int i = 0; i < 51; ++i)
for (int j = 0; j < 51; ++j)
grid[i][j] = false;
while (scanf("%d %d %c", &x, &y, &dir) == 3)
{
scanf("%s", path);
lost = false;
walk();
printf("%d %d %c", x, y, directions[dir]);
if (lost)
printf(" LOST");
printf("\n");
}
return 0;
}