#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5;
int dfn[N],low[N],dfc,f[N],g[N],n,m,K,L,cnt,tot,h[N];
struct edge{
int to,nxt;
}e[N * 20];
struct nd{
int l,r;
}ans[N];
void add(int x,int y) {e[++tot] = edge{y,h[x]},h[x] = tot;}
void tarjan(int u,int fa)
{
dfn[u] = low[u] = ++dfc;
for (int i = h[u]; i; i = e[i].nxt)
{
int v = e[i].to;
if (!dfn[v])
{
tarjan(v,u),low[u] = min(low[u],low[v]),f[u] += f[v],g[u] += g[v];
if (low[v] > dfn[u])
if (f[v] == 0 || g[v] == 0 || f[v] == K || g[v] == L) ans[++cnt] = nd{v,u};
}
else if (v != fa) low[u] = min(low[u],dfn[v]);
}
}
int main()
{
scanf("%d%d%d%d",&n,&m,&K,&L);
for (int i = 1,q; i <= K; i++) scanf("%d",&q),f[q] = 1;
for (int i = 1,q; i <= L; i++) scanf("%d",&q),g[q] = 1;
for (int i = 1,q,p; i <= m; i++) scanf("%d%d",&q,&p),add(q,p),add(p,q);
tarjan(1,1);
printf("%d\n",cnt);
for (int i = 1; i <= cnt; i++) printf("%d %d\n",ans[i].l,ans[i].r);
}