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 = 200000 + 10;
int n, m, Q, qn, p[110], fa[maxn], dep[maxn], val[maxn], pos[maxn], lst[maxn],
    ans[maxn], cnt, head[maxn], tot;
map<pair<int, int>, int> mp;
struct Edge {
  int x, y, w;
} e[maxn << 1], q[maxn << 2];
vector<Edge> G[maxn << 2];
vector<Edge>::iterator it;
inline int read() {
  register int x = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - '0';
  return (f == 1) ? x : -x;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void build(int l, int r, int rt) {
  if (l == r) return pos[l] = rt, void();
  int mid = (l + r) >> 1;
  build(l, mid, (rt << 1));
  build(mid + 1, r, (rt << 1 | 1));
}
void update(int L, int R, Edge C, int l, int r, int rt) {
  if (L <= l && r <= R) return G[rt].push_back(C), void();
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, C, l, mid, (rt << 1));
  if (R > mid) update(L, R, C, mid + 1, r, (rt << 1 | 1));
}
inline int find(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
inline int ask(int x) {
  int ans = 0;
  while (x != fa[x]) ans ^= val[x], x = fa[x];
  return ans;
}
inline int insert(int x) {
  for (int i = 29; i >= 0; i--) {
    if (!(x & (1 << i))) continue;
    if (!p[i]) return p[i] = x, i;
    x ^= p[i];
  }
  return -1;
}
inline int query(int x, int y) {
  int z = ask(x) ^ ask(y);
  for (int i = 29; i >= 0; i--)
    if (p[i] && (z & (1 << i))) z ^= p[i];
  return z;
}
void solve(int l, int r, int rt) {
  vector<int> rub;
  vector<Edge> del;
  int x, y, w, u, v, d;
  for (it = G[rt].begin(); it != G[rt].end(); it++) {
    x = it->x;
    y = it->y;
    w = it->w;
    u = find(x);
    v = find(y);
    if (u == v) {
      d = insert(ask(x) ^ ask(y) ^ w);
      if (d >= 0) rub.push_back(d);
    } else {
      if (dep[u] > dep[v]) swap(u, v);
      val[u] = ask(x) ^ ask(y) ^ w;
      fa[u] = v;
      del.push_back((Edge){u, v, dep[v]});
      if (dep[u] == dep[v]) dep[v]++;
    }
  }
  int mid = (l + r) >> 1;
  if (l == r) {
    if (q[rt].x) ans[q[rt].w] = query(q[rt].x, q[rt].y);
  } else
    solve(l, mid, (rt << 1)), solve(mid + 1, r, (rt << 1 | 1));
  reverse(del.begin(), del.end());
  for (it = del.begin(); it != del.end(); it++) {
    u = it->x;
    v = it->y;
    val[u] = 0;
    fa[u] = u;
    dep[v] = it->w;
  }
  for (int i = rub.size() - 1; i >= 0; i--) p[rub[i]] = 0;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) fa[i] = i;
  int op, x, y, w;
  for (int i = 1; i <= m; i++) {
    x = read(), y = read(), w = read();
    mp[make_pair(x, y)] = ++cnt;
    e[cnt] = (Edge){x, y, w};
  }
  Q = read();
  build(0, Q, 1);
  for (int i = 1; i <= Q; i++) {
    op = read(), x = read(), y = read();
    if (x > y) swap(x, y);
    if (op == 1)
      w = read(), mp[make_pair(x, y)] = ++cnt, lst[cnt] = i,
      e[cnt] = (Edge){x, y, w};
    if (op == 2)
      w = mp[make_pair(x, y)], update(lst[w], i - 1, e[w], 0, Q, 1),
      lst[w] = -1, mp[make_pair(x, y)] = 0;
    if (op == 3) q[pos[i]] = (Edge){x, y, ++qn};
  }
  for (int i = 1; i <= cnt; i++)
    if (lst[i] >= 0) update(lst[i], Q, e[i], 0, Q, 1);
  solve(0, Q, 1);
  for (int i = 1; i <= qn; i++) print(ans[i]), putchar('\n');
  return 0;
}