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 N = 400000 + 10;
using PII = pair<int, int>;
struct Base {
  int p[31];
  void ins(int x) {
    for (int j = 30; ~j; --j)
      if ((x >> j) & 1) {
        if (!p[j]) {
          p[j] = x;
          return;
        }
        x ^= p[j];
      }
  }
  int ask(int x) {
    for (int j = 30; ~j; --j) x = min(x, x ^ p[j]);
    return x;
  }
} S;
int st[N << 1], top, f[N], val[N], d[N];
void init(int n) {
  for (int i = 1; i <= n; i++) f[i] = i, val[i] = 0, d[i] = 1;
  top = 0;
}
int sf(int x) { return f[x] == x ? x : sf(f[x]); }
int ask(int x) {
  int res = 0;
  for (; x != f[x]; x = f[x]) res ^= val[x];
  return res;
}
void back(int tag) {
  for (; top != tag; top--) {
    if (st[top] < 0)
      d[-st[top]]--;
    else {
      f[st[top]] = st[top];
      val[st[top]] = 0;
    }
  }
}
void Union(int x, int y, int _val) {
  if (d[x] > d[y]) swap(x, y);
  if (d[x] == d[y]) d[y]++, st[++top] = -y;
  f[x] = y;
  val[x] = _val;
  st[++top] = x;
}
struct data1 {
  int x, y, w, l, r;
} E[N];
struct data2 {
  int x, y;
} Q[N];
vector<int> v[N << 1];
int idx(int l, int r) { return l + r | l != r; }
void upd(int l, int r, int y) {
  int x = idx(l, r), mid = (l + r) >> 1;
  if (E[y].l <= l && r <= E[y].r) {
    v[x].push_back(y);
    return;
  }
  if (E[y].l <= mid) upd(l, mid, y);
  if (E[y].r > mid) upd(mid + 1, r, y);
}
void dfs(int l, int r, Base S) {
  int x = idx(l, r), t = top, mid = (l + r) >> 1;
  for (auto y : v[x]) {
    int fx = sf(E[y].x), fy = sf(E[y].y);
    int dx = ask(E[y].x), dy = ask(E[y].y);
    if (fx == fy) {
      S.ins(dx ^ dy ^ E[y].w);
      continue;
    }
    Union(fx, fy, dx ^ dy ^ E[y].w);
  }
  if (l == r) {
    int dx = ask(Q[l].x), dy = ask(Q[l].y);
    printf("%d\n", S.ask(dx ^ dy));
    back(t);
    return;
  }
  dfs(l, mid, S);
  dfs(mid + 1, r, S);
  back(t);
}
map<PII, int> id;
int n, m, x, y, z, q, op, tot;
int main() {
  scanf("%d%d", &n, &m);
  init(n);
  tot = 0;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (x > y) swap(x, y);
    E[i] = {x, y, z, tot + 1, -1};
    id[{x, y}] = i;
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d%d", &x, &y, &z);
      if (x > y) swap(x, y);
      E[++m] = {x, y, z, tot + 1, -1};
      id[{x, y}] = m;
    } else if (op == 2) {
      scanf("%d%d", &x, &y);
      if (x > y) swap(x, y);
      E[id[{x, y}]].r = tot;
    } else {
      scanf("%d%d", &x, &y);
      Q[++tot] = {x, y};
    }
  }
  for (int i = 1; i <= m; i++) {
    if (E[i].r == -1) E[i].r = tot;
    if (E[i].l <= E[i].r) upd(1, tot, i);
  }
  dfs(1, tot, S);
  return 0;
}