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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
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
 *
 * @author pandusonu
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public HashMap<Integer, ArrayList<Integer>>[] adlist;
        public boolean[] visited;
        public int[] sAns0;

        public TaskG() {
            adlist = new HashMap[300001];
            for (int i = 0; i < 300001; i++) {
                adlist[i] = new HashMap<>();
            }
            visited = new boolean[300001];
            sAns0 = new int[300001];
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            int m = in.readInt();
            int s = in.readInt() - 1;
            for (int i = 0; i < n; i++) {
                adlist[i].clear();
            }
            int[][] edges = new int[m][3];
            for (int i = 0; i < m; i++) {
                edges[i] = in.readIntArray(3);
                edges[i][2]--;
                edges[i][1]--;
                int u = edges[i][1];
                int v = edges[i][2];
                if (edges[i][0] == 1) {
                    if (!adlist[u].containsKey(v))
                        adlist[u].put(v, new ArrayList<>(4));
                    adlist[u].get(v).add(-1);
                } else {
                    if (!adlist[u].containsKey(v))
                        adlist[u].put(v, new ArrayList<>(4));
                    if (!adlist[v].containsKey(u))
                        adlist[v].put(u, new ArrayList<>(4));
                    adlist[u].get(v).add(i);
                    adlist[v].get(u).add(i);
                }
            }
            int ans;
            ans = 0;
            Arrays.fill(visited, false);
            Arrays.fill(sAns0, -1);
            dfs1(s, adlist);
            for (int i = 0; i < n; i++) {
                if (visited[i])
                    ans++;
            }
            out.println(ans);
            for (int i = 0; i < m; i++) {
                if (edges[i][0] == 2) {
                    if (sAns0[i] == -1) out.print("-");
                    else {
                        if (sAns0[i] == edges[i][1]) out.print("+");
                        else out.print("-");
                    }
                }
            }
            Arrays.fill(visited, false);
            Arrays.fill(sAns0, -1);
            dfs0(s, adlist);
            out.println();
            ans = 0;
            for (int i = 0; i < n; i++) {
                if (visited[i])
                    ans++;
            }
            out.println(ans);
            for (int i = 0; i < m; i++) {
                if (edges[i][0] == 2) {
                    if (sAns0[i] == -1)
                        out.print("-");
                    else {
                        if (sAns0[i] == edges[i][1]) out.print("+");
                        else out.print("-");
                    }
                }
            }
        }

        public void dfs0(int cur, HashMap<Integer, ArrayList<Integer>>[] adlist) {
            visited[cur] = true;
            for (Map.Entry<Integer, ArrayList<Integer>> entry : adlist[cur].entrySet()) {
                boolean travel = false;
                for (int x : entry.getValue()) {
                    if (x == -1) travel = true;
                    else {
                        sAns0[x] = entry.getKey();
                    }
                }
                if (!visited[entry.getKey()] && travel) {
                    dfs0(entry.getKey(), adlist);
                }
            }
        }

        public void dfs1(int cur, HashMap<Integer, ArrayList<Integer>>[] adlist) {
            visited[cur] = true;
            for (Map.Entry<Integer, ArrayList<Integer>> entry : adlist[cur].entrySet()) {
                if (!visited[entry.getKey()]) {
                    for (int x : entry.getValue()) {
                        if (x != -1)
                            sAns0[x] = cur;
                    }
                    dfs1(entry.getKey(), adlist);
                }
            }
        }

    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

        public int readInt() {
            return (int) readLong();
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
                if (c == -1) throw new RuntimeException();
            }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += (c - '0');
                c = read();
            } while (!isSpaceChar(c));
            return negative ? (-res) : (res);
        }

        public int[] readIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) arr[i] = readInt();
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}