#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 7;
struct node {
  int y;
  int id;
};
vector<node> g[maxn];
int color[maxn];
bool vis[maxn];
int head[maxn], cnt;
void addedge(int x, int y, int id) { g[x].push_back({y, id}); }
int bfs1(int u) {
  queue<int> o;
  o.push(u);
  memset(vis, 0, sizeof(vis));
  int ans = 0;
  vis[u] = true;
  ans++;
  while (!o.empty()) {
    int x = o.front();
    o.pop();
    for (int i = 0; i < g[x].size(); i++) {
      int y = g[x][i].y;
      int id = g[x][i].id;
      if (vis[y]) continue;
      if (id != -1) {
        color[id / 2] = (id % 2);
      }
      o.push(y);
      vis[y] = true;
      ans++;
    }
  }
  return ans;
}
int bfs2(int u) {
  queue<int> o;
  o.push(u);
  memset(vis, 0, sizeof(vis));
  int ans = 0;
  ans++;
  vis[u] = true;
  while (!o.empty()) {
    int x = o.front();
    o.pop();
    for (int i = 0; i < g[x].size(); i++) {
      int y = g[x][i].y;
      int id = g[x][i].id;
      if (vis[y]) continue;
      if (id != -1) {
        color[id / 2] = 1 ^ (id % 2);
        continue;
      }
      o.push(y);
      vis[y] = true;
      ans++;
    }
  }
  return ans;
}
int main() {
  int n, m, s;
  cnt = 0;
  memset(head, -1, sizeof(head));
  int pos = 0;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    int op, u, v;
    scanf("%d%d%d", &op, &u, &v);
    if (op == 1) {
      addedge(u, v, -1);
    } else {
      addedge(u, v, pos);
      addedge(v, u, pos + 1);
      pos += 2;
    }
  }
  int ans1 = bfs1(s);
  cout << ans1 << endl;
  for (int i = 0; i < pos / 2; i++) {
    if (color[i])
      printf("-");
    else
      printf("+");
  }
  cout << endl;
  int ans2 = bfs2(s);
  cout << ans2 << endl;
  for (int i = 0; i < pos / 2; i++) {
    if (color[i])
      printf("-");
    else
      printf("+");
  }
  return 0;
}
