Note the unusual memory limit for this problem.

You are given an undirected graph consisting of *n* vertices and *m* edges. The vertices are numbered with integers from 1 to *n*, the edges are numbered with integers from 1 to *m*. Each edge can be unpainted or be painted in one of the *k* colors, which are numbered with integers from 1 to *k*. Initially, none of the edges is painted in any of the colors.

You get queries of the form "Repaint edge *e*<sub class="lower-index">*i*</sub> to color *c*<sub class="lower-index">*i*</sub>". At any time the graph formed by the edges of the same color must be bipartite. If after the repaint this condition is violated, then the query is considered to be invalid and edge *e*<sub class="lower-index">*i*</sub> keeps its color. Otherwise, edge *e*<sub class="lower-index">*i*</sub> is repainted in color *c*<sub class="lower-index">*i*</sub>, and the query is considered to valid.

Recall that the graph is called bipartite if the set of its vertices can be divided into two parts so that no edge connected vertices of the same parts.

For example, suppose you are given a triangle graph, that is a graph with three vertices and edges (1, 2), (2, 3) and (3, 1). Suppose that the first two edges are painted color 1, and the third one is painted color 2. Then the query of "repaint the third edge in color 1" will be incorrect because after its execution the graph formed by the edges of color 1 will not be bipartite. On the other hand, it is possible to repaint the second edge in color 2.

You receive *q* queries. For each query, you should either apply it, and report that the query is valid, or report that the query is invalid.
The first line contains integers *n*, *m*, *k*, *q* (2 ≤ *n* ≤ 5·10<sup class="upper-index">5</sup>, 1 ≤ *m*, *q* ≤ 5·10<sup class="upper-index">5</sup>, 1 ≤ *k* ≤ 50) — the number of vertices, the number of edges, the number of colors and the number of queries. 

Then follow *m* edges of the graph in the form *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> (1 ≤ *a*<sub class="lower-index">*i*</sub>, *b*<sub class="lower-index">*i*</sub> ≤ *n*). 

Then follow *q* queries of the form *e*<sub class="lower-index">*i*</sub>, *c*<sub class="lower-index">*i*</sub> (1 ≤ *e*<sub class="lower-index">*i*</sub> ≤ *m*, 1 ≤ *c*<sub class="lower-index">*i*</sub> ≤ *k*).

It is guaranteed that the graph doesn't contain multiple edges and loops.
# LUOGU_RID: 119235543
def is_bipartite(graph):
    n = len(graph)
    color = [-1] * n
    for i in range(n):
        if color[i] == -1:
            color[i] = 0
            queue = [i]
            while queue:
                u = queue.pop(0)
                for v in graph[u]:
                    if color[v] == -1:
                        color[v] = 1 - color[u]
                        queue.append(v)
                    elif color[v] == color[u]:
                        return False
    return True

n, m, k, q = map(int, input().split())
graph = [[] for _ in range(n)]
edge_colors = [-1] * m

for _ in range(m):
    u, v = map(int, input().split())
    graph[u-1].append(v-1)
    graph[v-1].append(u-1)

for _ in range(q):
    e, c = map(int, input().split())
    e -= 1
    edge_colors[e] = c
    temp_graph = graph.copy()
    temp_graph[e].remove(e)
    temp_graph[e].append(e)
    if is_bipartite(temp_graph):
        print("Yes")
    else:
        print("No")