def Matprod(A, B, N): temp = [0] * N*N for i in range(N): for j in range(N): ij = i * N + j for k in range(N): temp[ij] += A[i*N+k] * B[k*N+j] return temp def Matpow_Linear(A, M, N): Mat = [0] * N*N for i in range(N): Mat[i*N+i] = 1 while M: if M & 1: Mat = Matprod(Mat, A, N) A = Matprod(A, A, N) M >>= 1 return Mat M = [] for i in range(2): M.extend(list(map(int, input().split()))) M = Matpow_Linear(M, 3, 2) for i in range(2): print(*M[2*i:2*i+2])