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;
struct BASIC {
  int base[31];
  void insert(int w) {
    for (int i = 30, j; i >= 0; i--)
      if (w & (1 << i)) {
        if (!base[i]) {
          for (base[i] = w, j = 30; j > i; j--)
            if (base[j] & (1 << i)) base[j] ^= w;
          break;
        } else
          w ^= base[i];
      }
  }
  int query(int x) {
    for (int i = 30; i >= 0; i--)
      if ((x ^ base[i]) < x) x ^= base[i];
    return x;
  }
} V[30];
int fa[200010], dis[200010], size[200010];
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
int GetDis(int x) {
  int res = 0;
  while (x != fa[x]) res ^= dis[x], x = fa[x];
  return res;
}
void nunion(int x, int y, int w, vector<int> &d) {
  int tmp1 = GetDis(x), tmp2 = GetDis(y);
  x = find(x), y = find(y);
  if (size[x] > size[y]) swap(x, y);
  dis[x] = w ^ tmp1 ^ tmp2, fa[x] = y, size[y] += size[x], d.push_back(x);
}
void Clear(vector<int> &d) {
  for (int i = 0; i < d.size(); i++) fa[d[i]] = d[i], dis[d[i]] = 0;
  d.clear();
}
struct Edge {
  int fm, to, st, ed, w;
};
struct Ask {
  int u, v, id;
};
vector<Ask> q[200010];
int ans[200010], flg[200010];
void CDQ(int l, int r, int dep, vector<Edge> &e) {
  for (int i = 0; i <= 30; i++) V[dep].base[i] = V[dep - 1].base[i];
  vector<int> d;
  vector<Edge> L, R;
  int mid = (l + r) >> 1;
  for (int i = 0; i < e.size(); i++) {
    if (e[i].st <= l && e[i].ed >= r) {
      if (find(e[i].fm) == find(e[i].to))
        V[dep].insert(GetDis(e[i].fm) ^ GetDis(e[i].to) ^ e[i].w);
      else
        nunion(e[i].fm, e[i].to, e[i].w, d);
      continue;
    }
    if (e[i].st <= mid) L.push_back(e[i]);
    if (e[i].ed > mid) R.push_back(e[i]);
  }
  if (l == r) {
    for (int i = 0; i < q[l].size(); i++) {
      int u = q[l][i].u, v = q[l][i].v;
      if (find(u) != find(v)) continue;
      ans[q[l][i].id] = V[dep].query(GetDis(u) ^ GetDis(v));
    }
    Clear(d);
    return;
  }
  CDQ(l, mid, dep + 1, L), CDQ(mid + 1, r, dep + 1, R), Clear(d);
}
map<pair<int, int>, int> s;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<Edge> e;
  for (int i = 1, a, b, c; i <= m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    if (a > b) swap(a, b);
    s[pair<int, int>(a, b)] = i, e.push_back((Edge){a, b, 0, (int)1e9, c});
  }
  for (int i = 1; i <= n; i++) fa[i] = i, size[i] = 1;
  int Q, cnt = m, t = 0;
  scanf("%d", &Q);
  for (int i = 1, a, b, c, d; i <= Q; i++) {
    scanf("%d%d%d", &a, &b, &c);
    if (a == 1)
      cnt++, t++, scanf("%d", &d), e.push_back((Edge){b, c, t, (int)1e9, d}),
          s[pair<int, int>(b, c)] = cnt;
    if (a == 2) {
      if (b > c) swap(b, c);
      t++, e[s[pair<int, int>(b, c)] - 1].ed = t - 1;
    }
    if (a == 3) q[t].push_back((Ask){b, c, i}), flg[i] = 1;
  }
  CDQ(0, t, 1, e);
  for (int i = 1; i <= Q; i++)
    if (flg[i]) printf("%d\n", ans[i]);
  return 0;
}