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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        ArrayList<Edge>[] adj;
        boolean[] visited;
        char[] maxChars;

        void dfs(int cur, boolean disregard) {
            if (visited[cur]) throw new RuntimeException();
            visited[cur] = true;
            for (Edge edge : adj[cur]) {
                if (!visited[edge.to]) {
                    if (disregard) {
                        if (edge.edgeIndex != -1 && !edge.flipped) {
                            maxChars[edge.edgeIndex] = '-';
                        }
                        if (edge.edgeIndex == -1) {
                            dfs(edge.to, disregard);
                        }
                    } else {
                        if (edge.edgeIndex != -1 && edge.flipped) {
                            maxChars[edge.edgeIndex] = '-';
                        }
                        dfs(edge.to, disregard);
                    }
                }
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            int m = in.readInt();
            int s = in.readInt() - 1;
            int[] t = new int[m], u = new int[m], v = new int[m];
            IOUtils.readIntArrays(in, t, u, v);
            MiscUtils.decreaseByOne(u, v);
            adj = new ArrayList[n];
            for (int i = 0; i < adj.length; i++) {
                adj[i] = new ArrayList<>();
            }
            int edgeIndex = 0;
            for (int idx = 0; idx < t.length; idx++) {
                if (t[idx] == 1) { // only add directed for now
                    Edge edge = new Edge();
                    edge.to = v[idx];
                    adj[u[idx]].add(edge);
                } else if (t[idx] == 2) {
                    {
                        Edge edge = new Edge();
                        edge.to = v[idx]; // normal + orientation
                        edge.edgeIndex = edgeIndex;
                        edge.flipped = false;
                        adj[u[idx]].add(edge);
                    }
                    {
                        Edge edge = new Edge();
                        edge.to = u[idx];
                        edge.edgeIndex = edgeIndex;
                        edge.flipped = true;
                        adj[v[idx]].add(edge);
                    }
                    edgeIndex++;
                } else throw new RuntimeException();
            }
            visited = new boolean[n];
            maxChars = new char[edgeIndex];
            Arrays.fill(maxChars, '+');
            dfs(s, false);
            out.printLine(ArrayUtils.count(visited, true));
            out.printLine(maxChars);
            Arrays.fill(maxChars, '+');
            Arrays.fill(visited, false);
            dfs(s, true);
            out.printLine(ArrayUtils.count(visited, true));
            out.printLine(maxChars);
        }

        class Edge {
            int to;
            int edgeIndex = -1;
            boolean flipped = false;
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void printLine(char[] array) {
            writer.println(array);
        }

        public void close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }
    }
    static class MiscUtils {
        public static void decreaseByOne(int[]... arrays) {
            for (int[] array : arrays) {
                for (int i = 0; i < array.length; i++) {
                    array[i]--;
                }
            }
        }
    }
    static class IOUtils {
        public static void readIntArrays(InputReader in, int[]... arrays) {
            for (int i = 0; i < arrays[0].length; i++) {
                for (int j = 0; j < arrays.length; j++) {
                    arrays[j][i] = in.readInt();
                }
            }
        }
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    static class ArrayUtils {
        public static int count(boolean[] array, boolean value) {
            int result = 0;
            for (boolean i : array) {
                if (i == value) {
                    result++;
                }
            }
            return result;
        }
    }
}

