#include <stdio.h>

main() {
int t;
scanf("%d", &t);

while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);

    int l[n][m], u[n][m], a[n][m];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &l[i][j]);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            scanf("%d", &u[i][j]);
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            a[i][j] = l[i][j] - u[i][j];
        }
    }

    int resenje = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (a[i][j] < 0) {
                resenje = 0;
                break;
            }
        }
    }

    if (resenje) {
        printf("DA\n");
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                printf("%d ", a[i][j]);
            }
            printf("\n");
        }
    } else {
        printf("NE\n");
    }
}


}