java
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N = 10010, D = 30;
long[][] tmp = new long[D][D]; // 用于存储 K 的转置 * V 的结果
long[][] ans = new long[N][D]; // 存储最终结果
int n, d; // n 表示矩阵的行数,d 表示矩阵的列数
int[][] Q = new int[N][D]; // 输入矩阵 Q
int[][] K = new int[N][D]; // 输入矩阵 K
int[][] V = new int[N][D]; // 输入矩阵 V
int[] W = new int[N]; // 输入数组 W
n = input.nextInt(); // 输入矩阵行数
d = input.nextInt(); // 输入矩阵列数
// 输入矩阵 Q
for (int i = 1; i <= n; i++)
for (int j = 1; j <= d; j++)
Q[i][j] = input.nextInt();
// 输入矩阵 K
for (int i = 1; i <= n; i++)
for (int j = 1; j <= d; j++)
K[i][j] = input.nextInt();
// 输入矩阵 V
for (int i = 1; i <= n; i++)
for (int j = 1; j <= d; j++)
V[i][j] = input.nextInt();
// 输入数组 W
for (int i = 1; i <= n; i++)
W[i] = input.nextInt();
// 计算 K 的转置 * V = tmp
for (int i = 1; i <= d; i++)
for (int j = 1; j <= d; j++)
for (int k = 1; k <= n; k++)
tmp[i][j] += (long) K[k][i] * V[k][j];
// 计算 Q * tmp = ans
for (int i = 1; i <= n; i++)
for (int j = 1; j <= d; j++) {
for (int k = 1; k <= d; k++)
ans[i][j] += (long) Q[i][k] * tmp[k][j];
ans[i][j] *= (long) W[i];
}
// 输出结果
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= d; j++)
System.out.print(ans[i][j] + " ");
System.out.println();
}
}
}