#include <bits/stdc++.h>
using namespace std;
vector<int> V[600010];
int ans[600010], vis[600010];
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
struct node {
  int got, num, dir;
  inline node(int tmp1 = 0, int tmp2 = 0, int tmp3 = 0) {
    got = tmp1, num = tmp2, dir = tmp3;
  }
};
vector<node> v[600010];
inline void solve1(int n, int m, int s, int t) {
  int cnt = 1;
  queue<int> q;
  memset(ans, 0, sizeof(ans));
  memset(vis, 0, sizeof(vis));
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = true;
    for (int i = 0; i < V[x].size(); i++) {
      int y = V[x][i];
      if (!vis[y]) {
        ++cnt, q.push(y), vis[y] = true;
      }
    }
    for (int i = 0; i < v[x].size(); i++) {
      int got = v[x][i].got, num = v[x][i].num, val = v[x][i].dir;
      if (!vis[got] && ans[num] != -val) {
        ans[num] = val, ++cnt, vis[got] = true, q.push(got);
      }
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= t; i++) {
    putchar(ans[i] == 1 ? '+' : '-');
  }
  putchar('\n');
}
inline void solve2(int n, int m, int s, int t) {
  int cnt = 1;
  queue<int> q;
  memset(ans, 0, sizeof(ans));
  memset(vis, 0, sizeof(vis));
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    vis[x] = true;
    for (int i = 0; i < V[x].size(); i++) {
      int y = V[x][i];
      if (!vis[y]) {
        ++cnt, q.push(y), vis[y] = true;
      }
    }
    for (int i = 0; i < v[x].size(); i++) {
      int num = v[x][i].num, val = v[x][i].dir;
      if (ans[num] != val) ans[num] = -val;
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= t; i++) {
    putchar(ans[i] == 1 ? '+' : '-');
  }
  putchar('\n');
}
int main() {
  int tot = 0;
  int n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int opt = read(), x = read(), y = read();
    if (opt == 1) V[x].push_back(y);
    if (opt == 2) {
      ++tot;
      v[x].push_back(node(y, tot, 1));
      v[y].push_back(node(x, tot, -1));
    }
  }
  solve1(n, m, s, tot), solve2(n, m, s, tot);
  return 0;
}
