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
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

struct Graph {
  set<pii> edgs;
  vector<vector<int>> g;
  void init(int n) {
    g.assign(n, vector<int>());
    edgs.clear();
  }
  
  void add_edge(int a, int b) {
    if(a > b) swap(a, b);
    edgs.emplace(a, b);
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  
  bool query_edge(int a, int b) {
    if(a > b) swap(a, b);
    return a == b || edgs.count(pii{a, b});
  }
  
  vector<tuple<char, int, int>> clica_din1() {
    queue<int> que;
    int n = sz(g);
    vector<int> occ(n, 0);
    occ[1] = 1;
    que.emplace(1);
    
    vector<tuple<char, int, int>> opers;
    
    while(!que.empty()) {
      int node = que.front();
      que.pop();
      
      //cerr << node << '\t' << query_edge(1, node) << '\n';
      
      if(!query_edge(1, node))
        add_edge(1, node),
        opers.emplace_back('+', 1, node);
      
      for(auto x : g[node])
        if(!occ[x])
          que.emplace(x),
          occ[x] = 1;
    }
    
    //cerr << "--\n";
    
    return opers;
  }
};

signed main() {
  cin.tie(0) -> sync_with_stdio(0);
  int n, m;
  cin >> n;
  
  Graph A, B;
  A.init(n + 1);
  B.init(n + 1);
  
  cin >> m;
  for(int i = 0, a, b; i < m; i++)
    cin >> a >> b,
    A.add_edge(a, b);
  
  cin >> m;
  for(int i = 0, a, b; i < m; i++)
    cin >> a >> b,
    B.add_edge(a, b);
  
  auto first = A.clica_din1(), third = B.clica_din1();
  for(auto &[a, b, c] : third) a = '-';
  reverse(all(third));
  
  vector<tuple<char, int, int>> second;
  
  for(auto [a, b] : A.edgs) {
    if(a == 1 || b == 1) continue;
    if(!B.query_edge(a, b)) second.emplace_back('-', a , b);
  }
  for(auto [a, b] : B.edgs) {
    if(a == 1 || b == 1) continue;
    if(!A.query_edge(a, b)) second.emplace_back('+', a , b);
  }
  
  cout << sz(first) + sz(second) + sz(third) << '\n';
  for(auto [a, b, c] : first) cout << a << ' ' << b << ' ' << c << '\n';
  for(auto [a, b, c] : second) cout << a << ' ' << b << ' ' << c << '\n';
  for(auto [a, b, c] : third) cout << a << ' ' << b << ' ' << c << '\n';
  
  
  
  
  
  
  
}

/**
  Anul asta nu se da centroid
  -- Rugaciunile mele
*/