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 to, from, val, st, ed;
} E[800005];
struct Quer {
  int x, y;
} Q[800005];
int n, m, q, zq, zt, ze;
vector<int> id[800005];
map<pair<int, int>, int> mp;
int ql, qr, qv, f[800005], fv[800005], sze[800005];
int find(int x) { return f[x] == x ? x : find(f[x]); }
int findv(int x) { return f[x] == x ? 0 : (findv(f[x]) ^ fv[x]); }
void add(int p, int l, int r) {
  if (ql <= l && r <= qr) {
    id[p].push_back(qv);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) add(p << 1, l, mid);
  if (qr > mid) add(p << 1 | 1, mid + 1, r);
}
int ans[800005], xj[90][30], z[800005], zz;
void ins(int v, int dep) {
  for (int i = 29, ii = 1 << 29; i >= 0; --i, ii >>= 1) {
    if (v & ii) {
      if (xj[dep][i])
        v ^= xj[dep][i];
      else {
        xj[dep][i] = v;
        return;
      }
    }
  }
}
void solve(int p, int l, int r, int dep) {
  int mid = l + r >> 1, hc = zz;
  for (int i = 0, u, x, y; i < id[p].size(); ++i) {
    u = id[p][i];
    x = find(E[u].from), y = find(E[u].to);
    if (x == y)
      ins(E[u].val ^ findv(E[u].from) ^ findv(E[u].to), dep);
    else {
      if (sze[x] > sze[y]) swap(x, y);
      fv[x] = 0;
      fv[x] = findv(E[u].from) ^ findv(E[u].to) ^ E[u].val;
      f[x] = y;
      sze[y] += sze[x];
      z[++zz] = x;
    }
  }
  if (l == r) {
    int v = findv(Q[l].x) ^ findv(Q[l].y);
    for (int i = 29, ii = 1 << 29; i >= 0; --i, ii >>= 1) {
      if ((v & ii) && xj[dep][i]) v ^= xj[dep][i];
    }
    ans[l] = v;
  } else {
    for (int i = 0; i <= 29; ++i) xj[dep + 1][i] = xj[dep][i];
    solve(p << 1, l, mid, dep + 1);
    for (int i = 0; i <= 29; ++i) xj[dep + 1][i] = xj[dep][i];
    solve(p << 1 | 1, mid + 1, r, dep + 1);
  }
  while (zz != hc) {
    sze[f[z[zz]]] -= sze[z[zz]];
    fv[z[zz]] = 0;
    f[z[zz]] = z[zz];
    --zz;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int a, b, c, i = 1; i <= m; ++i) {
    scanf("%d%d%d", &E[i].from, &E[i].to, &E[i].val);
    E[i].st = 1;
    E[i].ed = 999999;
    mp[make_pair(E[i].from, E[i].to)] = i;
  }
  ze = m;
  scanf("%d", &q);
  int op, a, b;
  zt = 1;
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d%d", &op, &a, &b);
    if (op == 1) {
      E[++ze].from = a;
      E[ze].to = b;
      scanf("%d", &E[ze].val);
      E[ze].st = zt;
      E[ze].ed = 999999;
      mp[make_pair(E[ze].from, E[ze].to)] = ze;
    } else if (op == 2) {
      E[mp[make_pair(a, b)]].ed = zt - 1;
      mp[make_pair(a, b)] = 0;
    } else if (op == 3) {
      Q[zt].x = a;
      Q[zt].y = b;
      ++zt;
    }
  }
  --zt;
  if (!zt) return 0;
  for (int i = 1; i <= ze; ++i) {
    if (E[i].ed < E[i].st) continue;
    ql = E[i].st, qr = E[i].ed, qv = i;
    add(1, 1, zt);
  }
  for (int i = 1; i <= n; ++i) f[i] = i, sze[i] = 1;
  solve(1, 1, zt, 1);
  for (int i = 1; i <= zt; ++i) printf("%d\n", ans[i]);
  return 0;
}