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;
inline int read() {
  int ans = 0, fh = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
  return ans * fh;
}
const int maxn = 1e6 + 100;
struct Xxj {
  int p[31], ele;
  inline void insert(int x) {
    if (ele == 30) return;
    for (int i = 30; ~i; i--)
      if ((x >> i) & 1) {
        if (!p[i]) {
          p[i] = x;
          break;
        }
        x ^= p[i];
      }
  }
  inline int query(int x) {
    for (int i = 30; ~i; i--) x = min(x, x ^ p[i]);
    return x;
  }
} g;
struct Rev {
  int tl, tr, x, y, z;
} a[maxn];
struct node {
  int x, y, z;
};
int n, m, q, fa[maxn], p[maxn], ans[maxn], siz[maxn], cnt, tim;
vector<Rev> seg[maxn << 2];
map<pair<int, int>, int> pos;
pair<int, int> b[maxn];
inline int getfa(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
inline int getxor(int x, int tmp = 0) {
  while (x != fa[x]) tmp ^= p[x], x = fa[x];
  return tmp;
}
inline void work(int o, Xxj &g, vector<node> &vc) {
  for (int i = 0, lim = seg[o].size(); i < lim; i++) {
    Rev now = seg[o][i];
    int x = now.x, y = now.y, z = now.z;
    int fx = getfa(x), fy = getfa(y);
    if (fx == fy) {
      g.insert(getxor(x) ^ getxor(y) ^ z);
    } else {
      if (siz[fx] > siz[fy]) swap(x, y), swap(fx, fy);
      z ^= getxor(x) ^ getxor(y);
      vc.push_back((node){fx, fy, siz[fy]});
      fa[fx] = fy, p[fx] = z, siz[fy] += siz[fx];
    }
  }
}
inline void Clear(vector<node> vc) {
  for (int i = vc.size() - 1; ~i; i--) {
    node now = vc[i];
    int x = now.x, y = now.y, z = now.z;
    fa[x] = x, p[x] = 0, siz[y] = z;
  }
}
void query(int o, int l, int r, Xxj g) {
  vector<node> vc;
  vc.clear();
  work(o, g, vc);
  int mid = l + r >> 1;
  if (l == r)
    ans[l] = g.query(getxor(b[l].first) ^ getxor(b[l].second));
  else
    query(o << 1, l, mid, g), query(o << 1 | 1, mid + 1, r, g);
  Clear(vc);
}
void insert(int o, int l, int r, int ql, int qr, Rev qz) {
  if (ql == l && qr == r) {
    seg[o].push_back(qz);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) insert(o << 1, l, mid, ql, min(qr, mid), qz);
  if (qr > mid) insert(o << 1 | 1, mid + 1, r, max(ql, mid + 1), qr, qz);
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), z = read();
    if (x > y) swap(x, y);
    a[++cnt] = (Rev){1, -1, x, y, z};
    pos[make_pair(x, y)] = cnt;
  }
  q = read();
  for (int i = 1; i <= q; i++) {
    int ms = read(), x = read(), y = read();
    if (x > y) swap(x, y);
    if (ms == 1) {
      a[pos[make_pair(x, y)] = ++cnt] = (Rev){tim + 1, -1, x, y, read()};
    }
    if (ms == 2) {
      a[pos[make_pair(x, y)]].tr = tim;
    }
    if (ms == 3) {
      b[++tim] = make_pair(x, y);
    }
  }
  for (int i = 1; i <= cnt; i++)
    if (a[i].tr == -1) a[i].tr = tim;
  for (int i = 1; i <= cnt; i++)
    if (a[i].tl <= a[i].tr) insert(1, 1, tim, a[i].tl, a[i].tr, a[i]);
  for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  query(1, 1, tim, g);
  for (int i = 1; i <= tim; i++) printf("%d\n", ans[i]);
  return 0;
}