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;
namespace fastIO_0 {
template <typename T>
inline void read(T &d) {
  static char c;
  static bool flag;
  c = d = 0;
  flag = 0;
  while (c < '0' || c > '9') {
    if (c == '-') {
      flag = 1;
      c = getchar();
      break;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') d = (T)(d * 10 + c - '0'), c = getchar();
  if (flag) d = -d;
}
template <typename T>
inline void print(const T &x) {
  if (typeid(x) == typeid(int)) return printf("%d", x), void();
  if (typeid(x) == typeid(bool)) return printf("%d", x), void();
  if (typeid(x) == typeid(char)) return printf("%c", x), void();
  if (typeid(x) == typeid(long long)) return printf("%I64d", x), void();
}
void flush() {}
}  // namespace fastIO_0
namespace fastIO_1 {
inline char read() {
  const int IN_LEN = 1000000;
  static char buf[IN_LEN], *s, *t;
  if (s == t) {
    t = (s = buf) + fread(buf, 1, IN_LEN, stdin);
    if (s == t) return -1;
  }
  return *s++;
}
template <class T>
inline void read(T &x) {
  bool iosig;
  char c;
  for (iosig = false, c = read(); !isdigit(c); c = read()) {
    if (c == '-') iosig = true;
    if (c == -1) return;
  }
  for (x = 0; isdigit(c); c = read()) x = (x + (x << 2) << 1) + (c ^ '0');
  if (iosig) x = -x;
}
template <class T>
inline T read() {
  static T c;
  read(c);
  return c;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
  if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
  *ooh++ = c;
}
template <class T>
inline void print(T x) {
  static int buf[30], cnt;
  if (x == 0)
    print('0');
  else {
    if (x < 0) print('-'), x = -x;
    for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48;
    while (cnt) print((char)buf[cnt--]);
  }
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
inline void put(const char *s) {
  for (; *s; s++) print(*s);
  print('\n');
}
}  // namespace fastIO_1
using namespace fastIO_1;
struct Edge {
  int u, v, id, nxt;
} g[600010];
int first[600010], __cnt = -1;
vector<int> T[600010];
bool vis[600010], ok[600010], res[600010];
inline void add(int u, int v, int w) {
  g[++__cnt] = (Edge){u, v, w, first[u]};
  first[u] = __cnt;
}
queue<int> qu;
int main() {
  int n, m, s;
  read(n);
  read(m);
  read(s);
  memset(first, -1, sizeof(first));
  for (int i = 1; i <= m; ++i) {
    int t, u, v;
    read(t);
    read(u);
    read(v);
    if (t == 1)
      T[u].push_back(v);
    else
      add(u, v, i), add(v, u, i);
  }
  while (!qu.empty()) qu.pop();
  memset(vis, 0, sizeof(vis));
  memset(ok, 0, sizeof(ok));
  qu.push(s);
  vis[s] = 1;
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    for (int i = 0; i < T[x].size(); i++) {
      if (!vis[T[x][i]]) vis[T[x][i]] = 1, qu.push(T[x][i]);
    }
    for (int i = first[x]; i != -1; i = g[i].nxt) {
      if (!ok[i / 2 + 1]) {
        ok[i / 2 + 1] = 1;
        if (i & 1)
          res[i / 2 + 1] = 1;
        else
          res[i / 2 + 1] = 0;
        if (!vis[g[i].v]) vis[g[i].v] = 1, qu.push(g[i].v);
        continue;
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (vis[i]) cnt++;
  printf("%d\n", cnt);
  for (int i = 1; i <= __cnt / 2 + 1; ++i) printf(res[i] ? "-" : "+");
  puts("");
  while (!qu.empty()) qu.pop();
  memset(vis, 0, sizeof(vis));
  memset(ok, 0, sizeof(ok));
  qu.push(s);
  vis[s] = 1;
  while (!qu.empty()) {
    int x = qu.front();
    qu.pop();
    for (int i = 0; i < T[x].size(); i++) {
      if (!vis[T[x][i]]) vis[T[x][i]] = 1, qu.push(T[x][i]);
    }
    for (int i = first[x]; i != -1; i = g[i].nxt) {
      if (ok[i / 2 + 1]) {
        if (!vis[g[i].v]) vis[g[i].v] = 1, qu.push(g[i].v);
        continue;
      }
      ok[i / 2 + 1] = 1;
      if (i & 1)
        res[i / 2 + 1] = 0;
      else
        res[i / 2 + 1] = 1;
    }
  }
  cnt = 0;
  for (int i = 1; i <= n; ++i)
    if (vis[i]) cnt++;
  printf("%d\n", cnt);
  for (int i = 1; i <= __cnt / 2 + 1; ++i) printf(res[i] ? "-" : "+");
  return 0;
}