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 n, m, q, a[200050], fa[200050], size[200050], p[40][30], ans[200050], top;
struct node {
  int u, v, w;
  bool operator<(const node &x) const {
    if (u == x.u) {
      if (v == x.v) return w < x.w;
      return v < x.v;
    }
    return u < x.u;
  }
} qu[200050];
map<node, int> app;
vector<node> ch[200050 << 2];
pair<int *, int> st[200050 << 2];
void ins(int u, int l, int r, int tl, int tr, node x) {
  if (tl <= l && r <= tr) return ch[u].push_back(x);
  if (tl <= ((l + r) >> 1)) ins(u << 1, l, ((l + r) >> 1), tl, tr, x);
  if (((l + r) >> 1) < tr) ins(u << 1 | 1, ((l + r) >> 1) + 1, r, tl, tr, x);
}
pair<int, int> get(int u) {
  int d = 0;
  while (u ^ fa[u]) d ^= a[u], u = fa[u];
  return make_pair(u, d);
}
int merge(int u, int v, int w) {
  int ret = 0;
  if (size[u] < size[v]) swap(u, v);
  if (size[u] == size[v]) {
    st[++top] = make_pair(&size[u], size[u]);
    ++size[u], ++ret;
  }
  st[++top] = make_pair(&fa[v], fa[v]), fa[v] = u, ++ret;
  st[++top] = make_pair(&a[v], a[v]), a[v] = w, ++ret;
  return ret;
}
void add(int w, int d) {
  for (register int i = 30; ~i; --i) {
    if ((1 << i) & w) {
      if (!p[i][d])
        return void(p[i][d] = w);
      else
        w ^= p[i][d];
    }
  }
}
int calc(int w, int d) {
  for (register int i = 30; ~i; --i) {
    if ((1 << i) & w) w ^= p[i][d];
  }
  return w;
}
void solve(int u, int l, int r, int d) {
  int tms = 0;
  for (register int i = 0; i <= 31; ++i) p[i][d] = p[i][d - 1];
  for (auto p : ch[u]) {
    pair<int, int> x = get(p.u), y = get(p.v);
    if (x.first != y.first)
      tms += merge(x.first, y.first, p.w ^ x.second ^ y.second);
    else
      add(p.w ^ x.second ^ y.second, d);
  }
  if (l == r)
    ans[qu[l].w] = calc(get(qu[l].u).second ^ get(qu[l].v).second, d);
  else
    solve(u << 1, l, ((l + r) >> 1), d + 1),
        solve(u << 1 | 1, ((l + r) >> 1) + 1, r, d + 1);
  while (tms--) {
    *(st[top].first) = st[top].second;
    --top;
  }
}
int main() {
  int u, v, w;
  scanf("%d%d", &n, &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, &w);
    if (u > v) swap(u, v);
    app[node{u, v, w}] = 1;
  }
  scanf("%d", &q);
  int opt;
  for (register int i = 1; i <= q; ++i) {
    scanf("%d%d%d", &opt, &u, &v);
    if (u > v) swap(u, v);
    if (opt == 1) {
      scanf("%d", &w);
      app[node{u, v, w}] = i;
    } else if (opt == 2) {
      map<node, int>::iterator it = app.lower_bound(node{u, v, 0});
      ins(1, 1, q, it->second, i, it->first), app.erase(it);
    } else
      qu[i] = node{u, v, i};
  }
  for (auto u : app) ins(1, 1, q, u.second, q, u.first);
  memset(ans, -1, sizeof(ans));
  solve(1, 1, q, 1);
  for (register int i = 1; i <= q; ++i)
    if (ans[i] != -1) cout << ans[i] << endl;
  return 0;
}