#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
struct Edge {
  int to, nxt;
  bool valid;
} ini_edge[maxn * 2];
int ini_head[maxn];
int tot;
void addedge(int u, int v, bool valid) {
  ini_edge[tot].to = v;
  ini_edge[tot].nxt = ini_head[u];
  ini_edge[tot].valid = valid;
  ini_head[u] = tot;
  ++tot;
}
int head[maxn];
Edge edge[maxn * 2];
int n;
bool vis[maxn];
void copy() {
  for (int i = 1; i <= n; i++) head[i] = ini_head[i];
  for (int i = 0; i < tot; i++) edge[i] = ini_edge[i];
}
queue<int> q;
bool v[maxn];
int bfs1(int s) {
  while (!q.empty()) q.pop();
  memset(v, false, sizeof(v));
  q.push(s);
  v[s] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = edge[i].nxt) {
      int to = edge[i].to;
      if (!v[to] && edge[i].valid) {
        v[to] = true;
        edge[i ^ 1].valid = false;
        q.push(to);
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (v[i]) cnt++;
  return cnt;
}
int bfs2(int s) {
  while (!q.empty()) q.pop();
  memset(v, false, sizeof(v));
  q.push(s);
  v[s] = true;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = edge[i].nxt) {
      int to = edge[i].to;
      if (edge[i].valid && edge[i ^ 1].valid) edge[i].valid = false;
      if (!v[to] && edge[i].valid) {
        v[to] = true;
        edge[i ^ 1].valid = false;
        q.push(to);
      }
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (v[i]) cnt++;
  return cnt;
}
int main() {
  memset(ini_head, -1, sizeof(ini_head));
  int m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; i++) {
    int t, u, v;
    scanf("%d%d%d", &t, &u, &v);
    if (t == 1) {
      addedge(u, v, true);
      addedge(v, u, false);
    } else {
      addedge(u, v, true);
      addedge(v, u, true);
      vis[i] = true;
    }
  }
  copy();
  printf("%d\n", bfs1(s));
  for (int i = 0; i < tot; i += 2) {
    if (vis[i >> 1]) {
      if (edge[i].valid)
        putchar('+');
      else
        putchar('-');
    }
  }
  printf("\n");
  copy();
  printf("%d\n", bfs2(s));
  for (int i = 0; i < tot; i += 2) {
    if (vis[i >> 1]) {
      if (edge[i].valid)
        putchar('+');
      else
        putchar('-');
    }
  }
  printf("\n");
  return 0;
}
