Reorder a matrix, twice You are given a square \$n \times n\$ matrix \$A\$, and a list (or vector) \$u\$ of length \$n\$ containing the numbers \$1\$ through \$n\$ (or \$0\$ through \$n-1\$). Your task is to reorder the columns and rows of the matrix \$A\$ according to the order specified in \$u\$. 

That is, you will construct  a matrix \$B\$ where the \$(i,j)\$-th element is the \$(u(i),u(j))\$-th element of \$A\$. You should also output the inverse of this action; that is, the (i,j)-th element of \$A\$ will end up at position \$(u(i),u(j))\$ in a new matrix \$C\$.

For example, given $$A = \begin{bmatrix} 11 &amp;12&amp; 13 \\ 21&amp; 22&amp; 23 \\ 31&amp; 32&amp; 33 \end{bmatrix},\quad u=\begin{bmatrix}3 &amp; 1 &amp; 2\end{bmatrix}$$

the output should be $$B = \begin{bmatrix}33 &amp; 31 &amp; 32 \\ 13 &amp; 11 &amp; 12 \\ 23 &amp; 21 &amp; 22 \end{bmatrix},\quad C= \begin{bmatrix}22 &amp; 23 &amp; 21 \\32 &amp; 33 &amp; 31 \\ 12 &amp; 13 &amp; 11 \end{bmatrix}$$

You may take input and output through any of the default I/O methods. You do not have to specify which matrix is \$B\$ or \$C\$, as long as you output both. You may assume \$A\$ only contains positive integers, and you may use 1- or 0-based indexing for \$u\$. You must support matrices up to at least size \$64 \times 64\$.

Example

===== Input =====
A =
 35     1     6    26    19    24
  3    32     7    21    23    25
 31     9     2    22    27    20
  8    28    33    17    10    15
 30     5    34    12    14    16
  4    36    29    13    18    11
u=
  3 5 6 1 4 2

==== Output =====
B = 
  2    27    20    31    22     9
 34    14    16    30    12     5
 29    18    11     4    13    36
  6    19    24    35    26     1
 33    10    15     8    17    28
  7    23    25     3    21    32
C = 
 17    15     8    10    28    33
 13    11     4    18    36    29
 26    24    35    19     1     6
 12    16    30    14     5    34
 21    25     3    23    32     7
 22    20    31    27     9     2
MATL, 15 13 bytes

t3$)&amp;Gw&amp;St3$)


Inputs u,  then A.

Outputs B, then C without a separator, as there is no ambiguity.

Try it online!

Explanation

t     % Take input u implicitly. Duplicate u
3$)   % Take input A implicitly. Index A with u as row and column indices
&amp;G    % Push the two inputs again: u, A
w     % Swap
&amp;S    % Push indices that would make u sorted. Call that v
t     % Duplicate v
3$)   % Index A with v as row as column indices. Display implcitly