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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("sse,sse2,abm,mmx,sse3,tune=native")
using namespace std;
typedef long long lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define sz size()
#define For(i, s, a) for(int i = s; i < a; ++i)
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).erase(unique(all(x)), (x).end())

const int N = 3e4 + 1;
bitset<N> src[N], dst[N], odw;
vector<int> c[N], d[N];
vector<tuple<char, int, int>> out;

void dfs1(int x) {
    odw[x] = 1;
    for (auto s : c[x])
        if (!odw[s]) {
            if (!src[1][s]) {
                out.push_back({'+', 1, s});
                src[1][s] = src[s][1] = 1;

            }
            dfs1(s);
        }
}

void append1(int n) {
    bitset<N> tmp;
    For (i, 1, n + 1) {
        tmp = src[i];
        tmp.flip();
        tmp = tmp & dst[i];
        for (int j = tmp._Find_next(0); j < N; j = tmp._Find_next(j)) {
            if (i == j)
                continue;
            src[i][j] = src[j][i] = 1;
            out.push_back({'+', i, j});
        }
    }
}

void dfs2(int x) {
    odw[x] = 1;
    for (auto s : d[x])
        if (!odw[s]) {
            if (!dst[1][s]) {
                out.push_back({'-', 1, s});
                dst[1][s] = dst[s][1] = 1;

            }
            dfs1(s);
        }
}

void append2(int n) {
    bitset<N> tmp;
    For (i, 1, n + 1) {
        tmp = dst[i];
        tmp.flip();
        tmp = tmp & src[i];
        for (int j = tmp._Find_next(0); j < N; j = tmp._Find_next(j)) {
            if (i == j)
                continue;
            dst[i][j] = dst[j][i] = 1;
            out.push_back({'-', i, j});
        }
    }
}

int main(void) {
	int n;
    scanf("%d", &n);
    int m;
    
    scanf("%d", &m);
    For (i, 0, m) {
        int g, h;
        scanf("%d%d", &g, &h);
        src[g][h] = src[h][g] = 1;
        c[g].pb(h);
        c[h].pb(g);
    }
    
    scanf("%d", &m);
    For (i, 0, m) {
        int g, h;
        scanf("%d%d", &g, &h);
        dst[g][h] = dst[h][g] = 1;
        d[g].pb(h);
        d[h].pb(g);
    }

    dfs1(1);
    append1(n);

    int pvt = out.size();
    odw = 0;

    dfs2(1);
    append2(n);
    reverse(out.begin() + pvt, out.end());
    printf("%d\n", (int)out.size());
    for (auto s : out) {
        printf("%c %d %d\n", get<0>(s), get<1>(s), get<2>(s));
    }
}

/*
7
6
1 2
1 3
2 4
2 5
3 6
3 7
7
1 2
2 3
3 4
4 5
5 6
6 7
7 1


*/