#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int n, m, s, idx, tot;
int ea[333333 * 2], eb[333333 * 2], ed[333333 * 2], ec[333333], vis[333333],
    tag[333333 * 2], cnt[333333 * 2], oud[333333 * 2];
void add(int x, int y, int z) {
  tot++;
  ea[tot] = y;
  eb[tot] = ec[x];
  ec[x] = tot;
  ed[tot] = z;
}
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void solve1() {
  memset(vis, 0, sizeof(vis));
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = ec[x]; i; i = eb[i]) {
      int v = ea[i];
      if (ed[i]) {
        if (ed[i] == 1)
          oud[cnt[i]] = 0;
        else
          oud[cnt[i]] = 1;
        continue;
      }
      if (!vis[v]) {
        q.push(v);
        vis[v] = 1;
      }
    }
  }
  int cnts = 0;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) cnts++;
  }
  cout << cnts << endl;
  for (int i = 1; i <= idx; ++i) {
    if (oud[i])
      putchar('+');
    else
      putchar('-');
  }
  putchar('\n');
}
void solve2() {
  memset(vis, 0, sizeof(vis));
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = ec[x]; i; i = eb[i]) {
      int v = ea[i];
      if (!vis[v]) {
        q.push(v);
        vis[v] = 1;
        if (ed[i]) tag[i] = 1;
      }
    }
  }
  int cnts = 0;
  for (int i = 1; i <= n; ++i) {
    if (vis[i]) cnts++;
  }
  cout << cnts << endl;
  for (int i = 1; i <= tot; ++i) {
    if (tag[i] == 1) {
      if (ed[i] == 1)
        oud[cnt[i]] = 1;
      else
        oud[cnt[i]] = 0;
    }
  }
  for (int i = 1; i <= idx; ++i) {
    if (oud[i])
      putchar('+');
    else
      putchar('-');
  }
  putchar('\n');
  memset(oud, 0, sizeof(oud));
}
int main() {
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; ++i) {
    int op = read(), x = read(), y = read();
    if (op == 1) {
      add(x, y, 0);
    } else {
      add(x, y, 1);
      cnt[tot] = ++idx;
      add(y, x, 2);
      cnt[tot] = idx;
    }
  }
  solve2();
  solve1();
  return 0;
}
