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;
mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
inline void chkmax(T &x, T y) {
  if (x < y) x = y;
}
template <typename T>
inline void chkmin(T &x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < 48) c = getchar();
  while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x;
}
const int maxn = 2e5 + 10;
int n, m, q, ans[maxn];
struct edge {
  int u, v, w;
} Q[maxn];
map<pair<int, int>, pair<int, int> > G;
int top, st[maxn];
int par[maxn], sz[maxn], val[maxn];
int find(int x) {
  while (par[x] != x) x = par[x];
  return x;
}
int query(int x) {
  int res = 0;
  while (par[x] != x) res ^= val[x], x = par[x];
  return res;
}
struct linear_base {
  int A[30];
  void ins(int x) {
    for (int i = (29), iend = (0); i >= iend; --i)
      if (x >> i & 1) {
        if (A[i]) {
          x ^= A[i];
        } else {
          for (int j = (0), jend = (i - 1); j <= jend; ++j)
            if (x >> j & 1) x ^= A[j];
          for (int j = (i + 1), jend = (29); j <= jend; ++j)
            if (A[j] >> i & 1) A[j] ^= x;
          A[i] = x;
          return;
        }
      }
  }
  int query(int x) {
    for (int i = (29), iend = (0); i >= iend; --i) chkmin(x, x ^ A[i]);
    return x;
  }
} LB[20];
vector<edge> E[maxn << 2];
void ins(int k, int l, int r, int ql, int qr, edge x) {
  if (ql <= l && r <= qr) {
    E[k].push_back(x);
    return;
  }
  if (ql <= ((l + r) >> 1)) ins(k << 1, l, ((l + r) >> 1), ql, qr, x);
  if (qr > ((l + r) >> 1)) ins(k << 1 | 1, ((l + r) >> 1) + 1, r, ql, qr, x);
}
void solve(int k, int l, int r, int dep) {
  int state = top;
  LB[dep] = LB[dep - 1];
  for (edge p : E[k]) {
    int u = p.u, v = p.v;
    int x = find(u), y = find(v);
    int w = p.w ^ query(u) ^ query(v);
    if (x != y) {
      if (sz[x] < sz[y]) swap(x, y);
      par[y] = x, st[++top] = y;
      sz[x] += sz[y], val[y] = w;
    } else {
      LB[dep].ins(w);
    }
  }
  if (l == r) {
    int u = Q[l].u, v = Q[l].v;
    if (u) ans[l] = LB[dep].query(query(u) ^ query(v));
  } else {
    solve(k << 1, l, ((l + r) >> 1), dep + 1),
        solve(k << 1 | 1, ((l + r) >> 1) + 1, r, dep + 1);
  }
  while (top > state) {
    int u = st[top--];
    sz[par[u]] -= sz[u], par[u] = u, val[u] = 0;
  }
}
int main() {
  cin >> n >> m;
  for (int i = (1), iend = (m); i <= iend; ++i) {
    int u = read(), v = read(), w = read();
    if (u > v) swap(u, v);
    G[pair<int, int>(u, v)] = pair<int, int>(w, 1);
  }
  cin >> q;
  for (int i = (1), iend = (q); i <= iend; ++i) {
    int op = read(), u = read(), v = read();
    if (u > v) swap(u, v);
    if (op == 1) {
      int w = read();
      G[pair<int, int>(u, v)] = pair<int, int>(w, i);
    } else if (op == 2) {
      pair<int, int> p = G[pair<int, int>(u, v)];
      ins(1, 1, q, p.second, i, edge{u, v, p.first});
      G.erase(pair<int, int>(u, v));
    } else {
      Q[i] = {u, v};
    }
  }
  for (auto x : G) {
    pair<int, int> e = x.first, p = x.second;
    ins(1, 1, q, p.second, q, edge{e.first, e.second, p.first});
  }
  for (int i = (1), iend = (n); i <= iend; ++i) par[i] = i, sz[i] = 1;
  solve(1, 1, q, 1);
  for (int i = (1), iend = (q); i <= iend; ++i)
    if (Q[i].u) printf("%d\n", ans[i]);
  return 0;
}