#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
vector<int> vec1[N];
vector<pair<int, int> > vec2[N];
vector<pair<int, int> > vec3[N];
bool light[N];
int elight[N];
int main() {
  int n, m, s, t, u, v;
  scanf("%d%d%d", &n, &m, &s);
  int top = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &t, &u, &v);
    if (t == 1)
      vec1[u].push_back(v);
    else {
      vec2[u].push_back(make_pair(v, top));
      vec3[v].push_back(make_pair(u, top));
      top++;
    }
  }
  queue<int> quu;
  quu.push(s);
  int cnt = 1;
  light[s] = true;
  while (!quu.empty()) {
    int u = quu.front();
    quu.pop();
    for (auto it : vec1[u])
      if (!light[it]) {
        light[it] = true;
        cnt++;
        quu.push(it);
      }
    for (auto it : vec2[u]) {
      if (!light[it.first] && elight[it.second] == 0) {
        light[it.first] = true;
        cnt++;
        elight[it.second] = 1;
        quu.push(it.first);
      }
    }
    for (auto it : vec3[u]) {
      if (!light[it.first] && elight[it.second] == 0) {
        light[it.first] = true;
        cnt++;
        elight[it.second] = -1;
        quu.push(it.first);
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < top; i++) {
    if (elight[i] == 1)
      printf("+");
    else
      printf("-");
  }
  memset(elight, 0, sizeof(elight));
  memset(light, 0, sizeof(light));
  quu.push(s);
  light[s] = true;
  cnt = 1;
  while (!quu.empty()) {
    int u = quu.front();
    quu.pop();
    for (auto it : vec1[u])
      if (!light[it]) {
        cnt++;
        light[it] = true;
        quu.push(it);
      }
    for (auto it : vec2[u])
      if (elight[it.second] == 0) elight[it.second] = -1;
    for (auto it : vec3[u])
      if (elight[it.second] == 0) elight[it.second] = 1;
  }
  printf("\n%d\n", cnt);
  for (int i = 0; i < top; i++) {
    if (elight[i] == 1)
      printf("+");
    else
      printf("-");
  }
  printf("\n");
  return 0;
}
