#include <bits/stdc++.h>
using namespace std;
const int M = 1024 * 512;
vector<int> V[M];
int zrob[2][M];
pair<int, int> E[M];
bool vis[2][M];
char R[2][M];
int n, k = 1, second, m, r[2];
int dir(int i, int v, int ind) {
  zrob[ind][i] = 1;
  if (E[i].first == max((v), -(v))) {
    if (v > 0) {
      R[ind][i] = '-';
      return v;
    } else {
      R[ind][i] = '+';
      return E[i].second;
    }
  } else {
    if (v < 0) {
      R[ind][i] = '-';
      return E[i].first;
    } else {
      R[ind][i] = '+';
      return E[i].second;
    }
  }
}
int DFSmi(int v, int ind) {
  vis[ind][v] = 1;
  int siz = 1;
  for (int i = 0; i < ((int)V[v].size()); i++) {
    if (V[v][i] > 0) {
      if (!vis[ind][V[v][i]]) {
        siz += DFSmi(V[v][i], ind);
      }
    } else {
      if (zrob[ind][-V[v][i]]) {
        continue;
      }
      dir(-V[v][i], v, ind);
    }
  }
  return siz;
}
int DFSma(int v, int ind) {
  vis[ind][v] = 1;
  int siz = 1;
  for (int i = 0; i < ((int)V[v].size()); i++) {
    if (V[v][i] > 0) {
      if (!vis[ind][V[v][i]]) {
        siz += DFSma(V[v][i], ind);
      }
    } else {
      if (zrob[ind][-V[v][i]]) {
        continue;
      }
      int u = dir(-V[v][i], -v, ind);
      if (!vis[ind][u]) {
        siz += DFSma(u, ind);
      }
    }
  }
  return siz;
}
int main() {
  scanf("%d%d%d", &n, &m, &second);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a == 1) {
      V[b].push_back(c);
    } else {
      E[k] = make_pair(b, c);
      V[b].push_back(-k);
      V[c].push_back(-k);
      k++;
    }
  }
  r[1] = DFSmi(second, 1);
  r[0] = DFSma(second, 0);
  for (int i = 0; i < 2; i++) {
    printf("%d\n", r[i]);
    for (int j = 1; j < k; j++) {
      if (R[i][j] != '+' && R[i][j] != '-') {
        printf("+");
      } else {
        printf("%c", R[i][j]);
      }
    }
    printf("\n");
  }
  return 0;
}
