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>
struct ufs {
  int fa, siz, val;
} f[800010];
int find(int x) {
  while (x != f[x].fa) x = f[x].fa;
  return x;
}
int dis(int x) {
  int d = 0;
  while (x != f[x].fa) d ^= f[x].val, x = f[x].fa;
  return d;
}
struct ufsstk {
  int x, y;
  ufs fx, fy;
} stk[800010];
int tp;
struct base {
  int a[32];
  void insert(int x) {
    for (int i = 30; ~i; --i)
      if (x & (1 << i)) {
        if (a[i])
          x ^= a[i];
        else {
          a[i] = x;
          break;
        }
      }
  }
  int query(int s) {
    for (int i = 30; ~i; --i)
      if ((s ^ a[i]) < s) s ^= a[i];
    return s;
  }
} nul;
void unit(int x, int y, int w) {
  w ^= dis(x) ^ dis(y);
  x = find(x), y = find(y);
  if (x == y) return;
  if (f[x].siz < f[y].siz) std::swap(x, y);
  stk[++tp] = (ufsstk){x, y, f[x], f[y]};
  f[y].fa = x, f[y].val ^= w, f[x].siz += f[y].siz;
}
void undo() {
  f[stk[tp].x] = stk[tp].fx, f[stk[tp].y] = stk[tp].fy;
  tp--;
}
struct edge {
  int x, y, w;
};
struct node {
  int l, r;
  std::vector<edge> p;
  std::vector<edge> q;
} tr[800010];
void build(int o, int l, int r) {
  tr[o].l = l, tr[o].r = r;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
}
void insp(int o, int l, int r, edge e) {
  if (r < tr[o].l || tr[o].r < l) return;
  if (l <= tr[o].l && tr[o].r <= r) return tr[o].p.push_back(e);
  insp(o << 1, l, r, e), insp(o << 1 | 1, l, r, e);
}
void insq(int o, int v, edge q) {
  if (v < tr[o].l || tr[o].r < v) return;
  if (tr[o].l == tr[o].r) return tr[o].q.push_back(q);
  insq(o << 1, v, q), insq(o << 1 | 1, v, q);
}
void solve(int o, base s) {
  int beg = tp;
  for (auto e : tr[o].p) {
    if (find(e.x) != find(e.y))
      unit(e.x, e.y, e.w);
    else {
      s.insert(dis(e.x) ^ dis(e.y) ^ e.w);
    }
  }
  if (tr[o].l == tr[o].r) {
    for (auto q : tr[o].q) printf("%d\n", s.query(dis(q.x) ^ dis(q.y)));
  } else {
    solve(o << 1, s);
    solve(o << 1 | 1, s);
  }
  while (tp != beg) undo();
}
int n, m, q, id;
std::map<std::pair<int, int>, std::pair<int, int> > ha;
std::pair<int, int> ee[800010];
int tt;
std::map<std::pair<int, int>, bool> op;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ha[std::make_pair(u, v)] = std::make_pair(w, 0);
    ee[++tt] = std::make_pair(u, v);
    op[std::make_pair(u, v)] = 1;
  }
  scanf("%d", &q);
  build(1, 0, q + 1);
  for (int i = 1; i <= q; ++i) {
    int opt;
    scanf("%d", &opt);
    if (opt == 1) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w);
      ha[std::make_pair(u, v)] = std::make_pair(w, i);
      ee[++tt] = std::make_pair(u, v);
      op[std::make_pair(u, v)] = 1;
    } else if (opt == 2) {
      int u, v;
      scanf("%d%d", &u, &v);
      insp(1, ha[std::make_pair(u, v)].second, i,
           (edge){u, v, ha[std::make_pair(u, v)].first});
      op[std::make_pair(u, v)] = 0;
    } else if (opt == 3) {
      int u, v;
      scanf("%d%d", &u, &v);
      insq(1, i, (edge){u, v, 0});
    }
  }
  for (int i = 0; i <= tt; ++i) {
    if (op[ee[i]]) {
      insp(1, ha[ee[i]].second, q + 1,
           (edge){ee[i].first, ee[i].second, ha[ee[i]].first});
      ha[ee[i]] = std::make_pair(0, 0);
    }
  }
  for (int i = 1; i <= n; ++i) f[i] = (ufs){i, 1, 0};
  solve(1, nul);
  return 0;
}