#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int num;
int head[maxn], vis[maxn], father[maxn << 2];
string str1, str2;
int t1, t2;
struct node {
  int k;
  int fr;
  int to;
} q[maxn];
struct Edge {
  int fr;
  int to;
  int nex;
} edge[maxn << 2];
void addedge(int fr, int to) {
  edge[num].nex = head[fr];
  edge[num].to = to;
  edge[num].fr = fr;
  head[fr] = num++;
}
void dfs1(int st, int rt) {
  t1++;
  vis[st] = 1;
  for (int i = head[st]; i != -1; i = edge[i].nex) {
    int to = edge[i].to;
    if (vis[to]) continue;
    dfs1(to, st);
  }
}
void dfs2(int st, int rt) {
  t2++;
  vis[st] = 1;
  father[st] = rt;
  for (int i = head[st]; i != -1; i = edge[i].nex) {
    int to = edge[i].to;
    if (vis[to]) continue;
    dfs2(to, st);
  }
}
int main() {
  int n, m, s;
  scanf("%d %d %d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &q[i].k, &q[i].fr, &q[i].to);
  }
  num = 0;
  memset(head, -1, sizeof(head));
  for (int i = 1; i <= m; i++) {
    if (q[i].k == 1) {
      addedge(q[i].fr, q[i].to);
    }
  }
  dfs1(s, -1);
  for (int i = 1; i <= m; i++) {
    if (q[i].k == 2) {
      if (vis[q[i].fr])
        str1 += '-';
      else
        str1 += '+';
    }
  }
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) {
    if (q[i].k == 1) continue;
    addedge(q[i].fr, q[i].to);
    addedge(q[i].to, q[i].fr);
  }
  dfs2(s, -1);
  for (int i = 1; i <= m; i++) {
    if (q[i].k == 1) continue;
    if (father[q[i].to] == q[i].fr) {
      str2 += '+';
    } else
      str2 += '-';
  }
  cout << t2 << endl;
  cout << str2 << endl;
  cout << t1 << endl;
  cout << str1 << endl;
  return 0;
}
