#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, s;
  cin >> n >> m >> s;
  ;
  vector<vector<pair<int, pair<int, int> > > > g(n + 1);
  vector<int> reqd;
  for (int i = 0; i < m; i++) {
    int t, a, b;
    cin >> t >> a >> b;
    if (t == 2) {
      g[a].push_back(make_pair(b, make_pair(2, i + 1)));
      g[b].push_back(make_pair(a, make_pair(3, i + 1)));
      reqd.push_back(i + 1);
    } else {
      g[a].push_back(make_pair(b, make_pair(1, i + 1)));
    }
  }
  queue<int> q;
  q.push(s);
  int r = 0;
  vector<int> vis(n + 1, 0);
  vis[s] = 1;
  vector<char> red(m + 1, '?');
  while (!q.empty()) {
    r++;
    int d = q.front();
    q.pop();
    vector<pair<int, pair<int, int> > >::iterator it = g[d].begin();
    for (; it != g[d].end(); it++) {
      if (!vis[it->first]) {
        vis[it->first] = 1;
        if (it->second.first == 1) {
          q.push(it->first);
        } else if (it->second.first == 2) {
          red[it->second.second] = '+';
          q.push(it->first);
        } else {
          red[it->second.second] = '-';
          q.push(it->first);
        }
      }
    }
  }
  cout << r << "\n";
  int u = 0;
  for (int i = 1; i <= m; i++) {
    if (red[i] != '?') {
      cout << red[i];
      u++;
    } else {
      if (u < reqd.size() && reqd[u] == i) {
        cout << '+';
        u++;
      }
    }
  }
  r = 0;
  vis.clear();
  vis.resize(n + 1, 0);
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    r++;
    int d = q.front();
    q.pop();
    vector<pair<int, pair<int, int> > >::iterator it = g[d].begin();
    for (; it != g[d].end(); it++) {
      if (!vis[it->first]) {
        if (it->second.first == 1) {
          vis[it->first] = 1;
          q.push(it->first);
        } else if (it->second.first == 2) {
          red[it->second.second] = '-';
        } else {
          red[it->second.second] = '+';
        }
      }
    }
  }
  cout << "\n" << r << "\n";
  u = 0;
  for (int i = 1; i <= m; i++) {
    if (red[i] != '?') {
      u++;
      cout << red[i];
    } else {
      if (u < reqd.size() && reqd[u] == i) {
        cout << '+';
        u++;
      }
    }
  }
  return 0;
}
