1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<stdio.h>
#include<set>
#define N 200009
using namespace std;
inline char nc()
{
	static char buf[99999],*l,*r;
	return l==r&&(r=(l=buf)+fread(buf,1,99999,stdin),l==r)?EOF:*l++;
}
inline void read(int&x)
{
	char c=nc();for(;c<'0'||'9'<c;c=nc());
	for(x=0;'0'<=c&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=nc());
}
int n,m,o[N],u[N],v[N],sz;set<int>e[N],keep;bool vis[N];
inline void add(int u,int v)
	{o[sz]='+';::u[sz]=u;::v[sz++]=v;e[u].emplace(v);e[v].emplace(u);}
inline void del(int u,int v)
	{o[sz]='-';::u[sz]=u;::v[sz++]=v;e[u].erase(v);e[v].erase(u);}
inline void dfs1(int i)
{
	for(set<int>::iterator it=e[i].begin();it!=e[i].end();++it)
		if(*it^1)if(!e[1].count(*it))
		{
			add(1,*it);
			dfs1(*it);
		}
}
inline void dfs2(int i)
{
	vis[i]=1;
	for(set<int>::iterator it=e[i].begin();it!=e[i].end();++it)
		if(*it^1)if(!vis[*it])dfs2(*it);
	if(!keep.count(i))del(1,i);
}
main()
{
	read(n);read(m);
	for(int u,v;m--;)read(u),read(v),e[u].emplace(v),e[v].emplace(u);
	for(set<int>::iterator it=e[1].begin();it!=e[1].end();++it)
		dfs1(*it);
	for(int i=2;i<=n;++i)
	{
		set<int>tmp=e[i];tmp.erase(1);
		for(set<int>::iterator it=tmp.begin();it!=tmp.end();++it)
			del(i,*it);
	}
	read(m);
	for(int u,v;m--;)
	{
		read(u);read(v);
		if(u>v)u^=v^=u^=v;
		if(u^1)add(u,v);
		else keep.emplace(v);
	}
	for(set<int>::iterator it=keep.begin();it!=keep.end();++it)
		dfs2(*it);
	printf("%d\n",sz);
	for(int i=0;i<sz;++i)printf("%c %d %d\n",o[i],u[i],v[i]);
}