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;
map<pair<int, int>, int> M;
vector<int> V[1000000];
vector<int>::iterator it;
int c[1000000][2], fa[1000000], rev[1000000], num[1000000], sum[1000000];
struct edge {
  int l, r, x, y, z;
};
edge e[1000000];
int u[1000000], v[1000000];
int g[40][40];
int i, m, n, t, q, x, y, z;
inline bool checkroot(int x) {
  return ((c[fa[x]][0] != x) && (c[fa[x]][1] != x));
}
inline void pushdown(int x) {
  if (rev[x]) {
    swap(c[x][0], c[x][1]);
    rev[c[x][0]] = rev[c[x][0]] ^ 1;
    rev[c[x][1]] = rev[c[x][1]] ^ 1;
    rev[x] = rev[x] ^ 1;
  }
  return;
}
inline void pushup(int x) {
  sum[x] = num[x] ^ sum[c[x][0]] ^ sum[c[x][1]];
  return;
}
inline void tagdown(int x) {
  if (!checkroot(x)) tagdown(fa[x]);
  pushdown(x);
  return;
}
inline void rotate(int x) {
  int y = fa[x], z = fa[y], k = (c[y][1] == x);
  if (c[y][k] = c[x][k ^ 1]) fa[c[x][k ^ 1]] = y;
  if (!checkroot(y)) c[z][c[z][1] == y] = x;
  fa[y] = x, fa[x] = z, c[x][k ^ 1] = y;
  pushup(y), pushup(x);
  return;
}
inline void splay(int x) {
  tagdown(x);
  while (!checkroot(x)) {
    int y = fa[x], z = fa[y];
    if (!checkroot(y))
      if ((c[y][1] == x) ^ (c[z][1] == y))
        rotate(x);
      else
        rotate(y);
    rotate(x);
  }
  return;
}
inline void access(int x) {
  int p = x, t = 0;
  for (; x; t = x, x = fa[x]) splay(x), c[x][1] = t, pushup(x);
  splay(p);
  return;
}
inline void evert(int x) {
  access(x);
  rev[x] = rev[x] ^ 1;
  return;
}
inline void link(int x, int y) {
  evert(x);
  splay(y);
  fa[x] = y;
  return;
}
inline void cut(int x, int y) {
  access(x);
  splay(y);
  if (!fa[x]) fa[y] = 0;
  access(y);
  splay(x);
  if (!fa[y]) fa[x] = 0;
  return;
}
inline bool checklink(int x, int y) {
  access(x);
  access(y);
  return fa[x];
}
inline void add(int o, int *g) {
  int x = e[o].x, y = e[o].y, z = e[o].z;
  if (!checklink(x, y)) {
    num[n + o] = sum[n + o] = z;
    link(x, n + o);
    link(y, n + o);
  } else {
    evert(x);
    access(y);
    z = z ^ sum[y];
    for (int i = 30; i >= 0; i--)
      if ((1 << i) & z)
        if (g[i])
          z = z ^ g[i];
        else {
          g[i] = z;
          break;
        }
  }
  return;
}
inline void del(int o) {
  int x = e[o].x, y = e[o].y;
  if (checklink(x, y)) {
    cut(x, n + o);
    cut(y, n + o);
  }
  return;
}
inline int ask(int x, int y, int *g) {
  evert(x);
  access(y);
  int z = sum[y];
  for (int i = 30; i >= 0; i--)
    if ((z ^ g[i]) < z) z = z ^ g[i];
  return z;
}
inline void input() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
    e[i].l = 1, M[make_pair(e[i].x, e[i].y)] = i;
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &t);
    if (t == 1) {
      m++, scanf("%d%d%d", &e[m].x, &e[m].y, &e[m].z);
      e[m].l = i, M[make_pair(e[m].x, e[m].y)] = m;
    }
    if (t == 2) {
      scanf("%d%d", &x, &y);
      z = M[make_pair(x, y)], e[z].r = i;
    }
    if (t == 3) {
      scanf("%d%d", &u[i], &v[i]);
    }
  }
  for (i = 1; i <= m; i++)
    if (!e[i].r) e[i].r = q;
  return;
}
inline void inserttree(int l, int r, int x, int y, int z, int node) {
  if ((l == x) && (r == y))
    V[node].push_back(z);
  else {
    int mid = (l + r) >> 1;
    if (y <= mid)
      inserttree(l, mid, x, y, z, node << 1);
    else if (x > mid)
      inserttree(mid + 1, r, x, y, z, node << 1 | 1);
    else {
      inserttree(l, mid, x, mid, z, node << 1);
      inserttree(mid + 1, r, mid + 1, y, z, node << 1 | 1);
    }
  }
  return;
}
inline void asktree(int l, int r, int x, int node) {
  for (int i = 0; i <= 30; i++) g[x][i] = g[x - 1][i];
  for (it = V[node].begin(); it != V[node].end(); it++) add(*it, g[x]);
  if (l == r) {
    if (u[l]) printf("%d\n", ask(u[l], v[l], g[x]));
  } else {
    int mid = (l + r) >> 1;
    asktree(l, mid, x + 1, node << 1);
    asktree(mid + 1, r, x + 1, node << 1 | 1);
  }
  for (it = V[node].begin(); it != V[node].end(); it++) del(*it);
  return;
}
int main() {
  input();
  for (i = 1; i <= m; i++) inserttree(1, q, e[i].l, e[i].r, i, 1);
  asktree(1, q, 1, 1);
  return 0;
}