#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const long long int linf = 99999999999999999ll;
const int maxn = 5 * 1e5 + 100;
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
int n, m, s, t, u, v, vis[maxn], res, und;
vector<pair<pair<int, int>, pair<int, int> > > g[maxn];
char ans[maxn];
void dfs1(int s) {
  res++;
  vis[s] = 1;
  for (int i = 0; i < g[s].size(); i++) {
    if (!vis[g[s][i].first.first]) {
      if (g[s][i].second.second == 2) {
        if (g[s][i].first.second == -1) ans[g[s][i].second.first - 1] = '-';
      }
      dfs1(g[s][i].first.first);
    }
  }
}
void dfs2(int s) {
  res++;
  vis[s] = 1;
  for (int i = 0; i < g[s].size(); i++) {
    if (!vis[g[s][i].first.first]) {
      if (g[s][i].second.second == 2) {
        if (g[s][i].first.second == 1) ans[g[s][i].second.first - 1] = '-';
      } else
        dfs2(g[s][i].first.first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    cin >> t >> u >> v;
    if (t == 1)
      g[u].push_back(make_pair(make_pair(v, 1), make_pair(maxn - 1, t)));
    else {
      und++;
      g[u].push_back(make_pair(make_pair(v, 1), make_pair(und, t)));
      g[v].push_back(make_pair(make_pair(u, -1), make_pair(und, t)));
    }
  }
  for (int i = 0; i < und; i++) ans[i] = '+';
  dfs1(s);
  cout << res << endl;
  cout << ans << endl;
  for (int i = 0; i < und; i++) ans[i] = '+';
  memset(vis, 0, sizeof(vis));
  res = 0;
  dfs2(s);
  cout << res << endl;
  cout << ans << endl;
  return 0;
}
