using System;
public class Test {
public static int n, p, q, m;
public static int[] c;
public static int[][] b;
public static int[] a;
public static int[] f;
public static int[][] r;
public static int[][] ans;
public static void Main() {
string[] line;
line = Console.ReadLine().Split(' ');
n = Int32.Parse(line[0]);
p = Int32.Parse(line[1]);
q = Int32.Parse(line[2]);
c = new int[n];
b = new int[n][];
for (int i = 0; i < n; ++i) {
c[i] = Int32.Parse(Console.ReadLine());
b[i] = new int[p];
for (int j = 0; j < p; ++j) {
line = Console.ReadLine().Split(' ');
int cnt = Int32.Parse(line[0]);
for (int k = 0; k < cnt; ++k) {
b[i][j] |= 1 << Int32.Parse(line[k + 1]);
}
}
}
m = Int32.Parse(Console.ReadLine());
a = new int[m];
f = new int[m];
r = new int[m][];
for (int i = 0; i < m; ++i) {
line = Console.ReadLine().Split(' ');
a[i] = Int32.Parse(line[0]);
f[i] = Int32.Parse(line[1]);
r[i] = new int[p];
for (int j = 0; j < p; ++j) {
line = Console.ReadLine().Split(' ');
int cnt = Int32.Parse(line[0]);
for (int k = 0; k < cnt; ++k) {
r[i][j] |= 1 << Int32.Parse(line[k + 1]);
}
}
}
ans = new int[m][];
for (int i = 0; i < m; ++i) {
ans[i] = new int[n];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
bool ok = true;
for (int k = 0; k < p; ++k) {
if ((b[i][k] & r[j][k]) == 0) {
ok = false;
break;
}
}
if (ok) {
int cnt = Math.Min(c[i], a[j]);
if (f[j] != 0) {
cnt = Math.Min(cnt, f[j]);
}
ans[j][i] += cnt;
c[i] -= cnt;
a[j] -= cnt;
}
}
}
for (int i = 0; i < m; ++i) {
if (a[i] != 0) {
for (int j = 0; j < n; ++j) {
ans[i][j] = 0;
}
}
for (int j = 0; j < n; ++j) {
Console.Write(ans[i][j] + " ");
}
Console.Write("\n");
}
}
}