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;
void Read(int &v) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  v = c & 15;
  while ((c = getchar()) >= '0' && c <= '9') v = v * 10 + (c & 15);
}
const int N = 200100, M = 400100, Q = 200100;
int n, m, q;
int lb[25][35];
int cnt_lb;
int anc[N], siz[N], dis[N];
stack<pair<int, int> > stk;
int a[M], b[M], c[M];
vector<int> posL[M], posR[M];
struct Query {
  bool ask;
  int u, v;
} queries[M];
void LbInsert(int x) {
  for (int i = 29; i >= 0; --i) {
    if ((x >> i & 1) == 0) continue;
    if (!lb[cnt_lb][i]) {
      lb[cnt_lb][i] = x;
      return;
    }
    x ^= lb[cnt_lb][i];
  }
}
int LbQuery(int x) {
  for (int i = 29; i >= 0; --i) x = min(x, x ^ lb[cnt_lb][i]);
  return x;
}
inline void LbForward() {
  ++cnt_lb;
  memcpy(lb[cnt_lb], lb[cnt_lb - 1], sizeof lb[cnt_lb]);
}
inline void LbBack() { --cnt_lb; }
void Init() {
  for (int i = 1; i <= n; ++i) anc[i] = i, siz[i] = 1;
}
int Anc(int u) {
  if (anc[u] == u) return u;
  return Anc(anc[u]);
}
int Dist(int u) {
  if (anc[u] == u) return 0;
  return dis[u] ^ Dist(anc[u]);
}
inline void Merge(int u, int v, int w) {
  int anc_u = Anc(u), anc_v = Anc(v);
  if (anc_u == anc_v) {
    LbInsert(Dist(u) ^ Dist(v) ^ w);
    return;
  }
  if (siz[anc_u] > siz[anc_v]) swap(anc_u, anc_v);
  anc[anc_u] = anc_v;
  siz[anc_v] += siz[anc_u];
  dis[anc_u] = Dist(u) ^ Dist(v) ^ w;
  stk.push(make_pair(anc_u, anc_v));
}
inline void Undo() {
  int u = stk.top().first, v = stk.top().second;
  stk.pop();
  anc[u] = u, siz[v] -= siz[u], dis[u] = 0;
}
void Divide(int le, int ri, vector<pair<int, int> > arr) {
  vector<pair<int, int> > arrL, arrR;
  size_t already = stk.size();
  LbForward();
  int mid = (le + ri) >> 1;
  for (size_t i = 0; i < arr.size(); ++i) {
    int u = a[arr[i].first], v = b[arr[i].first], w = c[arr[i].first];
    int l = posL[arr[i].first][arr[i].second],
        r = posR[arr[i].first][arr[i].second];
    if (l <= le && ri <= r) {
      Merge(u, v, w);
    } else {
      if (l <= mid) arrL.push_back(arr[i]);
      if (mid < r) arrR.push_back(arr[i]);
    }
  }
  if (le == ri) {
    if (queries[le].ask)
      printf("%d\n", LbQuery(Dist(queries[le].u) ^ Dist(queries[le].v)));
  } else {
    Divide(le, mid, arrL), Divide(mid + 1, ri, arrR);
  }
  while (stk.size() > already) Undo();
  LbBack();
}
int main() {
  Read(n), Read(m);
  map<pair<int, int>, int> S;
  vector<pair<int, int> > vec;
  for (int i = 1; i <= m; ++i) {
    Read(a[i]), Read(b[i]), Read(c[i]);
    S[make_pair(a[i], b[i])] = i;
    posL[i].push_back(0);
  }
  Read(q);
  for (int i = 1; i <= q; ++i) {
    int op;
    Read(op), Read(queries[i].u), Read(queries[i].v);
    pair<int, int> ed(queries[i].u, queries[i].v),
        ed2(queries[i].v, queries[i].u);
    if (op == 1) {
      int w;
      Read(w);
      S[ed] = S[ed2] = ++m;
      a[m] = queries[i].u, b[m] = queries[i].v, c[m] = w;
      posL[m].push_back(i);
    } else if (op == 2) {
      int id = S[ed];
      posR[id].push_back(i - 1);
      vec.push_back(make_pair(id, posR[id].size() - 1));
    } else if (op == 3) {
      queries[i].ask = true;
    }
  }
  for (int i = 1; i <= m; ++i)
    if (posL[i].size() > posR[i].size()) {
      posR[i].push_back(m);
      vec.push_back(make_pair(i, posR[i].size() - 1));
    }
  Init();
  Divide(0, m, vec);
  return 0;
}