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>
using namespace std;
int fa[400005], len[400005], dep[400005], s[400005], t[400005];
pair<int, int> q[400005];
map<pair<int, int>, int> id;
struct node {
  int u, v;
  bool delta;
};
struct edge {
  int u, v, d;
} e[800005];
vector<edge> ve[4000005];
struct linear_basis {
  int lb[35];
  inline void ins(int x) {
    for (register int i = 30; ~i; --i)
      if (x >> i & 1) {
        if (lb[i])
          x ^= lb[i];
        else {
          lb[i] = x;
          break;
        }
      }
    return;
  }
  inline int qmin(int x) {
    for (register int i = 30; ~i; --i)
      if ((x ^ lb[i]) < x) x ^= lb[i];
    return x;
  }
} lnbs;
int ff(int x) {
  if (x == fa[x]) return x;
  return ff(fa[x]);
}
int sxpfa(int x) {
  if (x == fa[x]) return 0;
  return len[x] ^ sxpfa(fa[x]);
}
void inse(int root, int l, int r, int ql, int qr, edge delta) {
  if (ql <= l && r <= qr) return (void)ve[root].push_back(delta);
  int mid = l + r >> 1;
  if (ql <= mid) inse(root << 1, l, mid, ql, qr, delta);
  if (qr > mid) inse(root << 1 | 1, mid + 1, r, ql, qr, delta);
  return;
}
void solve(int root, int l, int r, linear_basis lnbs) {
  stack<node> sta;
  for (register int i = 0, u, v, k, fu, fv; i < ve[root].size(); ++i) {
    u = ve[root][i].u, v = ve[root][i].v, fu = ff(u), fv = ff(v),
    k = ve[root][i].d ^ sxpfa(u) ^ sxpfa(v);
    if (fu == fv)
      lnbs.ins(k);
    else {
      if (dep[fu] > dep[fv]) swap(u, v), swap(fu, fv);
      fa[fu] = fv, len[fu] = k;
      if (dep[fu] == dep[fv])
        ++dep[fv], sta.push((node){fu, fv, 1});
      else
        sta.push((node){fu, fv, 0});
    }
  }
  if (l == r)
    printf("%d\n", lnbs.qmin(sxpfa(q[l].first) ^ sxpfa(q[l].second)));
  else {
    int mid = l + r >> 1;
    solve(root << 1, l, mid, lnbs), solve(root << 1 | 1, mid + 1, r, lnbs);
  }
  while (!sta.empty()) {
    node tp = sta.top();
    len[fa[tp.u] = tp.u] = 0, dep[tp.v] -= tp.delta, sta.pop();
  }
  return;
}
int main() {
  int n, m, u, v, d, opt, qq;
  scanf("%d%d", &n, &m);
  int tim = 1, cnt = m;
  for (register int i = 1; i <= n; ++i) fa[i] = i;
  for (register int i = 1; i <= m; ++i)
    scanf("%d%d%d", &u, &v, &d),
        id[make_pair(u, v)] = i, e[i] = (edge){u, v, d}, s[i] = 1, t[i] = -1;
  scanf("%d", &qq);
  while (qq--) {
    scanf("%d%d%d", &opt, &u, &v);
    if (opt == 1)
      scanf("%d", &d), id[make_pair(u, v)] = ++cnt, s[cnt] = tim, t[cnt] = -1,
                                       e[cnt] = (edge){u, v, d};
    else if (opt == 2)
      t[id[make_pair(u, v)]] = tim - 1;
    else
      q[tim] = make_pair(u, v), ++tim;
  }
  --tim;
  for (register int i = 1; i <= cnt; ++i) t[i] == -1 ? t[i] = tim : t[i];
  for (register int i = 1; i <= cnt; ++i)
    if (s[i] <= t[i]) inse(1, 1, tim, s[i], t[i], e[i]);
  solve(1, 1, tim, lnbs);
  return 0;
}