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 = (int)2e5 + 1, maxd = 19, maxb = 31;
int n, qtot, htot, dsu[maxn], msk[maxn];
pair<int, int> que[maxn], his[maxn << 1 | 1];
pair<int, int> dsu_find(int u) {
  int ret = 0;
  for (; dsu[u] >= 0; ret ^= msk[u], u = dsu[u])
    ;
  return (pair<int, int>){u, ret};
}
int dsu_merge(int u, int v, int w) {
  pair<int, int> pu = dsu_find(u), pv = dsu_find(v);
  w ^= pu.second ^ pv.second;
  if ((u = pu.first) == (v = pv.first)) return w;
  if (dsu[u] < dsu[v]) swap(u, v);
  his[htot++] = (pair<int, int>){u, dsu[u]};
  his[htot++] = (pair<int, int>){v, dsu[v]};
  if (dsu[u] == dsu[v]) --dsu[v];
  dsu[u] = v;
  msk[u] = w;
  return 0;
}
int base[maxd][maxb];
vector<pair<pair<int, int>, int> > e[maxn << 1 | 1];
void update(int L, int R, int l, int r, pair<pair<int, int>, int> v) {
  if (l <= L && R <= r) {
    e[(L + R) | (L < R)].push_back(v);
  } else {
    int M = (L + R) >> 1;
    if (l <= M) update(L, M, l, r, v);
    if (M < r) update(M + 1, R, l, r, v);
  }
}
void solve(int dep, int L, int R) {
  int rt = (L + R) | (L < R), pht = htot;
  for (vector<pair<pair<int, int>, int> >::iterator it = e[rt].begin();
       it != e[rt].end(); ++it) {
    int tmp = dsu_merge(it->first.first, it->first.second, it->second);
    for (int i = 1; i <= base[dep][0] && tmp; ++i)
      tmp = min(tmp, tmp ^ base[dep][i]);
    if (tmp) {
      for (int i = 1; i <= base[dep][0]; ++i)
        base[dep][i] = min(base[dep][i], tmp ^ base[dep][i]);
      base[dep][++base[dep][0]] = tmp;
    }
  }
  if (L == R) {
    int tmp = dsu_find(que[L].first).second ^ dsu_find(que[L].second).second;
    for (int i = 1; i <= base[dep][0]; ++i) tmp = min(tmp, tmp ^ base[dep][i]);
    que[L].first = tmp;
  } else {
    int M = (L + R) >> 1;
    memcpy(base[dep + 1], base[dep], (base[dep][0] + 1) * sizeof(int));
    solve(dep + 1, L, M);
    memcpy(base[dep + 1], base[dep], (base[dep][0] + 1) * sizeof(int));
    solve(dep + 1, M + 1, R);
  }
  while (htot > pht) {
    pair<int, int> &tmp = his[--htot];
    dsu[tmp.first] = tmp.second;
    tmp = his[--htot];
    dsu[tmp.first] = tmp.second;
    msk[tmp.first] = 0;
  }
}
int etot;
struct Edge {
  int L, R;
  pair<pair<int, int>, int> E;
} edges[maxn];
map<int, pair<int, int> > tim[maxn];
int main() {
  int m;
  scanf("%d%d", &n, &m);
  while (m--) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    tim[u][v] = (pair<int, int>){qtot + 1, w};
  }
  scanf("%d", &m);
  while (m--) {
    int typ, u, v, w;
    scanf("%d%d%d", &typ, &u, &v);
    if (typ == 1) {
      scanf("%d", &w);
      tim[u][v] = (pair<int, int>){qtot + 1, w};
    } else if (typ == 2) {
      pair<int, int> tmp = tim[u][v];
      if (tmp.first <= qtot)
        edges[etot++] = (Edge){
            tmp.first, qtot,
            (pair<pair<int, int>, int>){(pair<int, int>){u, v}, tmp.second}};
      tim[u].erase(v);
    } else {
      que[++qtot] = (pair<int, int>){u, v};
    }
  }
  for (int i = 0; i < etot; ++i)
    update(1, qtot, edges[i].L, edges[i].R, edges[i].E);
  for (int u = 1; u <= n; ++u)
    for (map<int, pair<int, int> >::iterator it = tim[u].begin();
         it != tim[u].end(); ++it) {
      int v = it->first;
      pair<int, int> tmp = it->second;
      if (tmp.first <= qtot)
        update(1, qtot, tmp.first, qtot,
               (pair<pair<int, int>, int>){(pair<int, int>){u, v}, tmp.second});
    }
  memset(dsu + 1, -1, n * sizeof(int));
  solve(0, 1, qtot);
  for (int i = 1; i <= qtot; ++i) printf("%d\n", que[i].first);
  return 0;
}