#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long int M = 1000000007;
long long int inv(long long int a, long long int b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n;
  cin >> n;
  long long int m;
  cin >> m;
  long long int s;
  cin >> s;
  vector<vector<pair<long long int, long long int>>> graph(n);
  int t1 = 0;
  for (long long int i = 0; i < (m); i++) {
    long long int t;
    cin >> t;
    long long int x;
    cin >> x;
    long long int y;
    cin >> y;
    x--;
    y--;
    graph[x].push_back(make_pair(y, t == 2 ? ++t1 : 0));
    if (t == 2) graph[y].push_back(make_pair(x, -t1));
  }
  char res[t1 + 1];
  fill(res, res + t1 + 1, '?');
  queue<long long int> q;
  q.push(s - 1);
  bool visited[n];
  fill(visited, visited + n, false);
  long long int num = 0;
  while (!q.empty()) {
    long long int cur = q.front();
    q.pop();
    if (visited[cur]) continue;
    visited[cur] = true;
    num++;
    for (long long int i = 0; i < (graph[cur].size()); i++) {
      pair<long long int, long long int> next = graph[cur][i];
      if (next.second != 0) {
        long long int check = abs(next.second);
        if (res[check] == '?') {
          if (next.second < 0) {
            res[check] = '-';
          } else {
            res[check] = '+';
          }
          q.push(next.first);
        } else if ((res[check] == '+' && next.second > 0) ||
                   (res[check] == '-' && next.second < 0)) {
          q.push(next.first);
        }
      } else {
        q.push(next.first);
      }
    }
  }
  cout << num << endl;
  for (long long int i = 0; i < (t1); i++)
    cout << (res[i + 1] == '?' ? '+' : res[i + 1]);
  cout << endl;
  fill(res, res + t1 + 1, '?');
  q.push(s - 1);
  fill(visited, visited + n, false);
  num = 0;
  while (!q.empty()) {
    long long int cur = q.front();
    q.pop();
    if (visited[cur]) continue;
    visited[cur] = true;
    num++;
    for (long long int i = 0; i < (graph[cur].size()); i++) {
      pair<long long int, long long int> next = graph[cur][i];
      if (next.second != 0) {
        long long int check = abs(next.second);
        if (res[check] == '?') {
          if (next.second < 0) {
            res[check] = '+';
          } else {
            res[check] = '-';
          }
        } else if ((res[check] == '+' && next.second > 0) ||
                   (res[check] == '-' && next.second < 0)) {
          q.push(next.first);
        }
      } else {
        q.push(next.first);
      }
    }
  }
  cout << num << endl;
  for (long long int i = 0; i < (t1); i++)
    cout << (res[i + 1] == '?' ? '+' : res[i + 1]);
  cout << endl;
}
