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;
const int maxn = 200010, inf = 0x7fffffff;
struct node {
  int x, y, z, s, t;
} e[maxn * 2];
struct node2 {
  int x, y;
} q[maxn * 2];
struct node3 {
  int x, y, opt;
} p[maxn * 2];
int n, m, Q, ans[maxn], tQ, Time[maxn * 2], top, cnt, fa[maxn], val[maxn],
    ji[40][30], sizee[maxn], tmp[maxn * 2];
vector<int> V[maxn << 2];
map<pair<int, int>, int> M;
stack<pair<int, int> > S;
void update(int o, int l, int r, int x, int y, int id) {
  if (x > y) return;
  if (y < l || x > r) return;
  if (x <= l && r <= y) {
    V[o].push_back(id);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) update(o * 2, l, mid, x, y, id);
  if (y > mid) update(o * 2 + 1, mid + 1, r, x, y, id);
}
int find(int x) {
  if (x == fa[x]) return x;
  return find(fa[x]);
}
int getval(int x) {
  int res = 0;
  while (x != fa[x]) {
    res ^= val[x];
    x = fa[x];
  }
  return res;
}
void cha(int o, int dep) {
  int tot = 0;
  for (int i = 0; i < V[o].size(); i++) {
    int id = V[o][i];
    int x = e[id].x, y = e[id].y, z = e[id].z;
    int fx = find(x), fy = find(y);
    if (sizee[fx] < sizee[fy]) swap(fx, fy), swap(x, y);
    if (fx != fy) {
      fa[fy] = fx;
      val[fy] = getval(y) ^ getval(x) ^ z;
      sizee[fx] += sizee[fy];
      S.push(make_pair(fx, fy));
    } else
      tmp[++tot] = getval(y) ^ getval(x) ^ z;
  }
  for (int i = 1; i <= tot; i++)
    for (int j = 29; j >= 0; j--)
      if (tmp[i] >> j & 1) {
        if (!ji[dep][j]) {
          ji[dep][j] = tmp[i];
          break;
        } else
          tmp[i] ^= ji[dep][j];
      }
}
void del() {
  while (!S.empty()) {
    int x = S.top().first, y = S.top().second;
    S.pop();
    if (x == -1 && y == -1) return;
    fa[y] = y;
    sizee[x] -= sizee[y];
    val[y] = 0;
  }
}
void solve(int o, int l, int r, int dep) {
  S.push(make_pair(-1, -1));
  cha(o, dep);
  if (l == r) {
    int x = q[l].x, y = q[l].y;
    int temp = (getval(x) ^ getval(y));
    for (int j = 29; j >= 0; j--)
      if ((temp ^ ji[dep][j]) < temp) temp ^= ji[dep][j];
    printf("%d\n", temp);
    del();
    return;
  }
  int mid = (l + r) >> 1;
  for (int i = 0; i <= 29; i++) ji[dep + 1][i] = ji[dep][i];
  solve(o * 2, l, mid, dep + 1);
  for (int i = 0; i <= 29; i++) ji[dep + 1][i] = ji[dep][i];
  solve(o * 2 + 1, mid + 1, r, dep + 1);
  del();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i, sizee[i] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    M[make_pair(e[i].x, e[i].y)] = M[make_pair(e[i].y, e[i].x)] = i;
    e[i].s = 1;
    e[i].t = -1;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int opt;
    scanf("%d", &opt);
    if (opt == 1) {
      ++m;
      scanf("%d%d%d", &e[m].x, &e[m].y, &e[m].z);
      M[make_pair(e[m].x, e[m].y)] = M[make_pair(e[m].y, e[m].x)] = m;
      e[m].s = cnt + 1;
      e[m].t = -1;
    }
    if (opt == 2) {
      int x, y, id;
      scanf("%d%d", &x, &y);
      id = M[make_pair(x, y)];
      e[id].t = cnt;
    }
    if (opt == 3) {
      int x, y;
      scanf("%d%d", &x, &y);
      ++cnt;
      q[cnt].x = x;
      q[cnt].y = y;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (e[i].t == -1)
      update(1, 1, cnt, e[i].s, cnt, i);
    else
      update(1, 1, cnt, e[i].s, e[i].t, i);
  }
  for (int i = 1; i <= cnt; i++) ans[i] = inf;
  solve(1, 1, cnt, 1);
  return 0;
}