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 long long int mod = 1e9 + 7;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long int l = v.size();
  for (long long int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
long long int gcd(long long int a, long long int b) {
  if (b < a) {
    swap(a, b);
  }
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b / gcd(a, b));
}
long long int primefactorise(int n) {
  if (n == 1) {
    return 1;
  }
  long long int ans = n;
  while (n % 2 == 0) {
    n = n / 2;
    if (n != 1) {
      ans += n;
    }
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      n = n / i;
      if (n != 1) {
        ans += n;
      }
    }
  }
  ans += 1;
  return ans;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b > 0) {
    if (b % 2 == 1) {
      ans *= a;
      ans = ans;
    }
    b /= 2;
    a *= a;
    a = a;
  }
  return ans;
}
vector<long long int> getbinary(long long int x, long long int size) {
  vector<long long int> bin(size, 0);
  long long int iter = 0;
  while (x > 0) {
    if (x % 2 == 0) {
      bin[iter] = 0;
    } else {
      bin[iter] = 1;
    }
    x /= 2;
    iter++;
  }
  return bin;
}
long long int dist(pair<long long int, long long int> a,
                   pair<long long int, long long int> b) {
  return 0;
}
vector<long long int> getprimes() {
  vector<long long int> primes(1000000, 0);
  vector<long long int> ans;
  for (int i = 2; i < 1000000; i++) {
    if (primes[i] == 0) {
      for (int j = 2 * i; j < 1000000; j += i) {
        primes[j] = 1;
      }
      ans.push_back(i);
    }
  }
  return ans;
}
const long long int size = 10;
struct tnode {
  tnode* child[size];
  long long int isword;
};
tnode* makenode() {
  tnode* temp = new tnode;
  for (int i = 0; i < size; i++) {
    temp->child[i] = NULL;
  }
  temp->isword = 0;
  return temp;
}
void insert(tnode* root, string second) {
  tnode* temp = root;
  for (int i = 0; i < second.size(); i++) {
    long long int key = second[i] - 'a';
    if (temp->child[key] == NULL) {
      temp->child[key] = makenode();
    }
    temp = temp->child[key];
  }
  temp->isword = 1;
}
long long int search(tnode* root, string second) {
  tnode* temp = root;
  for (int i = 0; i < second.size(); i++) {
    long long int key = second[i] - 'a';
    if (temp->child[key] == NULL) {
      return 0;
    }
    temp = temp->child[key];
  }
  return temp->isword;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout.precision(50);
  long long int n, m, second;
  cin >> n >> m >> second;
  map<pair<long long int, long long int>, long long int> ori1, ori2;
  map<long long int, vector<pair<long long int, long long int> > > g;
  vector<pair<long long int, long long int> > ans;
  for (int i = 0; i < m; i++) {
    long long int t, u, v;
    cin >> t >> u >> v;
    if (t == 1) {
      g[u].push_back(make_pair(v, 1));
    } else {
      ans.push_back(make_pair(u, v));
      ori1[make_pair(u, v)] = 1;
      ori2[make_pair(u, v)] = 1;
      g[u].push_back(make_pair(v, 2));
      g[v].push_back(make_pair(u, 2));
    }
  }
  vector<long long int> col(n + 1, 0);
  stack<int> st;
  st.push(second);
  col[second] = 1;
  long long int answer1 = 1;
  while (!st.empty()) {
    long long int u = st.top();
    st.pop();
    for (auto v : g[u]) {
      if (col[v.first] == 0) {
        if (v.second == 2) {
          if (ori1[make_pair(u, v.first)] == 1) {
            ori1[make_pair(u, v.first)] = 2;
          } else {
            ori1[make_pair(v.first, u)] = 3;
          }
        }
        col[v.first] = 1;
        st.push(v.first);
        answer1++;
      }
    }
  }
  cout << answer1 << endl;
  for (int i = 0; i < ans.size(); i++) {
    if (ori1[ans[i]] == 2) {
      cout << "+";
    } else {
      cout << "-";
    }
  }
  cout << endl;
  answer1 = 1;
  fill(col.begin(), col.end(), 0);
  st.push(second);
  col[second] = 1;
  while (!st.empty()) {
    long long int u = st.top();
    st.pop();
    for (auto v : g[u]) {
      if (col[v.first] == 0) {
        if (v.second == 2) {
          if (ori2[make_pair(u, v.first)] == 1) {
            ori2[make_pair(u, v.first)] = 3;
          } else {
            ori2[make_pair(v.first, u)] = 2;
          }
        } else {
          col[v.first] = 1;
          st.push(v.first);
          answer1++;
        }
      }
    }
  }
  cout << answer1 << endl;
  for (int i = 0; i < ans.size(); i++) {
    if (ori2[ans[i]] == 2) {
      cout << "+";
    } else {
      cout << "-";
    }
  }
  cout << endl;
}