#include<stdio.h>
using namespace std;
struct node{
	int c[812][812];
};
node matA,matB,matC,zero;
int main(){
	int n;
	while( scanf("%d",&n)!=EOF){
		matA=zero,matB=zero,matC=zero;
		int x;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				scanf("%d",&x);
				matA.c[i][j]=x%3;
			}
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				scanf("%d",&x);
				matB.c[i][j]=x%3;
			}
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++){
					int t=matA.c[i][k]*matB.c[k][j];
					t=t%3;
					matC.c[i][j]=(matC.c[i][j]+t)%3;
				}
		for(int i=1;i<=n;i++){
			for(int j=1;j<n;j++)
				printf("%d ",matC.c[i][j]);
			printf("%d\n",matC.c[i][n]);
		}
	}
	return 0;
}
