Problem: 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; 
  2. 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.

Input

The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 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 ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi) — edge type and vertices connected by the edge. If ti = 1 then the edge is directed and goes from the vertex ui to the vertex vi. If ti = 2 then the edge is undirected and it connects the vertices ui and vi.

It is guaranteed that there is at least one undirected edge in the graph.

Output

The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices.

A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan should consist of f symbols '+' and '-', where f is the number of undirected edges in the initial graph. Print '+' as the j-th symbol of the string if the j-th undirected edge (u, v) from the input should be oriented from u to v. Print '-' to signify the opposite direction (from v to u). Consider undirected edges to be numbered in the same order they are given in the input.

If there are multiple solutions, print any of them.

Examples

Input

2 2 1
1 1 2
2 2 1


Output

2
-
2
+


Input

6 6 3
2 2 6
1 4 5
2 3 4
1 4 1
1 3 1
2 2 3


Output

6
++-
2
+-+

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
const int maxn = 300005, maxm = 600005;
const char output[2] = {'+', '-'};
int n, m, u[maxm], v[maxm], numUnd;
int low[maxn], dfn[maxn], scc[maxn], dfs_clock, scc_cnt, stk[maxn], top,
    siz[maxn];
int out[maxm], que[maxn], head_, tail, h;
char book[maxn];
struct Graph {
  int head[maxn], to[maxm], next[maxm], lb;
  Graph() {
    memset(head, -1, sizeof head);
    memset(next, -1, sizeof next);
    lb = 0;
  }
  void ist(int aa, int ss) {
    to[lb] = ss;
    next[lb] = head[aa];
    head[aa] = lb;
    ++lb;
  }
} g1, g2, g3;
void dfs(int r) {
  dfn[r] = low[r] = ++dfs_clock;
  stk[top++] = r;
  for (int j = g1.head[r]; j != -1; j = g1.next[j]) {
    if (!dfn[g1.to[j]]) {
      dfs(g1.to[j]);
      low[r] = std::min(low[r], low[g1.to[j]]);
    } else if (!scc[g1.to[j]]) {
      low[r] = std::min(low[r], dfn[g1.to[j]]);
    }
  }
  if (low[r] == dfn[r]) {
    ++scc_cnt;
    int x;
    while (1) {
      x = stk[--top];
      scc[x] = scc_cnt;
      ++siz[scc_cnt];
      if (x == r) {
        break;
      }
    }
  }
}
inline void find_scc() {
  dfs_clock = scc_cnt = 0;
  memset(scc, 0, sizeof scc);
  memset(dfn, 0, sizeof dfn);
  memset(low, 0, sizeof low);
  top = 0;
  for (int i = 1; i <= n; ++i) {
    if (dfn[i] == 0) {
      dfs(i);
    }
  }
}
int main() {
  int ini_s, type, t1, t2;
  scanf("%d%d%d", &n, &m, &ini_s);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d%d", &type, &t1, &t2);
    if (type == 1) {
      g1.ist(t1, t2);
    } else {
      u[numUnd] = t1;
      v[numUnd] = t2;
      ++numUnd;
    }
  }
  find_scc();
  for (int i = 1; i <= n; ++i) {
    for (int j = g1.head[i]; j != -1; j = g1.next[j]) {
      if (scc[i] == scc[g1.to[j]]) {
        continue;
      }
      g2.ist(scc[i], scc[g1.to[j]]);
    }
  }
  for (int i = 0; i < numUnd; ++i) {
    g3.ist(scc[u[i]], scc[v[i]]);
    g3.ist(scc[v[i]], scc[u[i]]);
  }
  int ans = 0;
  que[tail++] = scc[ini_s];
  book[scc[ini_s]] = 1;
  while (head_ != tail) {
    h = que[head_++];
    ans += siz[h];
    for (int j = g2.head[h]; j != -1; j = g2.next[j]) {
      if (!book[g2.to[j]]) {
        que[tail++] = g2.to[j];
        book[g2.to[j]] = 1;
      }
    }
    for (int j = g3.head[h]; j != -1; j = g3.next[j]) {
      if (!book[g3.to[j]]) {
        que[tail++] = g3.to[j];
        book[g3.to[j]] = 1;
        out[j / 2] = j & 1;
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 0; i < numUnd; ++i) {
    putchar(output[out[i]]);
  }
  ans = 0;
  head_ = tail = 0;
  memset(book, 0, sizeof book);
  que[tail++] = scc[ini_s];
  book[scc[ini_s]] = 1;
  while (head_ != tail) {
    h = que[head_++];
    ans += siz[h];
    for (int j = g2.head[h]; j != -1; j = g2.next[j]) {
      if (!book[g2.to[j]]) {
        que[tail++] = g2.to[j];
        book[g2.to[j]] = 1;
      }
    }
    for (int j = g3.head[h]; j != -1; j = g3.next[j]) {
      if (!book[g3.to[j]]) {
        out[j / 2] = j & 1 ^ 1;
      }
    }
  }
  printf("\n%d\n", ans);
  for (int i = 0; i < numUnd; ++i) {
    putchar(output[out[i]]);
  }
  puts("");
  return 0;
}