#include <bits/stdc++.h>
using namespace std;
struct box {
  int da, n;
};
int a, b, c, d, e, f, ans[300007];
bool qw[300007], qw2[300007];
box x;
vector<box> q[300007];
int get1(int x2) {
  if (x2 > b) return x2 - b;
  return x2;
}
void sou1(int x1) {
  e++;
  qw[x1] = true;
  for (int i = 0; i < q[x1].size(); i++) {
    if (q[x1][i].n > 0 && ans[get1(q[x1][i].n)] == 0)
      if (q[x1][i].n > b)
        ans[q[x1][i].n - b] = 2;
      else
        ans[q[x1][i].n] = 1;
    if (!qw[q[x1][i].da]) sou1(q[x1][i].da);
  }
}
void sou2(int x1) {
  e++;
  qw[x1] = true;
  for (int i = 0; i < q[x1].size(); i++) {
    if (q[x1][i].n > 0 && ans[get1(q[x1][i].n)] == 0) {
      if (q[x1][i].n > b)
        ans[q[x1][i].n - b] = 1;
      else
        ans[q[x1][i].n] = 2;
      continue;
    }
    if (!qw[q[x1][i].da]) sou2(q[x1][i].da);
  }
}
int main() {
  scanf("%d%d%d", &a, &b, &c);
  for (int i = 1; i <= a; i++) qw2[i] = 0;
  for (int i = 1; i <= b; i++) {
    scanf("%d%d%d", &d, &e, &f);
    if (d == 1) {
      x.da = f;
      x.n = 0;
      q[e].push_back(x);
    } else {
      x.da = f;
      x.n = i;
      q[e].push_back(x);
      x.da = e;
      x.n = b + i;
      q[f].push_back(x);
      qw2[i] = 1;
    }
  }
  for (int i = 1; i <= b; i++) ans[i] = 0;
  for (int i = 1; i <= a; i++) qw[i] = 0;
  e = 0;
  sou1(c);
  printf("%d\n", e);
  for (int i = 1; i <= b; i++)
    if (qw2[i])
      if (ans[i] == 2)
        printf("-");
      else
        printf("+");
  printf("\n");
  for (int i = 1; i <= b; i++) ans[i] = 0;
  for (int i = 1; i <= a; i++) qw[i] = 0;
  e = 0;
  sou2(c);
  printf("%d\n", e);
  for (int i = 1; i <= b; i++)
    if (qw2[i])
      if (ans[i] == 2)
        printf("-");
      else
        printf("+");
  return 0;
}
