Problem: In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.

Vicky the witch has been tasked with performing deliveries between some pairs of cities. However, Vicky is a beginner, so she can only complete a delivery if she can move from her starting city to her destination city through a double rainbow. A double rainbow is a sequence of cities c_1, c_2, ..., c_k satisfying the following properties:

  * For each i with 1 ≤ i ≤ k - 1, the cities c_i and c_{i + 1} are connected by a road. 
  * For each i with 1 ≤ i ≤ (k - 1)/(2), the roads connecting c_{2i} with c_{2i - 1} and c_{2i + 1} have the same color. 



For example if k = 5, the road between c_1 and c_2 must be the same color as the road between c_2 and c_3, and the road between c_3 and c_4 must be the same color as the road between c_4 and c_5.

Vicky has a list of events in chronological order, where each event is either a delivery she must perform, or appearance of a new road. Help her determine which of her deliveries she will be able to complete.

Input

The first line contains four integers n, m, c, and q (2 ≤ n ≤ 10^5, 1 ≤ m, c, q ≤ 10^5), denoting respectively the number of cities, the number of roads initially present, the number of different colors the roads can take, and the number of events.

Each of the following m lines contains three integers x, y, and z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), describing that there initially exists a bidirectional road with color z between cities x and y.

Then q lines follow, describing the events. Each event is one of the following two types: 

  1. + x y z (1 ≤ x, y ≤ n, 1 ≤ z ≤ c), meaning a road with color z appears between cities x and y; 
  2. ? x y (1 ≤ x, y ≤ n), meaning you should determine whether Vicky can make a delivery starting at city x and ending at city y. It is guaranteed that x ≠ y. 



It is guaranteed that at any moment, there is at most one road connecting any pair of cities, and that no road connects a city to itself. It is guaranteed that the input contains at least one event of the second type.

Output

For each event of the second type, print a single line containing "Yes" (without quotes) if the delivery can be made, or a single line containing "No" (without quotes) otherwise.

Example

Input


4 3 2 4
1 2 1
2 3 1
3 4 2
? 1 4
? 4 1
+ 3 1 2
? 4 1


Output


Yes
No
Yes

Note

The following picture corresponds to the sample.

<image>

For her first delivery, Vicky can use the sequence 1, 2, 3, 4 which is a double rainbow. However, she cannot complete the second delivery, as she can only reach city 3. After adding the road between cities 1 and 3, she can now complete a delivery from city 4 to city 1 by using the double rainbow 4, 3, 1.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Main implements Runnable{
    public static void main(String[] args) throws Exception {
        //new Thread(null,new Main(),"Thread-1",1024*1024*10).start();
        new Main().solve();
    }
    int[]fa;
    Set<Integer>[]conn,cont;
    Map<Integer,Integer>[]color;
    ArrayList<Integer>[]edge;
    void solve() throws Exception{
        InputReader in=new InputReader(System.in);
        PrintWriter out=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n=in.nextInt(),m=in.nextInt(),c=in.nextInt(),q=in.nextInt();
        fa=new int[n+1];
        conn=new Set[n+1];
        cont=new Set[n+1];
        color=new Map[n+1];
        edge=new ArrayList[n+1];
        for(int i=1;i<=n;i++){
            conn[i]=new HashSet<>();cont[i]=new TreeSet<>();cont[i].add(i);conn[i].add(i);
            color[i]=new HashMap<>();edge[i]=new ArrayList<>();
        }
        for(int i=0;i<m;i++){
            int u=in.nextInt(),v=in.nextInt(),w=in.nextInt();
            addEdge(u,v,w);
        }
        for(int i=0;i<q;i++){
            if(in.nextChar()=='+'){
                addEdge(in.nextInt(),in.nextInt(),in.nextInt());
            }else {
                int x=in.nextInt(),y=in.nextInt();
                out.println(conn[y].contains(find(x))?"Yes":"No");
            }
        }
        out.flush();
    }
    void addEdge(int a,int b,int c){
        edge[a].add(b);edge[b].add(a);
        conn[a].add(find(b));conn[b].add(find(a));
        if(!color[a].containsKey(c))color[a].put(c,b);
        else comb(color[a].get(c),b);
        if(!color[b].containsKey(c))color[b].put(c,a);
        else comb(color[b].get(c),a);
    }
    void comb(int a,int b){
        int af=find(a),bf=find(b);
        if(af!=bf){
            if(cont[af].size()<cont[bf].size()){
                int tmp=af;af=bf;bf=tmp;
            }
            merge(af,bf);
        }
    }
    void merge(int a,int b){
        cont[a].addAll(cont[b]);
        fa[b]=a;
        for(int x:cont[b])replace(x,b,a);
        cont[b].clear();
    }
    void replace(int p,int a,int b){
        conn[p].remove(a);
        conn[p].add(b);
        for(int x:edge[p]){
            conn[x].remove(a);conn[x].add(b);
        }
    }
    int find(int a){
        int a1=a;
        while(fa[a]!=0)a=fa[a];
        while(fa[a1]!=0){
            int tmp=a1;
            a1=fa[a1];
            fa[tmp]=a;
        }
        return a;
    }
    @Override
    public void run() {
        try {
            solve();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    void shuffle(int[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r-l; i>1; i--) {
            int j=rnd.nextInt(i)+l,tmp=a[j];
            a[j]=a[i-1+l];
            a[i-1+l]=tmp;
        }
    }
    void shuffle(Object[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r-l; i>1; i--) {
            int j=rnd.nextInt(i)+l;
            Object tmp=a[j];
            a[j]=a[i-1+l];
            a[i-1+l]=tmp;
        }
    }
    void shuffle(long[]a,int l,int r){
        Random rnd=new Random();
        for (int i=r-l; i>1; i--) {
            int j=rnd.nextInt(i)+l;
            long tmp=a[j];
            a[j]=a[i-1+l];
            a[i-1+l]=tmp;
        }
    }
    /*
    class InputReader{
        StreamTokenizer tokenizer;
        public InputReader(InputStream stream){
            tokenizer=new StreamTokenizer(new BufferedReader(new InputStreamReader(stream)));
            tokenizer.ordinaryChars(33,126);
            tokenizer.wordChars(33,126);
        }
        public String next() throws IOException {
            tokenizer.nextToken();
            return tokenizer.sval;
        }
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
        public boolean hasNext() throws IOException {
            int res=tokenizer.nextToken();
            tokenizer.pushBack();
            return res!=tokenizer.TT_EOF;
        }
    }*/
    class InputReader implements Closeable {
        private InputStreamReader reader;
        private char[] buf;
        private int len, now;

        public InputReader(InputStream stream) {
            reader = new InputStreamReader(stream);
            buf = new char[1024];
            len = 0;
            now = 0;
        }

        public String next() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            StringBuilder sb = new StringBuilder();
            while (!isSpaceChar(buf[now])) {
                sb.append(buf[now]);
                if (!move()) break;
            }
            return sb.toString();
        }

        public int next(char[] s) throws IOException {
            if (!hasNext()) throw new NullPointerException();
            int len = 0;
            while (!isSpaceChar(buf[now]) && len < s.length) {
                s[len++] = buf[now];
                if (!move()) break;
            }
            return len;
        }

        public int nextInt() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            int ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isNum(buf[now])) ans = ans * 10 + toNum(buf[now]);
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }

        public long nextLong() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            long ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isNum(buf[now])) ans = ans * 10 + toNum(buf[now]);
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int nextHexInt() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            boolean x = false;
            if (buf[now] == '-') {
                x = true;
                if (!move()) throw new NumberFormatException();
            }
            int ans = 0;
            while (!isSpaceChar(buf[now])) {
                if (isHex(buf[now])) ans = (ans << 4) + toNum(buf[now]);
                else throw new NumberFormatException();
                if (!move()) break;
            }
            return (x ? -1 : 1) * ans;
        }

        public char nextChar() throws IOException {
            if (!hasNext()) throw new NullPointerException();
            char tmp = buf[now];
            move();
            return tmp;
        }

        public String nextLine() throws IOException {
            if (!hasNextLine()) throw new NullPointerException();
            StringBuilder sb = new StringBuilder();
            while (buf[now] != '\n') {
                sb.append(buf[now]);
                if (!move()) return sb.toString();
            }
            now++;
            return sb.toString();
        }

        public boolean hasNext() throws IOException {
            return skip();
        }

        public boolean hasNextLine() throws IOException {
            return now < len || refill();
        }

        public void close() throws IOException {
            reader.close();
        }

        private boolean move() throws IOException {
            now++;
            return hasNextLine();
        }

        private boolean skip() throws IOException {
            if (!hasNextLine()) return false;
            while (isSpaceChar(buf[now])) {
                if (!move()) return false;
            }
            return true;
        }

        private boolean isSpaceChar(char c) {
            return !(c >= 33 && c <= 126);
        }

        private boolean isNum(char c) {
            return c >= '0' && c <= '9';
        }

        private boolean isHex(char c) {
            return c >= '0' && c <= '9' || c >= 'A' && c <= 'F';
        }

        private int toNum(char c) {
            if (c >= '0' && c <= '9') return c - '0';
            else if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
            else return c - 'a' + 10;
        }

        private boolean refill() throws IOException {
            len = reader.read(buf);
            now = 0;
            return len > 0;
        }
    }
}