#include <iostream>
using namespace std;
int main()
{
int m;
cin>>m;
int A[m][m], B[m][m], C[m][m], D[m][m];
int X[m][m], Y[m][m];
int el;
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
cin>>A[i][j];
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
cin>>B[i][j];
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
cin>>C[i][j];
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
cin>>D[i][j];
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
el=0;
for(int l=0;l<m;l++)
{
el=el+A[i][l]*C[l][j]-B[i][l]*D[l][j];
}
X[i][j]=el;
}
}
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
el=0;
for(int l=0;l<m;l++)
{
el=el+A[i][l]*D[l][j]+B[i][l]*C[l][j];
}
Y[i][j]=el;
}
}
cout<<"X:"<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
cout<<X[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
cout<<"Y:"<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
cout<<Y[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKQoJewoJCWludCBtOwoJCWNpbj4+bTsKCQlpbnQgQVttXVttXSwgQlttXVttXSwgQ1ttXVttXSwgRFttXVttXTsKCQlpbnQgWFttXVttXSwgWVttXVttXTsKCQlpbnQgZWw7CgkJZm9yKGludCBpPTA7aTxtO2krKykKCQkJZm9yKGludCBqPTA7ajxtO2orKykKCQkJCWNpbj4+QVtpXVtqXTsKCQlmb3IoaW50IGk9MDtpPG07aSsrKQoJCQlmb3IoaW50IGo9MDtqPG07aisrKQoJCQkJY2luPj5CW2ldW2pdOwoJCWZvcihpbnQgaT0wO2k8bTtpKyspCgkJCWZvcihpbnQgaj0wO2o8bTtqKyspCg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