#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
struct EDGE {
  int to, next;
  int id;
  EDGE() {}
  EDGE(int to, int next, int id) : to(to), next(next), id(id) {}
} edge[maxn * 2];
int type[maxn];
char ans[maxn];
int head[maxn], edgecnt;
bool vis[maxn];
void add(int s, int t, int id) {
  edge[edgecnt] = EDGE(t, head[s], id);
  head[s] = edgecnt++;
}
int m;
int x[maxn];
void init() {
  edgecnt = 0;
  memset(head, -1, sizeof(head));
}
int bfs1(int st) {
  queue<int> q;
  q.push(st);
  memset(ans, -1, sizeof(ans));
  memset(vis, 0, sizeof(vis));
  int cnt = 0;
  vis[st] = 1;
  while (!q.empty()) {
    cnt++;
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = edge[i].next) {
      int v = edge[i].to;
      if (type[edge[i].id] == 1) {
        ans[edge[i].id] = '+';
        if (vis[v]) continue;
        vis[v] = 1;
        q.push(v);
      } else {
        if (vis[v]) continue;
        if (x[edge[i].id] == u)
          ans[edge[i].id] = '+';
        else
          ans[edge[i].id] = '-';
        vis[v] = 1;
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= m; i++)
    if (ans[i] == -1) ans[i] = '+';
  return cnt;
}
int bfs2(int st) {
  queue<int> q;
  q.push(st);
  memset(ans, -1, sizeof(ans));
  memset(vis, 0, sizeof(vis));
  int cnt = 0;
  vis[st] = 1;
  while (!q.empty()) {
    cnt++;
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = edge[i].next) {
      int v = edge[i].to;
      if (type[edge[i].id] == 1) {
        ans[edge[i].id] = '+';
        if (vis[v]) continue;
        vis[v] = 1;
        q.push(v);
      } else {
        if (u == x[edge[i].id])
          ans[edge[i].id] = '-';
        else
          ans[edge[i].id] = '+';
      }
    }
  }
  for (int i = 1; i <= m; i++)
    if (ans[i] == -1) ans[i] = '+';
  return cnt;
}
int main() {
  init();
  int n, st;
  scanf("%d %d %d", &n, &m, &st);
  for (int i = 1; i <= m; i++) {
    int y;
    scanf("%d %d %d", &type[i], &x[i], &y);
    add(x[i], y, i);
    if (type[i] == 2) add(y, x[i], i);
  }
  int ret = bfs1(st);
  printf("%d\n", ret);
  for (int i = 1; i <= m; i++)
    if (type[i] == 2) putchar(ans[i]);
  printf("\n");
  ret = bfs2(st);
  printf("%d\n", ret);
  for (int i = 1; i <= m; i++)
    if (type[i] == 2) putchar(ans[i]);
  printf("\n");
  return 0;
}
