Permutation across matrices. Matrices may be used to permute the order of elements in a set. For example:
$$
    \begin{bmatrix}
        0 & 0 & 0 & 1 \\
        1 & 0 & 0 & 0 \\
        0 & 1 & 0 & 0 \\
        0 & 0 & 1 & 0
    \end{bmatrix}
    \times
    \begin{bmatrix}
        x \\
        y \\
        z \\
        w
    \end{bmatrix}
    =
    \begin{bmatrix}
        w \\
        x \\
        y \\
        z
    \end{bmatrix}
$$
My problem is that I need to permute values in different matrices:
$$
    A = \begin{bmatrix}
        0 & 0 & x & 0 & 0 \\
        x & x & x & x & x \\
        x & 0 & 0 & 0 & x \\
        0 & 0 & 0 & 0 & 0
    \end{bmatrix}
$$
$$
    B = \begin{bmatrix}
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & y & 0 & 0 \\
        y & y & y & y & y \\
        y & 0 & 0 & 0 & y
    \end{bmatrix}    
$$
$$
    C = \begin{bmatrix}
        z & 0 & 0 & 0 & z \\
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & z & 0 & 0 \\
        z & z & z & z & z
    \end{bmatrix}    
$$
$$
    D = \begin{bmatrix}
        w & w & w & w & w \\
        w & 0 & 0 & 0 & w \\
        0 & 0 & 0 & 0 & 0 \\
        0 & 0 & w & 0 & 0
    \end{bmatrix}    
$$
Thus given the permutation matrix (from above) and the following pattern matrix how would you change all the $x$ in $A$ to $w$, all the $y$ in $B$ to $x$, all the $z$ in $C$ to $y$, and all the $w$ in $D$ to $z$:
$$
    \begin{bmatrix}
        0 & 0 & 1 & 0 & 0 \\
        1 & 1 & 1 & 1 & 1 \\
        1 & 0 & 0 & 0 & 1 \\
        0 & 0 & 0 & 0 & 0
    \end{bmatrix}
$$

There's a pretty good chance I don't know what you're asking, but maybe the matrix you're looking for is $$M=\pmatrix{0&1&0&0\cr0&0&1&0\cr0&0&0&1\cr1&0&0&0\cr}$$ You get $$MA=\pmatrix{0&1&0&0\cr0&0&1&0\cr0&0&0&1\cr1&0&0&0\cr}\pmatrix{0&0&x&0&0\cr x&x&x&x&x\cr x&0&0&0&x\cr0&0&0&0&0\cr}=\pmatrix{x&x&x&x&x\cr x&0&0&0&x\cr0&0&0&0&0\cr0&0&x&0&0\cr}$$ which is exactly the pattern of $D$, but with $x$ instead of $w$, and you get similar things for $MB,MC,MD$.  
