var
a,b,v,g,ans:longint;
v1,d:array[1..25]of longint;
g1:array[1..15,1..25]of longint;
g2:array[1..15]of longint;
procedure siliao(w,s:longint);
var
i,j:longint;
begin
if ans=1 then exit;
if s=a then
begin
j:=0;
for i:=1 to v do
if not(d[i]>=v1[i]) then
begin
j:=1;break;
end;
if j=0 then
begin
ans:=1;
write(a,' ');
for i:=1 to g do
if g2[i]=1 then write(i,' ');
writeln;
end;
end;
if s<>a then
for i:=w+1 to g-(a-s)+1 do
if g2[i]=0 then
begin
for j:=1 to v do
d[j]:=d[j]+g1[i,j];
g2[i]:=1;
siliao(i,s+1);
g2[i]:=0;
for j:=1 to v do
d[j]:=d[j]-g1[i,j];
end;
end;
begin
assign(input,'holstein.in');
assign(output,'holstein.out');
reset(input);
rewrite(output);
readln(v);
for a:=1 to v do
read(v1[a]);
readln(g);
for a:=1 to g do
for b:=1 to v do
read(g1[a,b]);
ans:=0;
for a:=1 to g do
begin
siliao(0,0);
if ans=1 then break;
end;
close(input);close(output);
end.