#include <bits/stdc++.h>
using namespace std;
vector<int> yx[300005], wx[300005];
vector<pair<int, int> > edge;
map<long long, int> M;
int fir[300005], sec[300005];
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = (0); i < (m); i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (a == 1)
      yx[b].push_back(c);
    else {
      edge.push_back(make_pair(b, c));
      wx[b].push_back(c);
      wx[c].push_back(b);
    }
  }
  fir[s] = sec[s] = 1;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int f = q.front();
    for (int i = (0); i < ((int)(yx[f]).size()); i++) {
      int nex = yx[f][i];
      if (!fir[nex]) {
        fir[nex] = sec[nex] = 1;
        q.push(nex);
      }
    }
    q.pop();
  }
  for (int i = (1); i < (n + 1); i++)
    if (fir[i]) q.push(i);
  while (!q.empty()) {
    int f = q.front();
    for (int i = (0); i < ((int)(wx[f]).size()); i++) {
      int nex = wx[f][i];
      if (!sec[nex]) {
        sec[nex] = 1;
        q.push(nex);
        long long hh = 1LL * f * 1000000 + nex;
        M[hh] = 1;
      }
    }
    for (int i = (0); i < ((int)(yx[f]).size()); i++) {
      int nex = yx[f][i];
      if (!sec[nex]) {
        sec[nex] = 1;
        q.push(nex);
      }
    }
    q.pop();
  }
  int ans = 0;
  for (int i = (1); i < (n + 1); i++) ans += sec[i];
  printf("%d\n", ans);
  for (int i = (0); i < ((int)(edge).size()); i++) {
    long long hh = 1LL * edge[i].first * 1000000 + edge[i].second;
    if (M[hh])
      printf("+");
    else
      printf("-");
  }
  puts("");
  ans = 0;
  for (int i = (1); i < (n + 1); i++) ans += fir[i];
  printf("%d\n", ans);
  M.clear();
  for (int i = (1); i < (n + 1); i++)
    if (fir[i])
      for (int j = (0); j < ((int)(wx[i]).size()); j++) {
        int nex = wx[i][j];
        long long hh = 1LL * nex * 1000000 + i;
        M[hh] = 1;
      }
  for (int i = (0); i < ((int)(edge).size()); i++) {
    long long hh = 1LL * edge[i].first * 1000000 + edge[i].second;
    if (M[hh])
      printf("+");
    else
      printf("-");
  }
  return 0;
}
