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;
struct edge {
  int x, y, w, l, r;
} e[400010];
struct node {
  int x, y, w, fx, fy, rx, ry;
};
struct ask {
  int x, y;
} q[200010];
int n, m, Q, fa[200010], d[200010], rk[200010], p[25][35];
map<pair<int, int>, int> mp;
vector<node> v[1600010];
void ins(int k, int l, int r, int x, int y, int t) {
  if (l == x && r == y) {
    v[k].push_back((node){e[t].x, e[t].y, e[t].w, 0, 0});
    return;
  }
  int mid = (l + r) >> 1;
  if (x > mid) {
    ins(k << 1 | 1, mid + 1, r, x, y, t);
  } else if (y <= mid) {
    ins(k << 1, l, mid, x, y, t);
  } else {
    ins(k << 1, l, mid, x, mid, t);
    ins(k << 1 | 1, mid + 1, r, mid + 1, y, t);
  }
}
int find(int x, int &y) {
  y = 0;
  while (fa[x] != x) {
    y ^= d[x];
    x = fa[x];
  }
  return x;
}
void Union(int x, int y, int w) {
  if (rk[x] == rk[y]) {
    fa[x] = y;
    d[x] = w;
    rk[y]++;
  } else if (rk[x] < rk[y]) {
    fa[x] = y;
    d[x] = w;
  } else {
    fa[y] = x;
    d[y] = w;
  }
}
void add(int t, int x) {
  for (int i = 29; i >= 0; i--) {
    if (!(x & (1 << i))) {
      continue;
    }
    if (!p[t][i]) {
      p[t][i] = x;
      return;
    }
    x ^= p[t][i];
  }
}
int get(int x, int t) {
  for (int i = 29; i >= 0; i--) {
    if ((x ^ p[t][i]) < x) {
      x ^= p[t][i];
    }
  }
  return x;
}
void work(int k, int l, int r, int t) {
  for (int i = 0; i < v[k].size(); i++) {
    int x = v[k][i].x;
    int y = v[k][i].y;
    int w = v[k][i].w;
    int a, b, fx, fy;
    fx = find(x, a);
    fy = find(y, b);
    if (fx == fy) {
      add(t, w ^ a ^ b);
      continue;
    }
    v[k][i].fx = fx;
    v[k][i].fy = fy;
    v[k][i].rx = rk[fx];
    v[k][i].ry = rk[fy];
    Union(fx, fy, w ^ a ^ b);
  }
  if (l == r) {
    if (q[l].x) {
      int x = q[l].x;
      int y = q[l].y;
      int a, b;
      find(x, a);
      find(y, b);
      printf("%d\n", get(a ^ b, t));
    }
  } else {
    int mid = (l + r) >> 1;
    for (int i = 0; i < 30; i++) {
      p[t + 1][i] = p[t][i];
    }
    work(k << 1, l, mid, t + 1);
    for (int i = 0; i < 30; i++) {
      p[t + 1][i] = p[t][i];
    }
    work(k << 1 | 1, mid + 1, r, t + 1);
  }
  for (int i = (int)v[k].size() - 1; i >= 0; i--) {
    if (!v[k][i].fx) {
      continue;
    }
    int x = v[k][i].fx;
    int y = v[k][i].fy;
    fa[x] = x;
    fa[y] = y;
    d[x] = d[y] = 0;
    rk[x] = v[k][i].rx;
    rk[y] = v[k][i].ry;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
    if (e[i].x > e[i].y) {
      swap(e[i].x, e[i].y);
    }
    e[i].l = 0;
    mp[make_pair(e[i].x, e[i].y)] = i;
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int op, x, y, w;
    scanf("%d%d%d", &op, &x, &y);
    if (x > y) {
      swap(x, y);
    }
    if (op == 1) {
      scanf("%d", &w);
      m++;
      e[m].x = x;
      e[m].y = y;
      e[m].w = w;
      e[m].l = i;
      mp[make_pair(x, y)] = m;
    } else if (op == 2) {
      int tmp = mp[make_pair(x, y)];
      if (!tmp) {
        continue;
      }
      e[tmp].r = i;
      mp[make_pair(x, y)] = 0;
    } else {
      q[i] = (ask){x, y};
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!e[i].r) {
      e[i].r = Q + 1;
    }
    ins(1, 0, Q + 1, e[i].l, e[i].r, i);
  }
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    rk[i] = 1;
  }
  work(1, 0, Q + 1, 0);
  return 0;
}