#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
int type[100000 * 3 + 1];
int first[100000 * 3 + 1];
int second[100000 * 3 + 1];
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  g.resize(n + 1);
  for (size_t i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    type[i] = t;
    first[i] = u;
    second[i] = v;
    g[u].push_back(make_pair(v, i));
    if (t == 2) {
      g[v].push_back(make_pair(u, i));
    }
  }
  queue<int> q;
  vector<char> ans;
  int count = 0;
  ans.assign(m + 1, ' ');
  q.push(s);
  vector<bool> used(n + 1);
  used.assign(n + 1, false);
  used[s] = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    count++;
    for (size_t i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int ind = g[v][i].second;
      if (!used[to]) {
        q.push(to);
        used[to] = true;
        if (type[ind] == 2)
          if (first[ind] == v)
            ans[ind] = '+';
          else
            ans[ind] = '-';
      }
    }
  }
  cout << count << endl;
  for (size_t i = 0; i <= m; i++) {
    if (type[i] == 2) cout << (ans[i] == ' ' ? '-' : ans[i]);
  }
  cout << endl;
  count = 0;
  ans.assign(m + 1, ' ');
  q.push(s);
  used.assign(n + 1, false);
  used[s] = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    count++;
    for (size_t i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int ind = g[v][i].second;
      if (type[ind] == 2) {
        if (type[ind] == 2)
          if (first[ind] == to)
            ans[ind] = '+';
          else
            ans[ind] = '-';
      }
      if (!used[to] && type[ind] == 1) {
        q.push(to);
        used[to] = true;
      }
    }
  }
  cout << count << endl;
  for (size_t i = 0; i <= m; i++) {
    if (type[i] == 2) cout << (ans[i] == ' ' ? '-' : ans[i]);
  }
  cout << endl;
  return 0;
}
