Vasya has a graph containing both directed (oriented) and undirected (non-oriented) edges. There can be multiple edges between a pair of vertices.

Vasya has picked a vertex s from the graph. Now Vasya wants to create two separate plans:

  1. to orient each undirected edge in one of two possible directions to maximize number of vertices reachable from vertex s; 
  2. to orient each undirected edge in one of two possible directions to minimize number of vertices reachable from vertex s. 



In each of two plans each undirected edge must become directed. For an edge chosen directions can differ in two plans.

Help Vasya find the plans.

Input

The first line contains three integers n, m and s (2 ≤ n ≤ 3·105, 1 ≤ m ≤ 3·105, 1 ≤ s ≤ n) — number of vertices and edges in the graph, and the vertex Vasya has picked.

The following m lines contain information about the graph edges. Each line contains three integers ti, ui and vi (1 ≤ ti ≤ 2, 1 ≤ ui, vi ≤ n, ui ≠ vi) — edge type and vertices connected by the edge. If ti = 1 then the edge is directed and goes from the vertex ui to the vertex vi. If ti = 2 then the edge is undirected and it connects the vertices ui and vi.

It is guaranteed that there is at least one undirected edge in the graph.

Output

The first two lines should describe the plan which maximizes the number of reachable vertices. The lines three and four should describe the plan which minimizes the number of reachable vertices.

A description of each plan should start with a line containing the number of reachable vertices. The second line of a plan should consist of f symbols '+' and '-', where f is the number of undirected edges in the initial graph. Print '+' as the j-th symbol of the string if the j-th undirected edge (u, v) from the input should be oriented from u to v. Print '-' to signify the opposite direction (from v to u). Consider undirected edges to be numbered in the same order they are given in the input.

If there are multiple solutions, print any of them.

Examples

Input

2 2 1
1 1 2
2 2 1


Output

2
-
2
+


Input

6 6 3
2 2 6
1 4 5
2 3 4
1 4 1
1 3 1
2 2 3


Output

6
++-
2
+-+
//import java.io.*;
//import java.util.*;
//import java.math.*;
//import java.awt.*;
//
//public class Main{
//
//	static final int maxn=50+10;
//	static final int maxm=1000+10;
//	static public void main(String[] args)
//	{
//		Scanner cin=new Scanner(new BufferedInputStream(System.in));
//		int n,m;
//		String[] str=new String[maxm];
//		boolean[] isinsp=new boolean[256];
//		String ps;
//		n=cin.nextInt();
//		ps=cin.next();
//		for(int i=0;i<n;i++){
//			if(ps.charAt(i)=='*')	continue;
//			else isinsp[(int)ps.charAt(i)]=true;
//		}
//		m=cin.nextInt();
//		for(int i=0;i<m;i++){
//			str[i]=cin.next();
//		}
//		boolean[] ismatch=new boolean[maxm];
//		boolean[] vis=new boolean[256];
//		for(int i=0;i<m;i++){
////			System.out.println(str[i]);
//			ismatch[i]=true;
//		}
//		for(int i=0;i<m;i++){
//			for(int j=0;j<256;j++){
//				vis[j]=false;
//			}
//			for(int j=0;j<n;j++){
//				if(ps.charAt(j)=='*'){
//					if(isinsp[(int)str[i].charAt(j)]){
//						ismatch[i]=false;
//						break;
//					}
//				}
//				else{
//					if(str[i].charAt(j)!=ps.charAt(j)){
//						ismatch[i]=false;
//						break;
//					}
//				}
//			}
//		}
//		int ans=0;
//		boolean can=true;
//		for(char ch='a';(int)ch<=(int)'z';ch++){
//			if(isinsp[(int)ch])	continue;
//			can=true;
//			for(int i=0;i<m;i++){
////				System.out.println(Integer.valueOf(i).toString()+" "+ismatch[i]);
//				if(ismatch[i]==false){
//					continue;
//				}
//				boolean met=false;
//				for(int j=0;j<n;j++){
////					System.out.println(str[i].charAt(j));
////					System.out.println(ch);
//					if(str[i].charAt(j)==ch){
//						met=true;
//						break;
//					}
//				}
//				if(met==false){
//					can=false;
//					break;
//				}
//			}
//			if(can)	ans++;
////			System.out.println(can);
////			System.out.println(ch);
//		}
//		System.out.printf("%d\n",ans);
//	}
//}



import java.io.*;
import java.util.*;
import java.awt.*;
import java.math.*;


public class Main{
	static int n,m,s;
	static final int maxn=300000+10;
	static final int maxm=2*(300000+10);
	static int[] t=new int[maxn],u=new int[maxn],v=new int[maxn];
	
	static int head[]=new int[maxn];
	static Edge[] edges=new Edge[maxm];
	static int[][] ans=new int[2][maxm];
	static int[] cnt=new int[2];
	static int edgescnt=0;
	static void init()
	{
		edgescnt=0;
		for(int i=0;i<maxn;i++){
			head[i]=-1;
		}
	}
	static class Edge{
		public int u,v,id,d,next;
		public Edge()
		{
			u=v=id=d=0;
			next=0;
		}
		public Edge(int _u,int _v,int _id,int _d,int _next)
		{
			u=_u;v=_v;id=_id;d=_d;next=_next;
		}
	}
	static public void AddEdge(int u,int v,int id,int t)
	{
		edges[edgescnt]=new Edge(u,v,id,t,head[u]);
		head[u]=edgescnt++;
	}
	static boolean[] vis=new boolean[maxn];
	static public int BFS1()
	{
		Queue<Integer> que=new LinkedList<Integer>();
		for(int i=0;i<maxn;i++){
			vis[i]=false;
		}
		for(int i=0;i<m;i++){
			ans[0][i]=0;
		}
		vis[s]=true;
		que.offer(s);
		while(!que.isEmpty()){
			Integer u=que.peek();
			que.poll();
			for(int e=head[u.intValue()];e!=-1;e=edges[e].next){
				int v=edges[e].v,d=edges[e].d,id=edges[e].id;
				if(vis[v]){
					continue;
				}
				else{
					ans[0][id]=d;
					que.offer(v);
					vis[v]=true;
				}
			}
		}
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(vis[i])	cnt++;
		}
		return cnt;
	}

	static public int BFS2()
	{
		Queue<Integer> que=new LinkedList<Integer>();
		for(int i=0;i<maxn;i++){
			vis[i]=false;
		}
		for(int i=0;i<m;i++){
			ans[1][i]=0;
		}
		vis[s]=true;
		que.offer(s);
		while(!que.isEmpty()){
			Integer u=que.peek();
			que.poll();
			for(int e=head[u.intValue()];e!=-1;e=edges[e].next){
				int v=edges[e].v,d=edges[e].d,id=edges[e].id;
				if(d==0){
					if(!vis[v]){
						que.offer(v);
						vis[v]=true;
					}
				}
				else if(d==1){
					if(ans[1][id]==0){
						ans[1][id]=2;
					}
					else if(ans[1][id]==1){
						if(!vis[v]){
							que.offer(v);
							vis[v]=true;
						}
					}
				}
				else{
					if(ans[1][id]==0){
						ans[1][id]=1;
					}
					else if(ans[1][id]==2){
						if(!vis[v]){
							que.offer(v);
							vis[v]=true;
						}
					}
				}
			}
		}
		int cnt=0;
		for(int i=1;i<=n;i++){
			if(vis[i])	cnt++;
		}
		return cnt;
	}
	static public void main(String args[])
	{
		Scanner cin=new Scanner(new BufferedInputStream(System.in));
		n=cin.nextInt();m=cin.nextInt();s=cin.nextInt();
		init();
		cnt[0]=cnt[1]=0;
		for(int i=0;i<m;i++){
			t[i]=cin.nextInt();
			u[i]=cin.nextInt();
			v[i]=cin.nextInt();
		}
		for(int i=0;i<m;i++){
			if(t[i]==1){
				AddEdge(u[i],v[i],i,t[i]-1);
			}
			else{
				AddEdge(u[i],v[i],i,t[i]-1);
				AddEdge(v[i],u[i],i,t[i]);
			}
		}
		PrintWriter cout=new PrintWriter(new BufferedOutputStream(System.out));
		int res1,res2;
		res1=BFS1();
		cout.println(res1);
		for(int i=0;i<m;i++){
			if(t[i]==2){
				if(ans[0][i]==1){
					cout.print('+');
				}
				else{
					cout.print('-');
				}
			}
		}
		cout.println();
		res2=BFS2();
		cout.println(res2);
		for(int i=0;i<m;i++){
			if(t[i]==2){
				if(ans[1][i]==1){
					cout.print('+');
				}
				else{
					cout.print('-');
				}
			}
		}
		cout.close();
		cin.close();
	}
}