import java.util.Scanner;
import java.io.PrintWriter;
class Solve {
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 boolean[] used;
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
n = in.nextInt();
p = in.nextInt();
q = in.nextInt();
c = new int[n];
b = new int[n][];
for (int i = 0; i < n; ++i) {
c[i] = in.nextInt();
b[i] = new int[p];
for (int j = 0; j < p; ++j) {
int cnt = in.nextInt();
for (int k = 0; k < cnt; ++k) {
b[i][j] |= 1 << in.nextInt();
}
}
}
m = in.nextInt();
a = new int[m];
f = new int[m];
r = new int[m][];
for (int i = 0; i < m; ++i) {
a[i] = in.nextInt();
f[i] = in.nextInt();
r[i] = new int[p];
for (int j = 0; j < p; ++j) {
int cnt = in.nextInt();
for (int k = 0; k < cnt; ++k) {
r[i][j] |= 1 << in.nextInt();
}
}
}
ans = new int[m][];
for (int i = 0; i < m; ++i) {
ans[i] = new int[n];
}
used = new boolean[q+1];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
boolean 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;
}
}
}
PrintWriter out = new PrintWriter(System.out);
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) {
out.print(ans[i][j]);
out.print(" ");
}
out.print("\n");
}
out.flush();
}
}