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.util.*;

public class MainClass
{
    static int n = 0;
    static int m = 0;
    static int s = 0;
    static boolean[] visited;
    static ArrayList<Edge>[] adj;
    static int[] markFrom;
    static int[] markFrom1;
    static int count = 0;
    static StringBuilder stringBuilder = new StringBuilder();
    public static void main(String[] args)throws IOException
    {
        Reader in = new Reader();
        n = in.nextInt();
        m = in.nextInt();
        s = in.nextInt() - 1;
        visited = new boolean[n];
        adj = new ArrayList[n];
        markFrom = new int[m];
        markFrom1 = new int[m];
        int[] from = new int[m];
        int[] tt = new int[m];
        Arrays.fill(markFrom, -1);
        Arrays.fill(markFrom1, -1);
        for (int i=0;i<n;i++)   adj[i] = new ArrayList<>();
        for (int i=0;i<m;i++)
        {
            int type = 0;
            tt[i] = (type = in.nextInt());
            int x = in.nextInt() - 1;
            int y = in.nextInt() - 1;
            Edge edge = new Edge(y, i);
            from[i] = x;
            adj[x].add(edge);
            if (type == 2) adj[y].add(new Edge(x, i));
            else markFrom[i] = markFrom1[i] = x;
        }
        exploreForMax(s);
        stringBuilder.append(count).append("\n");
        for (int i=0;i<m;i++)
        {
            if (tt[i] == 2)
            {
                if (from[i] == markFrom[i])
                    stringBuilder.append("+");
                else
                    stringBuilder.append("-");
            }
        }
        stringBuilder.append("\n");
        count = 0;
        Arrays.fill(visited, false);
        exploreForMin(s);
        stringBuilder.append(count).append("\n");
        for (int i=0;i<m;i++)
        {
            if (tt[i] == 2)
            {
                if (from[i] == markFrom1[i])
                    stringBuilder.append("+");
                else
                    stringBuilder.append("-");
            }
        }
        System.out.println(stringBuilder);
    }
    public static void exploreForMax(int v)
    {
        visited[v] = true;
        count++;
        for (Edge edge: adj[v])
        {
            int to = edge.to;
            int indexOfEdge = edge.index;
            if (markFrom[indexOfEdge] == -1) markFrom[indexOfEdge] = v;
            if (!visited[to])   exploreForMax(to);
        }
    }
    public static void exploreForMin(int v)
    {
        visited[v] = true;
        count++;
        for (Edge edge: adj[v])
        {
            int to = edge.to;
            int indexOfEdge = edge.index;
            if (markFrom1[indexOfEdge] == -1) markFrom1[indexOfEdge] = to;
            else if (!visited[to])  exploreForMin(to);
        }
    }
}
class Edge
{
    int to;
    int index;

    public Edge(int to, int index)
    {
        this.to = to;
        this.index = index;
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private final DataInputStream din;
    private final byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}