{$O-,Q+,R+}
uses SysUtils;

const MaxN = 2000;
      MaxK = 1000000000000000000;
      MaxC = 1000000000000000;
      dx : array [0..3] of integer = (0, 1, 0, -1);
      dy : array [0..3] of integer = (1, 0, -1, 0);

procedure Res (x, y : int64; dx, dy : integer);
begin
  if odd (x + y) then begin inc (x, dx); inc (y, dy) end;
  writeln (x, ' ', y);
  halt;
end;

function getevens (x, y1, y2 : int64) : int64;
begin
  if odd (x) then begin
    if not odd (y1) then inc (y1);
    if not odd (y2) then dec (y2);
  end else begin
    if odd (y1) then inc (y1);
    if odd (y2) then dec (y2);
  end;
  Result := (y2 - y1) div 2 + 1;
end;


function geteven (x, y1, y2, k : int64; dy : integer) : int64;
begin
  if odd (x) then begin
    if not odd (y1) then inc (y1);
    if not odd (y2) then dec (y2);
  end else begin
    if odd (y1) then inc (y1);
    if odd (y2) then dec (y2);
  end;
  if dy > 0 then Result := y1 + k * 2 else Result := y2 - k * 2;
end;

type carr = array [0..MaxN * 3 + 1] of int64;


procedure sortkill (var a : carr; var ac : integer);
var i, j, p : integer;
    t : int64;
begin
  for i := 1 to ac do
    for j := i + 1 to ac do
      if a[j] < a[i] then begin t := a[j]; a[j] := a[i]; a[i] := t end;
  p := 1;
  for i := 2 to ac do 
    if a[i] <> a[p] then begin
      inc (p); a[p] := a[i];
    end;
  ac := p;
  a[0] := -maxint;
  a[ac + 1] := maxint;
end;

function find (var a : carr; ac : integer; k : int64) : integer;
var l, r, x : integer;
begin
  l := 0; r := ac + 1;
  while r - l > 1 do begin
    x := (l + r) shr 1;
    if k < a[x] then r := x else l := x;
  end;
  assert (k = a[l]);
  Result := l;
end;

var xc, yc : integer;
    xs, ys : carr;

procedure addx (x : int64);
begin
  inc (xc); xs[xc] := x;
end;


procedure addy (y : int64);
begin
  inc (yc); ys[yc] := y;
end;

procedure addxs (x : int64; k : integer);
begin
  while k > 0 do begin
    addx (x); inc (x); dec (k)
  end;
end;


procedure addys (y : int64; k : integer);
begin
  while k > 0 do begin
    addy (y); inc (y); dec (k)
  end;
end;


var xr, yr, l : array [1..MaxN] of int64;
    d : array [1..MaxN] of integer;
    c1, c2 : char;
    b : array [1..3*MaxN, 1..3*MaxN] of boolean;
    sx, sy, ex, ey, dr, qx, qy, n, i, j, x, y : integer;
    k : int64;
       


begin
  reset (input, 'internet.in');
  rewrite (output, 'internet.out');
  read (n, k);
  assert ((n >= 1) and (n <= MaxN) and (k >= 1) and (k <= MaxK));
  for i := 1 to n do begin
    read (xr[i], yr[i], c1, c2, l[i]); assert (c1 = ' ');
    assert ((abs (xr[i]) <= MaxC) and (abs (yr[i]) <= MaxC) and (abs (l[i]) <= MaxC));
    case c2 of
      'N' : begin d[i] := 0; addxs (xr[i] - 1, 3); addys (yr[i], 1); addys (yr[i] + l[i], 1) end;
      'E' : begin d[i] := 1; addxs (xr[i], 1); addxs (xr[i] + l[i], 1); addys (yr[i] - 1, 3) end;
      'S' : begin d[i] := 2; addxs (xr[i] - 1, 3); addys (yr[i], 1); addys (yr[i] - l[i], 1) end;
      'W' : begin d[i] := 3; addxs (xr[i], 1); addxs (xr[i] - l[i], 1); addys (yr[i] - 1, 3) end;
      else assert (false);
    end;
  end;
  assert (seekeof);
  sortkill (xs, xc);
  sortkill (ys, yc);
  k := k - 1;
  for i := 1 to n do
    case d[i] of
      0, 2: begin
        x := find (xs, xc, xr[i]);
        if d[i] = 0 then begin
          sy := find (ys, yc, yr[i]);
          ey := find (ys, yc, yr[i] + l[i]);
          qy := 1;
          dr := 0;
        end else begin
          sy := find (ys, yc, yr[i]) - 1;
          ey := find (ys, yc, yr[i] - l[i]) - 1;
          qy := -1;
          dr := 1;
        end;
        j := sy;
        while j <> ey do begin
          if not b[x-1][j] and not b[x][j] then begin
            if k < ys[j + 1] - ys[j] then Res (xs[x], ys[j + dr] + k * qy - dr, -1, 0);
            dec (k, ys[j + 1] - ys[j]);
          end else
          if not b[x-1][j] then begin
            if k < getevens (xs[x-1], ys[j], ys[j + 1] - 1) then
              Res (xs[x - 1], geteven (xs[x-1], ys[j], ys[j + 1] - 1, k, qy), 0, 0);
            dec (k, getevens (xs[x-1], ys[j], ys[j + 1] - 1));
          end else
          if not b[x][j] then begin
            if k < getevens (xs[x], ys[j], ys[j + 1] - 1) then
              Res (xs[x], geteven (xs[x], ys[j], ys[j + 1] - 1, k, qy), 0, 0);
            dec (k, getevens (xs[x], ys[j], ys[j + 1] - 1));
          end;
          b[x-1][j] := true;
          b[x][j] := true;
          inc (j, qy);
        end;
      end;
      1, 3: begin
        if d[i] = 1 then begin 
          sx := find (xs, xc, xr[i]);
          ex := find (xs, xc, xr[i] + l[i]);
          qx := 1;
          dr := 0;
        end else begin
          sx := find (xs, xc, xr[i]) - 1;
          ex := find (xs, xc, xr[i] - l[i]) - 1;
          qx := -1;
          dr := 1;
        end;
        y := find (ys, yc, yr[i]);
        j := sx;
        while j <> ex do begin
          if not b[j][y - 1] and not b[j][y] then begin
            if k < xs[j + 1] - xs[j] then Res (xs[j + dr] + k * qx - dr, ys[y], 0, -1);
            dec (k, xs[j + 1] - xs[j]);
          end else
          if not b[j][y - 1] then begin
            if k < getevens (ys[y - 1], xs[j], xs[j + 1] - 1) then
              Res (geteven (ys[y - 1], xs[j], xs[j + 1] - 1, k, qx), ys[y - 1], 0, 0);
            dec (k, getevens (ys[y - 1], xs[j], xs[j + 1] - 1));
          end else
          if not b[j][y] then begin
            if k < getevens (ys[y], xs[j], xs[j + 1] - 1) then
              Res (geteven (ys[y], xs[j], xs[j + 1] - 1, k, qx), ys[y], 0, 0);
            dec (k, getevens (ys[y], xs[j], xs[j + 1] - 1));
          end;
          b[j][y-1] := true;
          b[j][y] := true;
          inc (j, qx);
        end;
      end;
    end;
  assert (false);
end.