#include <bits/stdc++.h>
using namespace std;
int dfs1(int v, vector<bool> &used, vector<vector<int> > &List,
         vector<vector<int> > &Ind, vector<vector<int> > &Type,
         vector<int> &Res) {
  int ans = 1;
  used[v] = true;
  for (int i = 0; i < List[v].size(); ++i) {
    if (!used[List[v][i]]) {
      ans += dfs1(List[v][i], used, List, Ind, Type, Res);
      if (Type[v][i] == 1) {
        Res[Ind[v][i]] = 1;
      } else if (Type[v][i] == 2) {
        Res[Ind[v][i]] = 0;
      }
    }
  }
  return ans;
}
int dfs2(int v, vector<bool> &used, vector<vector<int> > &List,
         vector<vector<int> > &Ind, vector<vector<int> > &Type,
         vector<int> &Res) {
  int ans = 1;
  used[v] = true;
  for (int i = 0; i < List[v].size(); ++i) {
    if (!used[List[v][i]]) {
      if (Type[v][i] == 0)
        ans += dfs2(List[v][i], used, List, Ind, Type, Res);
      else if (Type[v][i] == 1) {
        Res[Ind[v][i]] = 0;
      } else if (Type[v][i] == 2) {
        Res[Ind[v][i]] = 1;
      }
    }
  }
  return ans;
}
int main() {
  int n, m, s;
  cin >> n >> m >> s;
  --s;
  vector<vector<int> > List(n);
  vector<vector<int> > Ind(n);
  vector<vector<int> > Type(n);
  vector<pair<int, int> > EO;
  vector<pair<int, int> > EN;
  for (int i = 0; i < m; ++i) {
    int t, u, v;
    cin >> t >> u >> v;
    --u;
    --v;
    if (t == 1) {
      List[u].push_back(v);
      Ind[u].push_back(EO.size());
      Type[u].push_back(0);
      EO.push_back({u, v});
    } else {
      List[u].push_back(v);
      Ind[u].push_back(EN.size());
      Type[u].push_back(1);
      List[v].push_back(u);
      Ind[v].push_back(EN.size());
      Type[v].push_back(2);
      EN.push_back({u, v});
    }
  }
  {
    vector<bool> used(n);
    vector<int> P1(EN.size(), -1);
    cout << dfs1(s, used, List, Ind, Type, P1) << endl;
    ;
    for (int i = 0; i < P1.size(); ++i) {
      if (P1[i] != 0) {
        cout << '+';
      } else {
        cout << '-';
      }
    }
    cout << endl;
  }
  {
    vector<bool> used(n);
    vector<int> P2(EN.size(), -1);
    cout << dfs2(s, used, List, Ind, Type, P2) << endl;
    ;
    for (int i = 0; i < P2.size(); ++i) {
      if (P2[i] != 0) {
        cout << '+';
      } else {
        cout << '-';
      }
    }
    cout << endl;
  }
}
