Problem: You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). 

There are three types of queries you have to process:

  * 1 x y d — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



Print the answers for all queries of type 3.

Input

The first line contains two numbers n and m (1 ≤ n, m ≤ 200000) — the number of vertices and the number of edges in the graph, respectively.

Then m lines follow denoting the edges of the graph. Each line contains three integers x, y and d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1). Each pair (x, y) is listed at most once. The initial graph is connected.

Then one line follows, containing an integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow, denoting queries in the following form:

  * 1 x y d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1) — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y (1 ≤ x < y ≤ n) — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y (1 ≤ x < y ≤ n) — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



It is guaranteed that at least one query has type 3.

Output

Print the answers for all queries of type 3 in the order they appear in input.

Example

Input

5 5
1 2 3
2 3 4
3 4 5
4 5 6
1 5 1
5
3 1 5
1 1 3 1
3 1 5
2 1 5
3 1 5


Output

1
1
2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
const int MN = 200005, MM = 400005, MQ = 200005, MTS = 524288, MS = 10000005;
struct Bs {
  int b[30];
  void ins(int x) {
    for (int i = 29; ~i; --i)
      if (x >> i & 1) {
        if (!b[i]) {
          b[i] = x;
          return;
        }
        x ^= b[i];
      }
  }
  int min(int x) {
    for (int i = 29; ~i; --i)
      if ((x ^ b[i]) < x) x ^= b[i];
    return x;
  }
} _0;
int N, M, Q, T, eu[MM], ev[MM], ew[MM], es[MM], et[MM], qt[MQ], qu[MQ], qv[MQ],
    Ans[MQ], h[MTS], nxt[MS], t1[MS], t2[MS], tot, st[MM], t, fa[MN], wgh[MN],
    sz[MN];
std::map<int, int> mp[MN];
inline void ins(int x, int y, int z) {
  nxt[++tot] = h[x], t1[tot] = y, t2[tot] = z, h[x] = tot;
}
void Update(int i, int l, int r, int a, int b, int x, int y) {
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    ins(i, x, y);
    return;
  }
  Update(i << 1, l, ((l + r) >> 1), a, b, x, y),
      Update(i << 1 | 1, ((l + r) >> 1) + 1, r, a, b, x, y);
}
int ff(int x, int& v) {
  if (fa[x]) {
    int d = ff(fa[x], v);
    return v ^= wgh[x], d;
  }
  return v = 0, x;
}
void Solve(int i, int l, int r, Bs B) {
  int ot = t;
  for (int j = h[i]; j; j = nxt[j])
    if (t1[j]) {
      int u = eu[t2[j]], v = ev[t2[j]], w = ew[t2[j]], x, y;
      u = ff(u, x), v = ff(v, y);
      if (u == v) {
        B.ins(x ^ y ^ w);
        continue;
      }
      if (sz[v] < sz[u]) v ^= u ^= v ^= u;
      fa[u] = v, wgh[u] = x ^ y ^ w, sz[v] += sz[u], st[++t] = u;
    }
  if (l == r) {
    for (int j = h[i]; j; j = nxt[j])
      if (!t1[j]) {
        int u = qu[t2[j]], v = qv[t2[j]], x, y;
        ff(u, x), ff(v, y), Ans[t2[j]] = B.min(x ^ y);
      }
  } else
    Solve(i << 1, l, ((l + r) >> 1), B),
        Solve(i << 1 | 1, ((l + r) >> 1) + 1, r, B);
  while (t != ot) sz[fa[st[t]]] -= sz[st[t]], fa[st[t]] = wgh[st[t]] = 0, --t;
}
int main() {
  scanf("%d%d", &N, &M), T = 1;
  for (int i = 1; i <= N; ++i) sz[i] = 1;
  for (int i = 1; i <= M; ++i)
    scanf("%d%d%d", &eu[i], &ev[i], &ew[i]), es[i] = T, mp[eu[i]][ev[i]] = i;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    int op, x, y, z;
    scanf("%d%d%d", &op, &x, &y);
    if (op == 1)
      scanf("%d", &z), ++M, eu[M] = x, ev[M] = y, ew[M] = z, es[M] = ++T,
                            mp[x][y] = M;
    if (op == 2) et[mp[x][y]] = T++;
    if (op == 3) qt[i] = T, qu[i] = x, qv[i] = y;
  }
  for (int i = 1; i <= M; ++i) Update(1, 1, T, es[i], et[i] ? et[i] : T, 1, i);
  for (int i = 1; i <= Q; ++i)
    if (qt[i]) Update(1, 1, T, qt[i], qt[i], 0, i);
  Solve(1, 1, T, _0);
  for (int i = 1; i <= Q; ++i)
    if (qt[i]) printf("%d\n", Ans[i]);
  return 0;
}