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
#include <cstdio>
#include <vector>
#include <utility>

#define REP(a, n) for (int a = 0; a < (n); ++a)

#define INF 1000000000

using namespace std;

template<class T> inline int SIZE(const T &t) { return t.size(); }

//////////////////////////

#define MAXN 30005

int N, cur;
vector<int> dla1[2];
vector<pair<int,int>> inne[2];
vector<int> sas[MAXN];
bool sas1[MAXN], byl[MAXN];

void dfs(int a) {
    if (byl[a]) return;
    byl[a] = 1;
    if (a!=1 && !sas1[a])
        dla1[cur].push_back(a);
    for (int s : sas[a])
        dfs(s);
}

void czytaj() {
    REP(a, N+1) { sas[a].clear(); sas1[a] = byl[a] = 0; }
    int M;
    scanf("%d", &M);
    REP(a, M) {
        int k, l;
        scanf("%d%d", &k, &l);
        sas[k].push_back(l);
        sas[l].push_back(k);
        if (l==1) swap(k,l);
        if (k==1)
            sas1[l] = 1;
        else
            inne[cur].emplace_back(k, l);
    }
    dfs(1);
    
}

int main() {
    scanf("%d", &N);
    for (cur = 0; cur < 2; ++cur)
        czytaj();
    printf("%d\n", SIZE(dla1[0])+SIZE(dla1[1])+SIZE(inne[0])+SIZE(inne[1]));
    for (int x : dla1[0])
        printf("+ 1 %d\n", x);
    for (auto p : inne[0])
        printf("- %d %d\n", p.first, p.second);
    for (auto p : inne[1])
        printf("+ %d %d\n", p.first, p.second);
    for (int a = SIZE(dla1[1])-1; a>=0; --a)
        printf("- 1 %d\n", dla1[1][a]);
}