#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 5;
int tot, head[maxn];
struct E {
  int w, to, next;
} edge[maxn << 1];
void add(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
int n, m, s;
set<pair<int, int> > S1;
map<pair<int, int>, int> mp1;
map<pair<int, int>, char> mpchar1;
vector<pair<int, int> > vec1;
int vis1[maxn], cnt1;
void dfs1(int x) {
  vis1[x] = true;
  cnt1 += 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis1[v] && edge[i].w == 1) {
      vis1[v] = 1;
      dfs1(v);
    }
    if (!vis1[v] && edge[i].w == 2 && mp1[{x, v}] == 0 && mp1[{v, x}] == 0) {
      vis1[v] = 1;
      mp1[{x, v}] = mp1[{v, x}] = 1;
      if (S1.count({x, v}))
        mpchar1[{x, v}] = '+';
      else if (!S1.count({x, v}))
        mpchar1[{v, x}] = '-';
      dfs1(v);
    }
  }
}
set<pair<int, int> > S2;
map<pair<int, int>, int> mp2;
map<pair<int, int>, char> mpchar2;
vector<pair<int, int> > vec2;
int vis2[maxn], cnt2;
void dfs2(int x) {
  vis2[x] = true;
  cnt2 += 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    int v = edge[i].to;
    if (!vis2[v] && edge[i].w == 1) {
      vis2[v] = 1;
      dfs2(v);
    }
    if (!vis2[v] && edge[i].w == 2 && mp2[{x, v}] == 0 && mp2[{v, x}] == 0) {
      mp2[{x, v}] = mp2[{v, x}] = 1;
      if (S2.count({x, v}))
        mpchar2[{x, v}] = '-';
      else if (!S2.count({x, v}))
        mpchar2[{v, x}] = '+';
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  memset(head, -1, sizeof(head));
  while (m--) {
    int u, v, w;
    scanf("%d%d%d", &w, &u, &v);
    if (w == 1)
      add(u, v, w);
    else {
      add(u, v, w);
      add(v, u, w);
      mp1[{u, v}] = mp1[{v, u}] = 0;
      vec1.push_back({u, v});
      S1.insert({u, v});
      mpchar1[{u, v}] = '+';
      mp2[{u, v}] = mp2[{v, u}] = 0;
      vec2.push_back({u, v});
      S2.insert({u, v});
      mpchar2[{u, v}] = '+';
    }
  }
  dfs1(s);
  printf("%d\n", cnt1);
  for (int i = 0; i < vec1.size(); i++) {
    cout << mpchar1[vec1[i]];
  }
  puts("");
  dfs2(s);
  printf("%d\n", cnt2);
  for (int i = 0; i < vec2.size(); i++) {
    cout << mpchar2[vec2[i]];
  }
  puts("");
}
