// editor1
#include<stdio.h>
#include<stdlib.h>

int *initVertices(int n){
    return (int*)calloc(n*n, sizeof(int));
}

int main(){
    int V, E, u, v, w;
    scanf("%d%d", &V, &E);
    if(V<0||E<0){
        printf("Invalid input");
        return 0;
    }
    int *graph=initVertices(V);
    for(int i=0;i<E;i++){
        scanf("%d%d%d", &u, &v, &w);
        *(graph+u*V+v)=w;
    }
    for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            printf("%d ", graph[i][j]);
        }
        printf("\n");
    }
    return 0;
}