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;
int n, m, Q, cnt, top, head[1000100], vis[1000100], que[1000100 * 2],
    lst[1000100 * 4], sta[1000100];
struct point {
  int x, y, z, l, r, p;
} q[1000100 * 2];
struct edge {
  int x, y, z;
};
struct bcj {
  int fa, dis, sz;
} b[1000100], ys[1000100];
struct xxj {
  int d[32];
  void insert(int x) {
    for (int i = 30; i >= 0; i--)
      if (x & (1 << i)) {
        if (!d[i]) d[i] = x;
        x ^= d[i];
      }
  }
  int get_min(int x) {
    for (int i = 30; i >= 0; i--)
      if (x & (1 << i)) x ^= d[i];
    return x;
  }
} D[25];
vector<edge> v[1000100 * 8];
map<pair<int, int>, int> mp;
int get_dis(int x, int &ret) {
  while (x != b[x].fa) ret ^= b[x].dis, x = b[x].fa;
  return x;
}
void modify(int x, int l, int r, int L, int R, edge p) {
  if (l >= L && r <= R) return v[x].push_back(p), void();
  int mid = (l + r) >> 1;
  if (L <= mid) modify(x << 1, l, mid, L, R, p);
  if (R > mid) modify(x << 1 | 1, mid + 1, r, L, R, p);
}
void add(int x, int l, int r, int pos) {
  vis[x] = 1;
  int mid = (l + r) >> 1;
  if (l == r) return;
  if (pos <= mid)
    add(x << 1, l, mid, pos);
  else
    add(x << 1 | 1, mid + 1, r, pos);
}
void solve(int x, int l, int r, int d) {
  lst[x] = top;
  D[d] = D[d - 1];
  for (int i = 0; i < v[x].size(); i++) {
    edge now = v[x][i];
    int fx, fy, dis1 = 0, dis2 = 0;
    fx = get_dis(now.x, dis1), fy = get_dis(now.y, dis2);
    sta[++top] = fx;
    ys[top] = b[fx];
    sta[++top] = fy;
    ys[top] = b[fy];
    if (fx == fy)
      D[d].insert(dis1 ^ dis2 ^ now.z);
    else {
      if (b[fx].sz < b[fy].sz) swap(fx, fy);
      b[fy].fa = fx;
      b[fy].dis = dis1 ^ dis2 ^ now.z;
      b[fx].sz += b[fy].sz;
    }
  }
  if (l == r) {
    int L = q[que[l]].x, R = q[que[l]].y, w = 0;
    get_dis(L, w);
    get_dis(R, w);
    printf("%d\n", D[d].get_min(w));
    return;
  }
  int mid = (l + r) >> 1;
  if (vis[x << 1]) solve(x << 1, l, mid, d + 1);
  if (vis[x << 1 | 1]) solve(x << 1 | 1, mid + 1, r, d + 1);
  while (top > lst[x]) b[sta[top]] = ys[top--];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    mp[make_pair(x, y)] = ++cnt;
    q[cnt].x = x;
    q[cnt].y = y;
    q[cnt].z = z;
    q[cnt].l = 1;
  }
  scanf("%d", &Q);
  for (int i = 1, opt, x, y, z; i <= Q; i++) {
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) {
      scanf("%d", &z);
      mp[make_pair(x, y)] = ++cnt;
      q[cnt].x = x;
      q[cnt].y = y;
      q[cnt].z = z;
      q[cnt].l = i;
    } else if (opt == 2)
      q[mp[make_pair(x, y)]].r = i;
    else
      q[++cnt].x = x, q[cnt].y = y, q[cnt].p = i;
  }
  for (int i = 1; i <= cnt; i++)
    if (!q[i].p && !q[i].r) q[i].r = Q;
  for (int i = 1; i <= cnt; i++)
    if (!q[i].p)
      modify(1, 1, Q, q[i].l, q[i].r, (edge){q[i].x, q[i].y, q[i].z});
    else
      add(1, 1, Q, q[i].p), que[q[i].p] = i;
  for (int i = 1; i <= n; i++) b[i].fa = i, b[i].sz = 1;
  solve(1, 1, Q, 1);
}