#include <iostream>
using namespace std;
int main() {
// Умножение матриц
int na, ma, nb, mb;
cin >> na >> ma;
int **a = new int *[na];
for (int i = 0; i < na; i++) {
a[i] = new int[ma];
}
for (int i = 0; i < na; i++) {
for (int j = 0; j < ma; j++) {
cin >> a[i][j];
}
}
cin >> nb >> mb;
// Проверяем возможность вычисления произведения матриц
if (ma != nb) {
cout << -1;
return 0;
}
int **b = new int *[nb];
for (int i = 0; i < nb; i++) {
b[i] = new int[mb];
}
for (int i = 0; i < nb; i++) {
for (int j = 0; j < mb; j++) {
cin >> b[i][j];
}
}
int **c = new int *[na];
for (int i = 0; i < na; i++) {
c[i] = new int[mb];
}
// Вычисляем произведение
for (int i = 0; i < na; i++) {
for (int j = 0; j < mb; j++) {
for (int r = 0; r < ma; r++) {
c[i][j] += a[i][r] * b[r][j];
}
}
}
// Выводим результат
cout << na << " " << mb << "\n";
for (int i = 0; i < na; i++) {
for (int j = 0; j < mb; j++) {
cout << c[i][j];
if (j + 1 != mb) cout << " ";
}
cout << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CgkvLyDQo9C80L3QvtC20LXQvdC40LUg0LzQsNGC0YDQuNGGCglpbnQgbmEsIG1hLCBuYiwgbWI7CgljaW4gPj4gbmEgPj4gbWE7CglpbnQgKiphID0gbmV3IGludCAqW25hXTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbmE7IGkrKykgewoJCWFbaV0gPSBuZXcgaW50W21hXTsKCX0KCWZvciAoaW50IGkgPSAwOyBpIDwgbmE7IGkrKykgewoJCWZvciAoaW50IGogPSAwOyBqIDwgbWE7IGorKykgewoJCQljaW4gPj4gYVtpXVtqXTsKCQl9Cgl9CgljaW4gPj4gbmIgPj4gbWI7CgkvLyDQn9GA0L7QstC10YDRj9C10Lwg0LLQvtC30LzQvtC20L3QvtGB0YLRjCDQstGL0YfQuNGB0LvQtdC90LjRjyDQv9GA0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