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
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;}
auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";}
#define debug(X) cerr << "["#X"]: " << X << '\n';
#else 
#define cerr if(0)cout
#define debug(X) ;
#endif
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define ssize(x) int(x.size())
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	cout.tie(nullptr);

	int n, ms, md;
	cin >> n;
	cin >> ms;

	vector<vector<int>> g(n), gd(n);
	for(int i = 0; i < ms; ++i) {
		int u, v;
		cin >> u >> v;
		g[u-1].eb(v-1);
		g[v-1].eb(u-1);
	}

	cin >> md;
	for(int i = 0; i < md; ++i) {
		int u, v;
		cin >> u >> v;
		gd[u-1].eb(v-1);
		gd[v-1].eb(u-1);
	}
	vector<array<int, 3>> query;

	vector<bool> s(n), d(n);
	for(auto u : g[0]) s[u] = true;
	for(auto u : gd[0]) d[u] = true;

	vector<bool> odw(n);
	auto add_star_edge = [&](int v) {
		if(v == 0 || s[v]) return;
		query.eb((array<int, 3>){0, v+1, 1});
	};

	function<void(int)> star = [&](int v) {
		odw[v] = true;
		add_star_edge(v);
		for(auto u : g[v]) if(!odw[u]) star(u);
	};
	star(0);

	auto add = [&](int v, int u) {
		if(v <= u) return;
		if(u == 0 || v == 0) return;
		query.eb((array<int, 3>){0, v+1, u+1});
	};
	vector<bool> neigh(n);
	for(int v = 1; v < n; ++v) {
		for(auto u : g[v]) neigh[u] = true;
		for(auto u : gd[v]) {
			if(!neigh[u]) add(v, u);
		}
		for(auto u : g[v]) neigh[u] = false;
	}
	
	auto remove = [&](int u, int v) {
		if(u <= v) return;
		query.eb((array<int, 3>){1, u+1, v+1});
	};
	fill(all(neigh), false);

	for(int v = 1; v < n; ++v) {
		for(auto u : gd[v]) neigh[u] = true;
		for(auto u : g[v]) {
			if(!neigh[u] && u != 0) remove(v, u);
		}
		for(auto u : gd[v]) neigh[u] = false;
	}
	
	fill(all(odw), false);
	function<void(int)> remove_star = [&](int v) {
		odw[v] = true;
		for(auto u : gd[v]) if(!odw[u]) remove_star(u);
		if(!d[v] && v != 0) remove(v, 0);
	};
	remove_star(0);

	cout << ssize(query) << '\n';
	for(auto [t, x, y] : query) {
		if(t == 0) cout << "+ ";
		else cout << "- ";
		cout << x << ' ' << y << '\n';
	}

	return 0;
}