#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
vector<int> G[N], g[N];
int v[N];
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  vector<pair<int, int>> undir;
  for (int i = 1; i <= m; ++i) {
    int u, v, t;
    scanf("%d%d%d", &t, &u, &v);
    if (t == 1) {
      G[u].push_back(v);
    } else {
      undir.push_back({u, v});
      g[u].push_back(v);
      g[v].push_back(u);
    }
  }
  queue<int> q;
  q.push(s);
  int vis = 0;
  v[s] = 1;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    vis++;
    for (int u : G[p]) {
      if (!v[u]) {
        q.push(u);
        v[u] = 1;
      }
    }
  }
  int ans_min = vis;
  string str_min;
  for (auto e : undir) {
    if (v[e.first] && !v[e.second]) {
      str_min += '-';
    } else {
      str_min += '+';
    }
  }
  fill(v + 1, v + 1 + n, 0);
  q.push(s);
  vis = 0;
  v[s] = 1;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    vis++;
    for (int u : G[p]) {
      if (!v[u]) {
        q.push(u);
        v[u] = v[p] + 1;
      }
    }
    for (int u : g[p]) {
      if (!v[u]) {
        q.push(u);
        v[u] = v[p] + 1;
      }
    }
  }
  int ans_max = vis;
  string str_max;
  for (auto e : undir) {
    if (v[e.first] > v[e.second]) {
      str_max += '-';
    } else {
      str_max += '+';
    }
  }
  printf("%d\n%s\n", ans_max, str_max.c_str());
  printf("%d\n%s\n", ans_min, str_min.c_str());
}
