#include <bits/stdc++.h>
using namespace std;
const int N = 300007;
int n, m, s, vis[N], cnt = 0;
struct edge {
  int u, v, type, ans;
} E[N];
vector<pair<int, int> > adj[N];
void bfs(int p) {
  queue<int> q;
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    cnt++;
    int u = q.front();
    q.pop();
    for (int i = 0; i < (int)adj[u].size(); i++) {
      int v = adj[u][i].first;
      int id = adj[u][i].second;
      if (E[id].type == 2) {
        if (p == 1 && vis[v] == 0) q.push(v), vis[v] = 1;
        if (E[id].ans != 0) continue;
        if ((p == 1 && u == E[id].u) || (p == 2 && v == E[id].u))
          E[id].ans = 1;
        else
          E[id].ans = 2;
      } else {
        if (vis[v] == 0) vis[v] = 1, q.push(v);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    cin >> E[i].type >> E[i].u >> E[i].v;
    if (E[i].type == 2) adj[E[i].v].push_back(make_pair(E[i].u, i));
    adj[E[i].u].push_back(make_pair(E[i].v, i));
  }
  cnt = 0;
  bfs(1);
  cout << cnt << "\n";
  for (int i = 1; i <= m; i++) {
    if (E[i].ans == 1)
      cout << "+";
    else if (E[i].ans == 2)
      cout << "-";
    else if (E[i].type == 2)
      cout << "-";
  }
  cout << "\n";
  cnt = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= m; i++) E[i].ans = 0;
  bfs(2);
  cout << cnt << "\n";
  for (int i = 1; i <= m; i++) {
    if (E[i].ans == 1)
      cout << "+";
    else if (E[i].ans == 2)
      cout << "-";
    else if (E[i].type == 2)
      cout << "-";
  }
  cout << "\n";
}
