#include "bits/stdc++.h"
using namespace std;
struct Graph
{
int n;
vector<int> a;
vector<pair<int, int> > e;
Graph read()
{
int m;
scanf("%d%d", &n, &m);
a.resize(n);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
a[i]--;
}
e.reserve(m);
for (int i = 0; i < m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
x--;
y--;
e.push_back(make_pair(x, y));
}
return *this;
}
bool find_isomorphism(const Graph& g, vector<int>& f) const
{
// 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;
}
};
int main(int argc, char* argv[])
{
Graph g;
g.read();
int k;
scanf("%d", &k);
vector<pair<int, vector<int> > > res;
for (int i = 0; i < k; i++)
{
Graph s;
s.read();
vector<int> f;
if (s.find_isomorphism(g, f)) res.push_back(make_pair(i, f));
}
printf("%d\n", (int)res.size());
for (int i = 0; i < (int)res.size(); i++)
{
printf("%d", res[i].first + 1);
for (int j = 0; j < (int)res[i].second.size(); j++)
{
printf(" %d", res[i].second[j] + 1);
}
printf("\n");
}
}