#include ""
long long a[30][30];
long long f[10010][30];
int main(){
int n,d;
int Q[10010][30],K[10010][30],V[10010][30];
int W[10010];
scanf("%d %d",&n,&d);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < d; ++j) {
scanf("%d",&Q[i][j]);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < d; ++j) {
scanf("%d",&K[i][j]);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < d; ++j) {
scanf("%d",&V[i][j]);
}
}
for (int i = 0; i < n; ++i) {
scanf("%d",&W[i]);
}
for (int i = 0; i < d; ++i) {
for (int j = 0; j < d; ++j) {
for (int k = 0; k < n; ++k) {
a[i][j]+=(K[k][i]*V[k][j]);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < d; ++j) {
for (int k = 0; k < d; ++k) {
f[i][j]+=(a[k][j]*Q[i][k]);
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < d; ++j) {
f[i][j]*=(long long)W[i];
}
}
for (int i = 0; i < n; ++i) {
printf("%lld",f[i][0]);
for (int j = 1; j < d; ++j) {
printf(" %lld",f[i][j]);
}
printf("\n");
}
return 0;
}