#include <bits/stdc++.h>
using namespace std;
struct edge {
  int t, u, v, id;
};
int n, m, s;
vector<edge> e[300010];
bool vis1[300010], vis2[300010];
int ct1, ct2;
int o1[300010], o2[300010];
int tt[300010];
void dfs1(int x) {
  if (vis1[x]) return;
  ct1++;
  vis1[x] = 1;
  for (auto& ee : e[x]) {
    int y = ee.u + ee.v - x;
    if (ee.t == 2) {
      if (!vis1[y]) {
        o1[ee.id] = ee.u != x;
        dfs1(y);
      }
    } else if (ee.u == x) {
      dfs1(y);
    }
  }
}
void dfs2(int x) {
  if (vis2[x]) return;
  ct2++;
  vis2[x] = 1;
  for (auto& ee : e[x]) {
    int y = ee.u + ee.v - x;
    if (ee.t == 2) {
      o2[ee.id] = ee.u == x;
    } else if (ee.u == x) {
      dfs2(y);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    e[u].push_back({t, u, v, i});
    e[v].push_back({t, u, v, i});
    tt[i] = t;
  }
  dfs1(s);
  dfs2(s);
  cout << ct1 << '\n';
  for (int i = 0; i < m; i++) {
    if (tt[i] == 1) continue;
    cout << (o1[i] ? '-' : '+');
  }
  cout << '\n';
  cout << ct2 << '\n';
  for (int i = 0; i < m; i++) {
    if (tt[i] == 1) continue;
    cout << (o2[i] ? '-' : '+');
  }
  cout << '\n';
}
