#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 200;
vector<pair<int, int> > E[MAXN];
int from[MAXN];
int type[MAXN];
int flag[MAXN];
int seen[MAXN];
int max_bfs(int source) {
  memset(seen, -1, sizeof seen);
  queue<int> Q;
  Q.push(source);
  seen[source] = 1;
  int answer = 0;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    answer++;
    for (int i = 0; i < E[v].size(); i++) {
      int to = E[v][i].first;
      int id = E[v][i].second;
      if (seen[to] == -1) {
        seen[to] = 1;
        Q.push(to);
        if (from[id] != v) {
          flag[id] = 1;
        }
      }
    }
  }
  return answer;
}
int min_bfs(int source) {
  memset(seen, -1, sizeof seen);
  queue<int> Q;
  Q.push(source);
  seen[source] = 1;
  int answer = 0;
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    answer++;
    for (int i = 0; i < E[v].size(); i++) {
      int to = E[v][i].first;
      int id = E[v][i].second;
      if (seen[to] == -1) {
        if (type[id] == 2) {
          if (from[id] == v) {
            flag[id] = 1;
          }
          continue;
        }
        seen[to] = 1;
        Q.push(to);
      }
    }
  }
  return answer;
}
int main() {
  ios::sync_with_stdio(0);
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    type[i] = t;
    E[u].push_back(make_pair(v, i));
    if (t == 2) {
      E[v].push_back(make_pair(u, i));
    }
    from[i] = u;
  }
  cout << max_bfs(s) << '\n';
  for (int i = 0; i < m; i++) {
    if (type[i] == 1) continue;
    if (flag[i])
      cout << '-';
    else
      cout << '+';
  }
  cout << endl;
  for (int i = 0; i < m; i++) flag[i] = 0;
  cout << min_bfs(s) << '\n';
  for (int i = 0; i < m; i++) {
    if (type[i] == 1) continue;
    if (flag[i])
      cout << '-';
    else
      cout << '+';
  }
  cout << endl;
  return 0;
}
