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;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int n, m, q, num, tree_cnt, edge_cnt, root, top;
int ls[400010], rs[400010], pre[400010], nxt[400010], ans[400010];
map<pair<int, int>, int> mp;
struct Edge {
  int x, y, v;
} e[400010];
struct node {
  int x, y, deep;
} st[400010];
struct query {
  int x, y;
} qu[400010];
void build(int l, int r, int &cur) {
  if (!cur) cur = ++tree_cnt;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(l, mid, ls[cur]);
  build(mid + 1, r, rs[cur]);
}
vector<int> v[400010];
void insert(int L, int R, int l, int r, int id, int cur) {
  if (L <= l && R >= r) {
    v[cur].push_back(id);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) insert(L, R, l, mid, id, ls[cur]);
  if (R > mid) insert(L, R, mid + 1, r, id, rs[cur]);
}
int a[400010][40];
void ins(int x, int cur) {
  for (int i = 30; i >= 0; --i) {
    if (x & (1 << i)) {
      if (!a[cur][i]) {
        a[cur][i] = x;
        break;
      } else
        x ^= a[cur][i];
    }
  }
}
int get(int x, int cur) {
  for (int i = 30; i >= 0; --i)
    if ((x ^ a[cur][i]) < x) x ^= a[cur][i];
  return x;
}
int fa[400010], de[400010], dis[400010];
int find(int x) { return fa[x] == x ? x : find(fa[x]); }
int xor_dis(int x) { return fa[x] == x ? dis[x] : dis[x] ^ xor_dis(fa[x]); }
void merge(int x, int y, int v) {
  if (de[x] < de[y]) swap(x, y);
  st[++top] = (node){x, y, de[x]};
  fa[y] = x, dis[y] = v, de[x] = max(de[x], de[y] + 1);
}
void del(int id) {
  int x = st[id].x, y = st[id].y;
  fa[y] = y, dis[y] = 0, de[x] = st[id].deep;
}
void copy(int x, int y) {
  for (int i = 0; i <= 30; ++i) a[y][i] = a[x][i];
}
void dfs(int l, int r, int cur) {
  int now = top, size = v[cur].size();
  for (int i = 0; i < size; ++i) {
    int id = v[cur][i], x = e[id].x, y = e[id].y, v = e[id].v;
    v ^= xor_dis(x) ^ xor_dis(y), x = find(x), y = find(y);
    if (x == y)
      ins(v, cur);
    else
      merge(x, y, v);
  }
  if (l == r) {
    int x = qu[l].x, y = qu[l].y;
    ans[l] = get(xor_dis(x) ^ xor_dis(y), cur);
  } else {
    int mid = (l + r) >> 1;
    copy(cur, ls[cur]), dfs(l, mid, ls[cur]);
    copy(cur, rs[cur]), dfs(mid + 1, r, rs[cur]);
  }
  while (top > now) del(top--);
}
int main() {
  read(n), read(m), edge_cnt = m;
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= m; ++i) {
    read(e[i].x), read(e[i].y), read(e[i].v);
    mp[make_pair(e[i].x, e[i].y)] = i, pre[i] = 1, nxt[i] = -1;
  }
  read(q);
  while (q--) {
    int opt, x, y, v;
    read(opt);
    if (opt == 1) {
      read(x), read(y), read(v);
      e[++edge_cnt] = (Edge){x, y, v};
      mp[make_pair(x, y)] = edge_cnt;
      pre[edge_cnt] = num + 1, nxt[edge_cnt] = -1;
    }
    if (opt == 2) {
      read(x), read(y);
      nxt[mp[make_pair(x, y)]] = num;
    }
    if (opt == 3) {
      read(x), read(y);
      qu[++num] = (query){x, y};
    }
  }
  build(1, num, root);
  for (int i = 1; i <= edge_cnt; ++i) {
    if (nxt[i] < 0) nxt[i] = num;
    if (pre[i] <= nxt[i]) insert(pre[i], nxt[i], 1, num, i, root);
  }
  dfs(1, num, root);
  for (int i = 1; i <= num; ++i) printf("%d\n", ans[i]);
  return 0;
}