Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.

Vasya has picked a vertex *s* from the graph. Now Vasya wants to create two separate plans:
 1.  to orient each undirected edge in one of two possible directions to maximize number of vertices reachable from vertex *s*; 1.  to orient each undirected edge in one of two possible directions to minimize number of vertices reachable from vertex *s*. 
In each of two plans each undirected edge must become directed. For an edge chosen directions can differ in two plans.

Help Vasya find the plans.
The first line contains three integers *n*, *m* and *s* (2 ≤ *n* ≤ 3·10<sup class="upper-index">5</sup>, 1 ≤ *m* ≤ 3·10<sup class="upper-index">5</sup>, 1 ≤ *s* ≤ *n*) — number of vertices and edges in the graph, and the vertex Vasya has picked.

The following *m* lines contain information about the graph edges. Each line contains three integers *t*<sub class="lower-index">*i*</sub>, *u*<sub class="lower-index">*i*</sub> and *v*<sub class="lower-index">*i*</sub> (1 ≤ *t*<sub class="lower-index">*i*</sub> ≤ 2, 1 ≤ *u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub> ≤ *n*, *u*<sub class="lower-index">*i*</sub> ≠ *v*<sub class="lower-index">*i*</sub>) — edge type and vertices connected by the edge. If *t*<sub class="lower-index">*i*</sub> = 1 then the edge is directed and goes from the vertex *u*<sub class="lower-index">*i*</sub> to the vertex *v*<sub class="lower-index">*i*</sub>. If *t*<sub class="lower-index">*i*</sub> = 2 then the edge is undirected and it connects the vertices *u*<sub class="lower-index">*i*</sub> and *v*<sub class="lower-index">*i*</sub>.

It is guaranteed that there is at least one undirected edge in the graph.
none
2 2 1
1 1 2
2 2 1
2
-
2
+
6 6 3
2 2 6
1 4 5
2 3 4
1 4 1
1 3 1
2 2 3
6
++-
2
+-+
5 5 5
2 5 3
1 2 3
1 4 5
2 5 2
1 2 1
4
++
1
--
13 18 9
2 3 10
1 12 10
1 11 4
2 2 8
1 5 1
1 7 12
1 5 13
1 9 7
1 10 11
2 3 12
1 9 2
1 3 9
1 8 12
2 11 3
1 3 1
1 8 4
2 9 11
1 12 13
11
++-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1 2
1 2 1
2
+
2
+
2 2 1
2 1 2
2 2 1
2
+-
1
-+
2 5 1
2 1 2
2 1 2
2 1 2
2 1 2
2 1 2
2
+++++
1
-----
n,m,s=map(int,input().split())
g=[[] for i in range(n)]
t=[0]*m
s-=1
for i in range(m):
  t[i],u,v=map(int,input().split())
  g[u-1].append((v-1,i,t[i]-1))
  if t[i]==2:
    g[v-1].append((u-1,i,-1))
q=[s]
vu=[0]*n
eu=['']*m
vu[s]=1
while q:
  v=q.pop(0)
  for u,i,p in g[v]:
    if vu[u]: continue
    vu[u]=1
    q.append(u)
    if p<0: eu[i]='-'
    elif p>0: eu[i]='+'
for i in range(m):
  if t[i]==2 and not eu[i]:
    eu[i]='+'
print(sum(vu))
print(''.join(eu))

q=[s]
vu=[0]*n
eu=['']*m
vu[s]=1
while q:
  v=q.pop(0)
  for u,i,p in g[v]:
    if vu[u]: continue
    if p==0:
      vu[u]=1
      q.append(u)
    elif p<0: eu[i]='+'
    elif p>0: eu[i]='-'
for i in range(m):
  if t[i]==2 and not eu[i]:
    eu[i]='+'
print(sum(vu))
print(''.join(eu))