
/*
  Copyright 2011 Marek "p2004a" Rusinowski
  Matrix multiplication (class matrix)
*/
#include <cstdio>
#include <cstring>
#include <cassert>

class Matrix {
 private:
  static const int cmod = 1000000007;
  int n_;
  int *t_;
  
 public:
  Matrix(int n) : n_(n), t_(new int [n_ * n_]) {}
  
  Matrix(int n, const int *t) : n_(n), t_(new int [n_ * n_]) {
    memcpy(t_, t, sizeof(int) * n_ * n_);
  }
  
  Matrix(const Matrix &obj) : n_(obj.n_), t_(new int [n_ * n_]) {
    memcpy(t_, obj.t_, sizeof(int) * n_ * n_);
  }
  
  ~Matrix() {
    delete t_;
  }
  
  Matrix &operator=(const Matrix &obj) {
    if (&obj == this) {
      return *this;
    }
    if (obj.n_ != n_) {
      delete t_;
      n_ = obj.n_;
      t_ = new int [n_ * n_];
    }
    memcpy(t_, obj.t_, sizeof(int) * n_ * n_);
    return *this;
  }
  
  const Matrix operator*(const Matrix &obj) {
    assert(obj.n_ == n_);
    Matrix res(n_);
    for (int i = 0; i < n_; ++i) {
      for (int k = 0; k < n_; ++k) {
        for (int j = 0; j < n_; ++j) {
          *(res.t_ + n_ * i + j) += *(t_ + n_ * i + k) * *(obj.t_ + n_ * k + j) % cmod;
          *(res.t_ + n_ * i + j) %= cmod;
        }
      }
    }
    return res;
  }
  
  Matrix &operator*=(const Matrix &obj) {
    (*this) = (*this) * obj;
    return *this;
  }
  
  const int *operator[](int i) {
    return t_ + n_ * i;
  }
};

void read_matrix(int n, int *t) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", t + n * i + j);
    }
  }
}

int main() {
  int n;
  scanf("%d", &n);
  int *a = new int [n * n], *b = new int [n * n];
  read_matrix(n, a);
  read_matrix(n, b);
  Matrix A(n, a), B(n, b);
  A *= B;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      printf("%3d ", A[i][j]);
    }
    printf("\n");
  }
  delete a;
  delete b;
  return 0;
}
