#include <bits/stdc++.h>
using namespace std;
int maxn = 3 * 1e5 + 10;
vector<vector<int> > g(maxn);
vector<vector<int> > edges;
vector<int> used;
vector<int> dir;
int dfs(int x) {
  int ans = 1;
  used[x] = 1;
  for (auto id : g[x]) {
    if (edges[id][0] == 2) {
      if (edges[id][1] == x)
        dir[id] = 1;
      else
        dir[id] = 0;
      continue;
    }
    if (used[edges[id][2]]) continue;
    ans += dfs(edges[id][2]);
  }
  return ans;
}
int udfs(int x) {
  int ans = 1;
  used[x] = 1;
  for (auto id : g[x]) {
    if (edges[id][0] == 1 && !used[edges[id][2]]) {
      ans += udfs(edges[id][2]);
      continue;
    }
    if (edges[id][0] == 2) {
      if (edges[id][1] == x) {
        if (used[edges[id][2]]) continue;
        dir[id] = 0;
        ans += udfs(edges[id][2]);
      } else {
        if (used[edges[id][1]]) continue;
        dir[id] = 1;
        ans += udfs(edges[id][1]);
      }
    }
  }
  return ans;
}
void solve() {
  int n, m, second;
  cin >> n >> m >> second;
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    u--, v--;
    edges.push_back({t, u, v});
    g[u].push_back(i);
    if (t == 2) {
      cnt++;
      g[v].push_back(i);
    }
  }
  used = vector<int>(maxn, 0);
  dir = vector<int>(maxn, 0);
  cout << udfs(second - 1) << "\n";
  for (int i = 0; i < m; i++) {
    if (edges[i][0] == 2) cout << "+-"[dir[i]];
  }
  cout << "\n";
  used = vector<int>(maxn, 0);
  dir = vector<int>(maxn, 0);
  cout << dfs(second - 1) << "\n";
  for (int i = 0; i < m; i++) {
    if (edges[i][0] == 2) cout << "+-"[dir[i]];
  }
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  solve();
  return 0;
}
