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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n;


int def(int a, int b, vector<vector<int>> &graf)
{
    auto tmp = find(graf[a].begin(), graf[a].end(), b);
    if(tmp != graf[a].end()) 
        return 0;
    else 
    {
        if(b == n)
        {
            auto ser = find(graf[a].begin(), graf[a].end(), b-1);
            if(ser == graf[a].end())
            {
               // cout << "+ " << a << " " << b-1 << "\n";
                
               // cout << "+ " << a << " " << b << "\n";
                graf[a].emplace_back(b);
                graf[b].emplace_back(a);

                //cout<< "- " << a << " " << b-1 << "\n";
                return 3;
            }
        }
        else 
        {
            auto ser = find(graf[a].begin(), graf[a].end(), b+1);
            if(ser == graf[a].end())
            {
               // cout << "+ " << a << " " << b+1 << "\n";
                
               // cout << "+ " << a << " " << b << "\n";
                graf[a].emplace_back(b);
                graf[b].emplace_back(a);

               // cout<< "- " << a << " " << b+1 << "\n";
                return 3;
            }
        }
    }
    
   // cout << "+ " << a << " " << b << "\n";
    graf[a].emplace_back(b);
    graf[b].emplace_back(a);
    return 1;

}

void def2(int a, int b, vector<vector<int>> &graf)
{
    auto tmp = find(graf[a].begin(), graf[a].end(), b);
    if(tmp != graf[a].end()) 
        return;
    else
    {
        if(b == n)
        {
            auto ser = find(graf[a].begin(), graf[a].end(), b-1);
            if(ser == graf[a].end())
            {
                cout << "+ " << a << " " << b-1 << "\n";
                
                cout << "+ " << a << " " << b << "\n";
                graf[a].emplace_back(b);
                graf[b].emplace_back(a);

                cout<< "- " << a << " " << b-1 << "\n";
                return;
            }
        }
        else 
        {
            auto ser = find(graf[a].begin(), graf[a].end(), b+1);
            if(ser == graf[a].end())
            {
                cout << "+ " << a << " " << b+1 << "\n";
                
                cout << "+ " << a << " " << b << "\n";
                graf[a].emplace_back(b);
                graf[b].emplace_back(a);

                cout<< "- " << a << " " << b+1 << "\n";
                return;
            }
        }
    }
    
    cout << "+ " << a << " " << b << "\n";
    graf[a].emplace_back(b);
    graf[b].emplace_back(a);
    return;

}

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

    int ms, md;
    int a, b;

    

    cin >> n >> ms;
    vector<vector<int>> start_graf(n + 1);
    vector<vector<int>> graf(n + 1);
    vector<vector<int>> graf2(n + 1);

    for (int i = 0; i < ms; ++i) {
        cin >> a >> b;
        graf[a].push_back(b);
        graf[b].push_back(a);
        graf2[a].push_back(b);
        graf2[b].push_back(a);
        start_graf[a].push_back(b);
        
    }

    cin >> md;
    int res{0};

    vector<vector<int>> target_graf(n + 1);


    vector<pair<int,int>> target(md);
    for (int i = 0; i < md; ++i) {
        int a, b;
        cin >> a >> b;
        target[i]=make_pair(a,b);
        target_graf[a].push_back(b);
        target_graf[b].push_back(a);
    }

    for (int i = 0; i < md; ++i) {
        res+=def(target[i].first, target[i].second, graf);
    }

    vector<pair<int,int>>forerase;
    for(int i{1}; i<start_graf.size();i++)
    {
        for(int j{0}; j<start_graf[i].size();j++)
        {
            auto g = find(target_graf[i].begin(), target_graf[i].end(), start_graf[i][j]);
            if(g == target_graf[i].end())
            {
                res++;
                forerase.push_back(make_pair(i, start_graf[i][j]));
            }
        }
    }

    
    cout<<res<<"\n";

    for (int i = 0; i < md; ++i) {
        def2(target[i].first, target[i].second, graf2);
    }

    for(int i=0;i<forerase.size();i++)
        cout << "- " << forerase[i].first << " " << forerase[i].second << "\n";
}