Roll a cube to a target position You have your very heavy cubical box on a flat floor at position (0,0). All you can do with it is roll it in four cardinal directions (east, north, west, south). Your task is to bring it to a target position, such that the side facing up is the same as before your manipulations.

Make a program or function which receives target coordinates and returns the minimal sequence of moves which results in the box arriving to target in upright position.

Input: two integers x, y


Get it in any convenient format - as a pair, as a complex number, etc.
You can assume x² + y² ≠ 0


Output: a string of instructions containing characters E, N, W, S


Spaces and newlines are allowed
UPPER-CASE, lower-case and MiXeD-cAsE are allowed


Test cases:

2, 2 =&gt; EENN
2, 3 =&gt; ENENN
1, 0 =&gt; NES
-1, 0 =&gt; NWS
-1, -1 =&gt; ESWNWS
3, 4 =&gt; ENNENEN
-9, 0 =&gt; NWWWWWWWWWS
20, 5 =&gt; EEEEEEEEEEEEEEEEEEENENNNN


Note: the solutions above are not unique, so your code can have slightly different output. But it's required to output a minimal solution.

Invalid test cases:

0, 0 =&gt; not required to handle (the solution is an empty string)
1, 0 =&gt; N (invalid - the box arrives to x=0, y=1)
1, 0 =&gt; E (invalid because the box on its side)
2, 2 =&gt; ENWNESENWNES (invalid because it's not minimal)
JavaScript (ES6),  146 ... 138  125 bytes
Saved 2 bytes thanks to @Klaycon
Takes input as [x,y]. Brute-forces a path.
p=&gt;eval(&quot;for(n=0;s=([X,Y]=p,k=0,++n+'').replace(/./g,n=&gt;n&lt;4&amp;&amp;'ENWS'[X+=~-n%2,Y+=~-~-n%2,k+=(n&amp;2^6)+(k-~n)%3,n]),X|Y|k%6;);s&quot;)

Try it online!
How?
The position of the top face is \$k \bmod 6\$:
$$\begin{array}{c|c|c|c|c|c}
0&amp;1&amp;2&amp;3&amp;4&amp;5\\[5px]
\hline
\text{top}&amp;\text{left}&amp;\text{back}&amp;\text{bottom}&amp;\text{right}&amp;\text{front}
\end{array}$$
The current direction is \$n\$:
$$\begin{array}{c|c|c|c}
0&amp;1&amp;2&amp;3\\[5px]
\hline
\text{East}&amp;\text{North}&amp;\text{West}&amp;\text{South}
\end{array}$$
Given \$k\$ and \$n\$, the new position of the top face is:
$$k'=k+((n\operatorname{and}2)\operatorname{xor}6)+((k+n+1)\bmod3)$$
The values of \$k'\bmod6\$ given \$n\$ and \$k\bmod6\$ are summarized in the following table:
$$\begin{array}{c|cccccc}
k \bmod 6 &amp; 0 &amp; 1 &amp; 2 &amp; 3 &amp; 4 &amp; 5\\
\hline
n = 0 &amp; 1 &amp; 3 &amp; 2 &amp; 4 &amp; 0 &amp; 5\\
n = 1 &amp; 2 &amp; 1 &amp; 3 &amp; 5 &amp; 4 &amp; 0\\
n = 2 &amp; 4 &amp; 0 &amp; 2 &amp; 1 &amp; 3 &amp; 5\\
n = 3 &amp; 5 &amp; 1 &amp; 0 &amp; 2 &amp; 4 &amp; 3
\end{array}$$
Commented
Note: this is a version without eval() for readability
p =&gt; {                   // p = [x, y] = starting position
  for(                   // main loop:
    n = 0;               //   start with n = 0
    s = (                //   s is the move string that we're going to build
      [X, Y] = p,        //     start with [X, Y] = starting position
      k = 0,             //     start with k = 0
      ++n + ''           //     increment n and coerce it to a string
    ).replace(/./g, n =&gt; //   for each digit n in the resulting string:
      n &lt; 4 &amp;&amp;           //     abort if n is greater than or equal to 4
      'ENWS'[            //     replace it with a direction character
        X += ~-n % 2,    //       X += dx
        Y += ~-~-n % 2,  //       Y += dy
        k +=             //       update k
          (n &amp; 2 ^ 6) +  //
          (k - ~n) % 3,  //
        n                //       actual index for the direction character
      ]                  //
    ),                   //   end of replace()
    X | Y | k % 6;       //   stop when X = Y = k mod 6 = 0
  );                     // end of for()
  return s               // return the solution
}                        //