import java.util.*;
import java.io.*;
class Graph
{
public int n;
int[] a;
List<AbstractMap.SimpleEntry<Integer, Integer>> e;
public Graph read(BufferedReader reader) throws IOException
{
StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
n = Integer.parseInt(tokenizer.nextToken());
int m = Integer.parseInt(tokenizer.nextToken());
a = new int[n];
tokenizer = new StringTokenizer(reader.readLine());
for (int i = 0; i < n; i++)
{
a[i] = Integer.parseInt(tokenizer.nextToken());
}
e = new ArrayList<AbstractMap.SimpleEntry<Integer, Integer>>();
for (int i = 0; i < m; i++)
{
tokenizer = new StringTokenizer(reader.readLine());
int x = Integer.parseInt(tokenizer.nextToken()) - 1;
int y = Integer.parseInt(tokenizer.nextToken()) - 1;
e.add(new AbstractMap.SimpleEntry<Integer, Integer>(x, y));
}
return this;
}
public boolean checkIsomorphism(Graph g, int[] f)
{
// check if subgraph isomorphism exists
// if found return true and fill f with mapping according to the statement
// if not found return false
return false;
}
}
public class main
{
public static void main(String args[]) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Graph g = new Graph().read(reader);
int k = Integer.parseInt(reader.readLine());
ArrayList<AbstractMap.SimpleEntry<Integer, int[]>> res = new ArrayList<AbstractMap.SimpleEntry<Integer, int[]>>();
for (int i = 0; i < k; i++)
{
Graph s = new Graph().read(reader);
int[] f = new int[s.n];
if (s.checkIsomorphism(g, f))
{
res.add(new AbstractMap.SimpleEntry<Integer, int[]>(i, f));
}
}
System.out.println(res.size());
for (int i = 0; i < res.size(); i++)
{
System.out.print(res.get(i).getKey() + 1);
for (int j = 0; j < res.get(i).getValue().length; j++)
{
System.out.print(" " + (res.get(i).getValue()[j] + 1));
}
System.out.println();
}
}
}