#include <bits/stdc++.h>
using namespace std;
struct ed {
  int t;
  int u;
  int v;
  int pos;
};
int n, m, s;
vector<pair<int, ed> > v[400000];
queue<int> q;
ed lis[400000];
int str[400000] = {0};
bool vis[400000] = {0};
int dfs1(int root) {
  vis[root] = 1;
  if (v[root].size() == 0) {
    return 1;
  }
  int ch = 1;
  for (int i = 0; i < v[root].size(); i++) {
    int x = v[root][i].first;
    if (vis[x] == 0) {
      if (v[root][i].second.t == 2) {
        if (root == v[root][i].second.u) str[v[root][i].second.pos] = 1;
      }
      ch += dfs1(x);
    }
  }
  return ch;
}
void dfs2(int root) {
  vis[root] = 1;
  for (int i = 0; i < v[root].size(); i++) {
    int x = v[root][i].first;
    if (vis[x] == 0 && v[root][i].second.t == 1) {
      q.push(x);
      dfs2(x);
    }
  }
}
int main() {
  cin >> n >> m >> s;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int f, a, b;
    cin >> f >> a >> b;
    lis[i] = (ed){f, a, b, -1};
    if (f == 1) {
      v[a].push_back(make_pair(b, lis[i]));
    } else {
      lis[i].pos = cnt++;
      v[a].push_back(make_pair(b, lis[i]));
      v[b].push_back(make_pair(a, lis[i]));
    }
  }
  cout << dfs1(s) << endl;
  for (int i = 0; i < cnt; i++) {
    if (str[i] == 1)
      cout << '+';
    else
      cout << '-';
  }
  cout << endl;
  for (int i = 1; i < 400000; i++) vis[i] = 0;
  dfs2(s);
  q.push(s);
  int str2[400000] = {0};
  cout << q.size() << endl;
  while (q.size() != 0) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < v[x].size(); i++) {
      if (v[x][i].second.t == 2) {
        if (x != v[x][i].second.u) {
          str2[v[x][i].second.pos] = 1;
        }
      }
    }
  }
  for (int i = 0; i < cnt; i++) {
    if (str2[i] == 1)
      cout << '+';
    else
      cout << '-';
  }
  cout << endl;
  return 0;
}
