#include <bits/stdc++.h>
static void dfs_max(std::vector<std::vector<int>> &v, std::vector<bool> &used,
                    std::map<std::pair<int, int>, bool> &map, int vertex,
                    int &count) {
  if (!used[vertex]) {
    count++;
    used[vertex] = true;
    for (int child : v[vertex]) {
      if (!used[child]) {
        dfs_max(v, used, map, child, count);
        map[{vertex, child}] = true;
      }
    }
  }
}
static void dfs_min(std::vector<std::vector<int>> &v, std::vector<bool> &used,
                    std::map<std::pair<int, int>, bool> &map,
                    std::map<std::pair<int, int>, bool> &eormap,
                    std::map<std::pair<int, int>, bool> &emap, int vertex,
                    int &count) {
  if (!used[vertex]) {
    count++;
    used[vertex] = true;
    for (int child : v[vertex]) {
      if (!used[child]) {
        if (eormap[{vertex, child}]) {
          if (emap[{vertex, child}])
            map[{vertex, child}] = true;
          else if (emap[{child, vertex}])
            map[{vertex, child}] = true;
          dfs_min(v, used, map, eormap, emap, child, count);
        } else if (emap[{vertex, child}])
          map[{child, vertex}] = true;
        else if (emap[{child, vertex}])
          map[{child, vertex}] = true;
        else
          dfs_min(v, used, map, eormap, emap, child, count);
      }
    }
  }
}
int main(int argc, const char *argv[]) {
  int n, m, s;
  std::cin >> n >> m >> s;
  std::vector<std::vector<int>> graph(n);
  std::vector<std::pair<int, int>> edges;
  std::map<std::pair<int, int>, bool> emap;
  std::map<std::pair<int, int>, bool> eormap;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    std::cin >> t >> u >> v;
    graph[u - 1].push_back(v - 1);
    if (t == 1) eormap[{u - 1, v - 1}] = true;
    if (t == 2) {
      graph[v - 1].push_back(u - 1);
      edges.push_back({u - 1, v - 1});
      emap[{u - 1, v - 1}] = true;
    }
  }
  std::vector<bool> used0(n);
  std::map<std::pair<int, int>, bool> result0;
  int count0 = 0;
  dfs_max(graph, used0, result0, s - 1, count0);
  std::cout << count0 << std::endl;
  for (std::pair<int, int> p : edges) {
    if (result0[p])
      std::cout << "+";
    else
      std::cout << "-";
  }
  std::cout << std::endl;
  std::vector<bool> used1(n);
  std::map<std::pair<int, int>, bool> result1;
  int count1 = 0;
  dfs_min(graph, used1, result1, eormap, emap, s - 1, count1);
  std::cout << count1 << std::endl;
  for (std::pair<int, int> p : edges) {
    if (result1[p])
      std::cout << "+";
    else
      std::cout << "-";
  }
  std::cout << std::endl;
  return 0;
}
