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
#!/usr/bin/python3

# === wej ===

n = int(input())

def read_graph():
    G = []
    for i in range(n+1):
        G.append([])
    m = int(input())
    for i in range(m):
        a, b = input().split()
        a, b = int(a), int(b)
        G[a].append(b)
        G[b].append(a)
    return G

G1 = read_graph()
G2 = read_graph()

# === prog ===

edges = None
def edge(a, b):
    return tuple(sorted([a, b]))
    # e = [a, b]
    # e.sort()
    # return tuple(e)

moves = None
def add(a, b):
    edges.add(edge(a, b))
    moves.append((True, a, b))
def remove(a, b):
    edges.remove(edge(a, b))
    moves.append((False, a, b))
def in_edges(a, b):
    return edge(a, b) in edges

G = None
vis = None

def dfs(v):
    if v != 1:
        if not in_edges(v, 1):
            add(v, 1)
    vis[v] = 1
    # print(f"-> {v}")
    for u in G[v]:
        if not vis[u]:
            dfs(u)
        elif vis[u] == 1:
            if u != 1:
                remove(v, u)
        elif vis[u] == 2:
            pass
        else:
            assert(False)
    
    vis[v] = 2
    # print(f"<- {v}")


def standarize(G_):
    global moves
    global G
    global vis
    global edges
    moves = []
    G = G_
    vis = [0] * (n+1)

    edges = set()
    for v in range(1, n+1):
        for u in G[v]:
            edges.add(edge(v, u))
    
    # print(G)
    dfs(1)
    # dfs(2)
    # print(moves)

    return moves


moves1 = standarize(G1)
moves2 = list(reversed(standarize(G2)))

# === wyj ===

print(len(moves1) + len(moves2))
for op, a, b in moves1:
    print(f"{'+' if op else '-'} {a} {b}")
for op, a, b in moves2:
    print(f"{'-' if op else '+'} {a} {b}")