using System;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Scanner
{
// StreamReader input = new StreamReader(Console.OpenStandardInput(), bufferSize: 16384);
StreamReader input = new StreamReader(Console.OpenStandardInput());
char[] buffer = new char[4096];
public int ReadInt()
{
var length = PrepareToken();
var res = int.Parse(buffer.AsSpan(0, length));
return res;
}
private int PrepareToken()
{
int length = 0;
bool readStart = false;
while (true)
{
int ch = input.Read();
if (ch == -1)
break;
if (char.IsWhiteSpace((char)ch))
{
if (readStart) break;
continue;
}
readStart = true;
buffer[length++] = (char)ch;
}
return length;
}
}
class Graph
{
int n;
int[] a;
Tuple<int, int>[] e;
public Graph Read(Scanner s)
{
int n = s.ReadInt();
int m = s.ReadInt();
for (int i = 0; i < n; i++)
{
int label = s.ReadInt();
}
e = new Tuple<int, int>[m];
for (int i = 0; i < m; i++)
{
int from = s.ReadInt();
int to = s.ReadInt();
e[i] = new Tuple<int, int>(from - 1, to - 1);
}
return this;
}
public bool CheckIsomophism(Graph g, out 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
f = null;
return false;
}
}
class main
{
public static void Main(string[] args)
{
Scanner sc = new Scanner();
Graph g = new Graph().Read(sc);
int k = sc.ReadInt();
var res = new List<Tuple<int, int[]>>();
for (int i = 0; i < k; i++)
{
Graph s = new Graph().Read(sc);
int[] f;
if (s.CheckIsomophism(g, out f))
{
res.Add(new Tuple<int, int[]>(i, f));
}
}
Console.WriteLine(res.Count);
for (int i = 0; i < res.Count; i++)
{
Console.Write(res[i].Item1 + 1);
for (int j = 0; j < res[i].Item2.Length; j++)
{
Console.Write($" {res[i].Item2[j] + 1}");
}
Console.WriteLine();
}
}
}