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>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int tot, head[maxn];
struct E {
  int w, to, next;
} edge[maxn << 1];
void add(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
int n, m, s;
set<pair<int, int> > S1;
map<pair<int, int>, int> mp1;
map<pair<int, int>, char> mpchar1;
vector<pair<int, int> > vec1;
int vis1[maxn], cnt1;
void dfs1(int x) {
  vis1[x] = true;
  cnt1 += 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis1[v] && edge[i].w == 1) {
      vis1[v] = 1;
      dfs1(v);
    }
    if (!vis1[v] && edge[i].w == 2 && mp1[{x, v}] == 0 && mp1[{v, x}] == 0) {
      vis1[v] = 1;
      mp1[{x, v}] = mp1[{v, x}] = 1;
      if (S1.count({x, v}))
        mpchar1[{x, v}] = '+';
      else if (!S1.count({x, v}))
        mpchar1[{v, x}] = '-';
      dfs1(v);
    }
  }
}
set<pair<int, int> > S2;
map<pair<int, int>, int> mp2;
map<pair<int, int>, char> mpchar2;
vector<pair<int, int> > vec2;
int vis2[maxn], cnt2;
void dfs2(int x) {
  vis2[x] = true;
  cnt2 += 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis2[v] && edge[i].w == 1) {
      vis2[v] = 1;
      dfs2(v);
    }
    if (!vis2[v] && edge[i].w == 2 && mp2[{x, v}] == 0 && mp2[{v, x}] == 0) {
      mp2[{x, v}] = mp2[{v, x}] = 1;
      if (S2.count({x, v}))
        mpchar2[{x, v}] = '-';
      else if (!S2.count({x, v}))
        mpchar2[{v, x}] = '+';
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  memset(head, -1, sizeof(head));
  while (m--) {
    int u, v, w;
    scanf("%d%d%d", &w, &u, &v);
    if (w == 1)
      add(u, v, w);
    else {
      add(u, v, w);
      add(v, u, w);
      mp1[{u, v}] = mp1[{v, u}] = 0;
      vec1.push_back({u, v});
      S1.insert({u, v});
      mpchar1[{u, v}] = '+';
      mp2[{u, v}] = mp2[{v, u}] = 0;
      vec2.push_back({u, v});
      S2.insert({u, v});
      mpchar2[{u, v}] = '+';
    }
  }
  dfs1(s);
  printf("%d\n", cnt1);
  for (int i = 0; i < vec1.size(); i++) {
    cout << mpchar1[vec1[i]];
  }
  puts("");
  dfs2(s);
  printf("%d\n", cnt2);
  for (int i = 0; i < vec2.size(); i++) {
    cout << mpchar2[vec2[i]];
  }
  puts("");
}