#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
const long long int N = 5e5 + 10;
long long int vis[N], ans_max, ans_min;
map<long long int, pair<long long int, long long int> > number;
map<pair<long long int, long long int>, long long int> dir;
map<pair<long long int, long long int>, long long int> undir;
map<pair<long long int, long long int>, long long int> res;
vector<long long int> v[N];
long long int n, mi, s;
void maxi(long long int node, long long int parent) {
  ans_max++;
  vis[node] = 1;
  long long int i;
  for (i = 0; i < v[node].size(); i++) {
    long long int child = v[node][i];
    long long int x = node;
    long long int y = child;
    if (child == parent) continue;
    if (vis[child] == 0) {
      if (undir.find(make_pair(x, y)) != undir.end()) {
        res[make_pair(x, y)] = 1;
        res[make_pair(y, x)] = -1;
      }
      maxi(child, node);
    }
  }
}
void mini(long long int node, long long int parent) {
  ans_min++;
  vis[node] = 1;
  long long int i;
  for (i = 0; i < v[node].size(); i++) {
    long long int child = v[node][i];
    long long int x = node;
    long long int y = child;
    if (child == parent) continue;
    if (vis[child] == 0) {
      if (undir.find(make_pair(x, y)) != undir.end()) {
        res[make_pair(x, y)] = -1;
        res[make_pair(y, x)] = 1;
      }
      if (dir.find(make_pair(x, y)) != dir.end()) {
        mini(child, node);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> mi >> s;
  long long int t, x, y, i;
  long long int cnt = 0;
  for (i = 1; i <= mi; i++) {
    cin >> t >> x >> y;
    if (t == 1) {
      v[x].push_back(y);
      dir[make_pair(x, y)] = 1;
    } else {
      v[x].push_back(y);
      v[y].push_back(x);
      cnt++;
      number[cnt] = make_pair(x, y);
      undir[make_pair(x, y)] = 1;
      undir[make_pair(y, x)] = 1;
    }
  }
  memset(vis, 0, sizeof(vis));
  maxi(s, -1);
  cout << ans_max << endl;
  for (i = 1; i <= cnt; i++) {
    pair<long long int, long long int> tmp = number[i];
    if (res[tmp] == 1)
      cout << "+";
    else
      cout << "-";
  }
  cout << endl;
  memset(vis, 0, sizeof(vis));
  mini(s, -1);
  cout << ans_min << endl;
  for (i = 1; i <= cnt; i++) {
    pair<long long int, long long int> tmp = number[i];
    if (res[tmp] == 1)
      cout << "+";
    else
      cout << "-";
  }
  cout << endl;
  return 0;
}
