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.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;
import java.net.*;

import static java.lang.Math.*;

public class Solution implements Runnable {
    
    class Edge {
        int to, ind;
        boolean init;
        
        Edge(int to, int ind, boolean init) {
            this.to = to;
            this.ind = ind;
            this.init = init;
        }        
    }
    
    List<Integer>[] to;
    List<Edge>[] e;
    boolean[] was;
    char[] resMax, resMin;
    
    void doIt(int v, boolean forMax) {
        was[v] = true;
        for (int u : to[v]) {
            if (!was[u]) {
                doIt(u, forMax);
            }
        }
        for (Edge edge : e[v]) {
            if (forMax) {
                if (!was[edge.to] && resMax[edge.ind] == '\0') {
                    resMax[edge.ind] = (edge.init ? '+' : '-');
                    doIt(edge.to, forMax);
                }
            } else {
                if (!was[edge.to] && resMin[edge.ind] == '\0') {
                    resMin[edge.ind] = (edge.init ? '-' : '+');
                }
            }
        }
    }
    
    void solve() throws Exception {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int s = sc.nextInt() - 1;
        to = new List[n];
        e = new List[n];
        was = new boolean[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<>();
            e[i] = new ArrayList<>();
        }
        int k = 0;
        while (m-- > 0) {
            int type = sc.nextInt();
            int v = sc.nextInt() - 1;
            int u = sc.nextInt() - 1;
            if (type == 1) {
                to[v].add(u);
            } else {
                e[v].add(new Edge(u, k, true));
                e[u].add(new Edge(v, k, false));
                k++;
            }
        }
        resMax = new char[k];
        doIt(s, true);
        int ansMax = 0;
        for (int i = 0; i < n; i++) {
            ansMax += (was[i] ? 1 : 0);
        }
        Arrays.fill(was, false);
        resMin = new char[k];
        doIt(s, false);
        int ansMin = 0;
        for (int i = 0; i < n; i++) {
            ansMin += (was[i] ? 1 : 0);
        }
        out.println(ansMax);
        for (int i = 0; i < k; i++) {
            out.print(resMax[i] != '\0' ? resMax[i] : '+');
        }
        out.println();
        out.println(ansMin);
        for (int i = 0; i < k; i++) {
            out.print(resMin[i] != '\0' ? resMin[i] : '+');
        }
        out.println();
    }

    BufferedReader in;
    PrintWriter out;
    FastScanner sc;

    final String INPUT_FILE = "";
    final String OUTPUT_FILE = "";

    static Throwable throwable;

    public static void main(String[] args) throws Throwable {
        Thread thread = new Thread(null, new Solution(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (Solution.throwable != null)
            throw Solution.throwable;
    }

    public void run() {
        try {
            if (INPUT_FILE.equals("")) {
                in = new BufferedReader(new InputStreamReader(System.in));
            } else {
                in = new BufferedReader(new FileReader(INPUT_FILE));
            }
            if (OUTPUT_FILE.equals("")) {
                out = new PrintWriter(System.out);
            } else {
                out = new PrintWriter(OUTPUT_FILE);
            }
            sc = new FastScanner(in);
            solve();
        } catch (Exception e) {
            throwable = e;
        } finally {
            out.close();
        }
    }

}

class FastScanner {
	
    BufferedReader reader;
    StringTokenizer strTok;

    FastScanner(BufferedReader reader) {
        this.reader = reader;
    }

    public String nextToken() throws Exception {
        while (strTok == null || !strTok.hasMoreTokens()) {
            strTok = new StringTokenizer(reader.readLine());
        }
        return strTok.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }
}