#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
template<class T> inline void chkmax(T &x, const T &y) { if(x < y) x = y; }
template<class T> inline void chkmin(T &x, const T &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);
int n, m, s, c;
vector<pair<int, int> > adj[MAXN];
pair<int, int> def_ord[MAXN];
void read()
{
cin >> n >> m >> s;
c = 0;
for(int i = 0; i < m; i++)
{
int type, u, v;
cin >> type >> u >> v;
if(type == 2)
{
c++;
adj[u].push_back({v, c});
adj[v].push_back({u, c});
def_ord[c] = {u, v};
}
else adj[u].push_back({v, -1});
}
}
pair<int, int> ord[MAXN];
int answer = 0;
bool visited[MAXN];
void dfs(int u, bool mn)
{
answer++;
visited[u] = 1;
for(auto e: adj[u])
if(!visited[e.first])
{
int v = e.first;
if(e.second == -1) dfs(v, mn);
else
{
if(mn) ord[e.second] = {v, u};
else
{
ord[e.second] = {u, v};
dfs(v, mn);
}
}
}
}
void solve(bool mn)
{
answer = 0;
memset(visited, 0, sizeof(visited));
dfs(s, mn);
cout << answer << endl;
for(int i = 1; i <= c; i++)
if(ord[i] == def_ord[i]) cout << "+";
else cout << "-";
cout << endl;
}
void solve()
{
solve(0);
solve(1);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0ZW1wbGF0ZTxjbGFzcyBUPiBpbmxpbmUgdm9pZCBjaGttYXgoVCAmeCwgY29uc3QgVCAmeSkgeyBpZih4IDwgeSkgeCA9IHk7IH0KdGVtcGxhdGU8Y2xhc3MgVD4gaW5saW5lIHZvaWQgY2hrbWluKFQgJngsIGNvbnN0IFQgJnkpIHsgaWYoeCA+IHkpIHggPSB5OyB9CmNvbnN0IGludCBNQVhOID0gKDEgPDwgMjApOwoKaW50IG4sIG0sIHMsIGM7CnZlY3RvcjxwYWlyPGludCw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