#include <bits/stdc++.h>
const int INF = 2 * 1e9;
const long long int MOD = 1000000007;
using namespace std;
vector<int> was;
int n, m, s;
vector<vector<pair<int, int>>> p;
vector<pair<int, int>> v;
map<pair<int, int>, int> ma;
map<pair<int, int>, int> ms;
int dfs(int x) {
  int ans = 1;
  was[x] = 0;
  for (pair<int, int> y : p[x]) {
    if (was[y.second] == -1) {
      if (y.first) ma[{x, y.second}] = 1;
      ans += dfs(y.second);
    }
  }
  was[x] = ans;
  return was[x];
}
int dfs2(int x) {
  int ans = 1;
  was[x] = 0;
  for (pair<int, int> y : p[x]) {
    if (was[y.second] == -1) {
      if (y.first) {
        ms[{y.second, x}] = 1;
        continue;
      }
      ans += dfs2(y.second);
    }
  }
  was[x] = ans;
  return was[x];
}
void solve() {
  cin >> n >> m >> s;
  was.assign(n, -1);
  p.resize(n);
  for (int(i) = 0; (i) < (m); (i)++) {
    int f, x, y;
    cin >> f >> x >> y;
    f--;
    x--;
    y--;
    if (f) {
      v.push_back({x, y});
      p[y].push_back({f, x});
    }
    p[x].push_back({f, y});
  }
  s--;
  string ans;
  cout << dfs(s) << '\n';
  for (auto x : v) {
    if (ma.count(x)) {
      ans.push_back('+');
      continue;
    }
    if (ma.count({x.second, x.first})) {
      ans.push_back('-');
      continue;
    }
    ans.push_back('+');
  }
  was.assign(n, -1);
  cout << ans << '\n' << dfs2(s) << '\n';
  ans.clear();
  for (auto x : v) {
    if (ms.count(x)) {
      ans.push_back('+');
      continue;
    }
    if (ms.count({x.second, x.first})) {
      ans.push_back('-');
      continue;
    }
    ans.push_back('+');
  }
  cout << ans;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.fixed;
  cout.precision(12);
  solve();
  return 0;
}
