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 G883 {
    static class Pair<U extends Comparable<U>, V extends Comparable<V>>
            implements Comparable<Pair<U,V>>{

        public final U a;
        public final V b;

        private Pair(U a, V b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!a.equals(pair.a))
                return false;
            return b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return 31 * a.hashCode() + b.hashCode();
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }

        @Override
        public int compareTo(Pair<U, V> o) {
            if(this.a.equals(o.a)){
                return getV().compareTo(o.getV());
            }
            return getU().compareTo(o.getU());
        }
        private U getU() {
            return a;
        }
        private V getV() {
            return b;
        }
    }
    static class Graph{
        int vertices;
        ArrayList<Integer>[][] edge;
        ArrayList<Pair<Integer,Integer>> type2;

        boolean once = true;

        Map<Pair<Integer,Integer>,String> minMap = new HashMap<>();
        Map<Pair<Integer,Integer>,String> maxMap = new HashMap<>();
        Set<Pair<Integer,Integer>> set = new HashSet<>();

        int countA = 0;
        int countB = 0;

        Queue<Integer> queue = new ArrayDeque<>();

        Graph(int vertices){
            this.vertices = vertices;
            edge = new ArrayList[vertices+1][2];
            type2 = new ArrayList<>();
            for(int i=0;i<=vertices;i++){
                edge[i][0] = new ArrayList<>();
                edge[i][1] = new ArrayList<>();

            }

        }

        void addEdge(int a,int b,int type){
            if(type==1) {
                edge[a][0].add(b);
            }
            else{
                edge[a][1].add(b);
                edge[b][1].add(a);
                set.add(new Pair<>(a,b));
                type2.add(new Pair<>(a,b));
            }
        }

        void DFS(int at) throws IOException{
            boolean[] visited = new boolean[vertices+1];
            boolean[] visited2 = new boolean[vertices+1];
            DFSutil(at,visited,visited2);
            countB = countA;
            once = false;
            while (queue.size()>0){
                DFSutil2(queue.poll(),visited,visited2);
            }
            out.write(countA+"\n");
            for(int i=0;i<type2.size();i++){
                if(maxMap.containsKey(type2.get(i))) {
                    out.write(maxMap.get(type2.get(i)) + "");
                }
                else{
                    out.write("+" + "");
                }
            }
            out.write("\n");
            out.write(countB+"\n");
            for(int i=0;i<type2.size();i++){
                if(minMap.containsKey(type2.get(i))) {
                    out.write(minMap.get(type2.get(i)) + "");
                }
                else{
                    out.write("+" + "");
                }
            }
            out.write("\n");
            out.flush();
        }

        private void DFSutil(int v, boolean[] visited,boolean[] visited2) {
            visited[v] = true;
            if(once) {
                visited2[v] = true;
            }
            countA++;
            Iterator<Integer> iterator = edge[v][0].listIterator();
            if(edge[v][1].size()>0){
                queue.add(v);
            }
            while (iterator.hasNext()){
                int a = iterator.next();
                if(!visited[a]){
                    DFSutil(a,visited,visited2);
                }
            }
        }

        private void DFSutil2(int v, boolean[] visited,boolean[] visited2) {

            Iterator<Integer> iterator = edge[v][1].listIterator();

            while (iterator.hasNext()){
                int a = iterator.next();
                Pair<Integer,Integer> pairA = new Pair<>(v,a);
                Pair<Integer,Integer> pairB = new Pair<>(a,v);
                if(!visited2[a] ){
                    if(set.contains(pairA)){
                        maxMap.put(pairA,"+");
                        minMap.put(pairA,"-");
                        set.remove(pairA);
                    }

                    if(set.contains(pairB)){
                        maxMap.put(pairB,"-");
                        minMap.put(pairB,"+");
                        set.remove(pairB);
                    }
                    if(!visited[a]) {
                        DFSutil(a, visited, visited2);
                    }
                }
                else{
//                    System.out.println(a);
//                    print(visited);
                    if(set.contains(pairA)){
                        maxMap.put(pairA,"+");
                        minMap.put(pairA,"+");
                        set.remove(pairA);
                    }

                    if(set.contains(pairB)){
                        maxMap.put(pairB,"+");
                        minMap.put(pairB,"+");
                        set.remove(pairB);
                    }

                }
            }
        }

    }

    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args)throws IOException{
        String[] s1 = inp.readLine().split(" ");
        int a = Integer.parseInt(s1[0]);
        int b = Integer.parseInt(s1[1]);
        int c = Integer.parseInt(s1[2]);



        Graph graph = new Graph(a);
        for(int i=0;i<b;i++){
            s1 = inp.readLine().split(" ");
            int aa = Integer.parseInt(s1[0]);
            int bb = Integer.parseInt(s1[1]);
            int cc = Integer.parseInt(s1[2]);
            graph.addEdge(bb,cc,aa);
        }

        graph.DFS(c);

    }
    static void print(boolean[] bin){
        for(int i=0;i<bin.length;i++){
            System.out.print(i+" "+bin[i]+" ");
        }
        System.out.println();
    }

}