#include<bits/stdc++.h>
#include<atcoder/all>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
#define ld long double
using namespace std;
using namespace atcoder;
using ll = long long;
const ll mod = 998244353;
using mint = modint998244353;
using Graph = vector<vector<pair<int,int>>>;
const vector<int> dx = {1,0,-1,0}, dy = {0,1,0,-1};

int main(){
  // input
  int N,K; cin >> N >> K;
  vector<vector<char>> A(N,vector<char>(N));
  for(int i=0;i<N;i++) for(int j=0;j<N;j++) cin >> A[i][j];
  // solve
  int M = N*K;
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cout << A[i/K][j/K];
    }
    cout << endl;
  }
  
  
  // output
  
  
}