def main():
n, p, q = [int(x) for x in input().split()]
c = [0] * n
b = []
for i in range(n):
c[i] = int(input().strip())
b_i = []
for j in range(p):
_, *v = [int(x) for x in input().split()]
val = 0
for x in v:
val |= 1 << x
b_i += [val]
b += [b_i]
m = int(input().strip())
a = [0] * m
f = [0] * m
r = []
for i in range(m):
a[i], f[i] = [int(x) for x in input().split()]
r_i = []
for j in range(p):
_, *v = [int(x) for x in input().split()]
val = 0
for x in v:
val |= 1 << x
r_i += [val]
r += [r_i]
ans = [[0] * n for _ in range(m)]
for i in range(n):
for j in range(m):
ok = True
for k in range(p):
if b[i][k] & r[j][k] == 0:
ok = False
break
if ok:
cnt = min(c[i], a[j])
if f[j] != 0:
cnt = min(cnt, f[j])
ans[j][i] += cnt
c[i] -= cnt
a[j] -= cnt
for i in range(m):
if a[i] != 0:
for j in range(n):
ans[i][j] = 0
print(' '.join([str(x) for x in ans[i]]))
if __name__ == '__main__':
main()