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;
void solve_min(int n, int m, vector<int> us, vector<int> vs, vector<int> ds,
               vector<vector<int>> g, int s) {
  queue<int> q;
  q.push(s);
  vector<bool> vis(n);
  vis[s] = true;
  int cnt = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    cnt++;
    for (int i : g[u])
      if (i % 2 == 0 && ds[i >> 1]) {
        int v = vs[i >> 1];
        if (!vis[v]) {
          q.push(v);
          vis[v] = true;
        }
      }
  }
  vector<int> ans(m);
  for (int i = 0; i < n; i++) {
    for (int ii : g[i])
      if (!ds[ii >> 1]) {
        int v = ii % 2 == 0 ? vs[ii >> 1] : us[ii >> 1];
        if (!vis[i] && vis[v]) {
          ans[ii >> 1] = ii % 2 == 1;
        }
      }
  }
  cout << cnt << endl;
  for (int i = 0; i < m; i++) {
    if (!ds[i]) {
      putchar(ans[i] ? '-' : '+');
    }
  }
  cout << endl;
}
void solve_max(int n, int m, vector<int> us, vector<int> vs, vector<int> ds,
               vector<vector<int>> g, int s) {
  priority_queue<pair<int, int>> q;
  q.emplace(1, s);
  q.emplace(0, s);
  vector<bool> vis(n);
  vis[s] = true;
  int cnt = 0;
  vector<int> ans(m);
  while (!q.empty()) {
    int d = q.top().first;
    int u = q.top().second;
    q.pop();
    cnt += d;
    if (d) {
      for (int i : g[u])
        if (ds[i >> 1]) {
          int v = vs[i >> 1];
          if (!vis[v]) {
            q.emplace(0, v);
            q.emplace(1, v);
            vis[v] = true;
          }
        }
    } else {
      for (int i : g[u])
        if (!ds[i >> 1]) {
          int v = i % 2 == 0 ? vs[i >> 1] : us[i >> 1];
          if (!vis[v]) {
            q.emplace(0, v);
            q.emplace(1, v);
            ans[i >> 1] = i % 2 == 1;
            vis[v] = true;
          }
        }
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < m; i++) {
    if (!ds[i]) {
      putchar(ans[i] ? '-' : '+');
    }
  }
  cout << endl;
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  s--;
  vector<int> us(m), vs(m), ds(m);
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &ds[i], &us[i], &vs[i]);
    ds[i] = ds[i] == 1;
    us[i]--;
    vs[i]--;
    if (ds[i]) {
      g[us[i]].push_back(i * 2);
    } else {
      g[us[i]].push_back(i * 2);
      g[vs[i]].push_back(i * 2 + 1);
    }
  }
  solve_max(n, m, us, vs, ds, g, s);
  solve_min(n, m, us, vs, ds, g, s);
}