Problem: 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
+-+

Solution (in JAVA):

Solution:
import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;

public class SPOJANDCC
{
	private InputStream is;
	private PrintWriter out;

	/*
	 * long arr[],lazy[][]; void check(int p) { if(lazy[p][0]!=0) {
	 * 
	 * } } void update(int l,int r,int c,int x,int y) {
	 * 
	 * }
	 */
	class e
	{
		int p, t, ind, ans, in;

		e(int a, int b, int c, int d)
		{
			p = a;
			t = b;
			ind = c;
			in = d;
		}
	}

	boolean v[];

	ArrayList<e> a[];

	int mp = 0;

	void mx(int y)
	{
		v[y] = true;
		mp++;
		for (e i : a[y])
		{
			if (v[i.p])
				continue;
			else if (i.t == 2)
				anss[i.in] = i.ind;
			mx(i.p);
		}
	}

	void mn(int y)
	{
		v[y] = true;
		mp++;
		for (e i : a[y])
		{
			if (v[i.p])
				continue;
			else if (i.t == 2)
			{
				anss[i.in] = i.ind;
				continue;
			}
			mn(i.p);
		}
	}

	int anss[];

	@SuppressWarnings("unchecked")
	void solve()
	{
		int n = ni(), m = ni(), s = ni();
		anss = new int[m];
		a = new ArrayList[n + 1];
		v = new boolean[n + 1];
		for (int i = 0; i <= n; i++)
			a[i] = new ArrayList<e>();
		boolean u[] = new boolean[m];
		for (int i = 0; i < m; i++)
		{
			int t = ni(), x = ni(), y = ni();
			if (t == 1)
			{
				e r = new e(y, t, 0, i);
				a[x].add(r);
			} else
			{
				e r = new e(y, t, 1, i);
				a[x].add(r);
				u[i] = true;
				r = new e(x, t, 2, i);
				a[y].add(r);
			}
		}
		mx(s);
		out.println(mp);
		for (int i = 0; i < m; i++)
		{
			if (anss[i] == 1)
				out.print("+");
			else if (anss[i] == 2)
				out.print("-");
			else if (u[i])
				out.print("+");
		}
		out.println();
		mp = 0;
		Arrays.fill(v, false);
		Arrays.fill(anss, 0);
		mn(s);
		out.println(mp);
		for (int i = 0; i < m; i++)
		{
			if (anss[i] == 2)
				out.print("+");
			else if (anss[i] == 1)
				out.print("-");
			else if (u[i])
				out.print("+");
		}
	}

	void soln()
	{
		is = System.in;
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	public static void main(String[] args)
	{
		new Thread(null, new Runnable()
		{
			public void run()
			{
				try
				{
					new SPOJANDCC().soln();
				} catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		}, "1", 1 << 26).start();
	}

	// To Get Input
	// Some Buffer Methods
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf)
		{
			ptrbuf = 0;
			try
			{
				lenbuf = is.read(inbuf);
			} catch (IOException e)
			{
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c)
	{
		return !(c >= 33 && c <= 126);
	}

	private int skip()
	{
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd()
	{
		return Double.parseDouble(ns());
	}

	private char nc()
	{
		return (char) skip();
	}

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b)))
		{ // when nextLine, (isSpaceChar(b) && b != '
			// ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b)))
		{
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-')
		{
			minus = true;
			b = readByte();
		}

		while (true)
		{
			if (b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			} else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-')
		{
			minus = true;
			b = readByte();
		}

		while (true)
		{
			if (b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			} else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}