#include <bits/stdc++.h>
using namespace std;
int a, b, c, n, m, s, k = 0, T, head[3 * 100010], x[3 * 100010], ui[3 * 100010],
                      vi[3 * 100010], la[3 * 100010];
struct node {
  int u, v, Next;
} t[2 * 3 * 100010];
void add(int u, int v) {
  t[++k].u = u;
  t[k].v = v;
  t[k].Next = head[u];
  head[u] = k;
}
void bfs() {
  for (int i = 1; i <= n; i++) x[i] = 0;
  queue<int> q;
  q.push(s);
  x[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = t[i].Next) {
      int v = t[i].v;
      if (x[v] != 0) continue;
      x[v] = x[u] + 1;
      q.push(v);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &c, &a, &b);
    if (c == 2)
      add(a, b), add(b, a);
    else
      add(a, b);
    ui[i] = a, vi[i] = b;
    la[i] = c;
  }
  bfs();
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (x[i] != 0) ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= m; i++) {
    if (la[i] == 1) continue;
    if (x[ui[i]] > x[vi[i]])
      cout << '-';
    else
      cout << '+';
  }
  cout << endl;
  for (int i = 1; i <= n; i++) head[i] = 0;
  k = 0;
  for (int i = 1; i <= m; i++) {
    if (la[i] == 2) continue;
    add(ui[i], vi[i]);
  }
  bfs();
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if (x[i] != 0) ans++;
  }
  cout << ans << endl;
  for (int i = 1; i <= m; i++) {
    if (la[i] == 1) continue;
    if (x[ui[i]] > x[vi[i]])
      cout << '-';
    else
      cout << '+';
  }
}
