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 maxn = 2e5 + 5;
int n, m, q, cnt, top;
int f[maxn], dis[maxn], siz[maxn], rg[maxn][2];
struct lst {
  int i, x, y, z;
} p[maxn << 1];
vector<lst> o[maxn << 2];
vector<pair<int, int> > que[maxn];
map<pair<int, int>, int> ys;
struct node {
  int d[31];
  void ins(int x) {
    for (int i = 30; i >= 0; i--) {
      if (x & (1 << i)) {
        if (d[i])
          x ^= d[i];
        else {
          d[i] = x;
          break;
        }
      }
    }
  }
  void getmn(int x) {
    int res = x;
    for (int i = 30; i >= 0; i--) res = min(res, res ^ d[i]);
    printf("%d\n", res);
  }
} t;
int getf(int x) { return (f[x] == x) ? x : getf(f[x]); }
int getdis(int x) { return (f[x] == x) ? dis[x] : dis[x] ^ getdis(f[x]); }
bool fux(int x, int y, int z) {
  int tx = getf(x), ty = getf(y);
  if (tx == ty) return 1;
  if (siz[tx] > siz[ty]) swap(x, y), swap(tx, ty);
  siz[ty] += siz[tx];
  dis[tx] = getdis(x) ^ getdis(y) ^ z;
  f[tx] = ty;
  rg[++top][0] = tx, rg[top][1] = ty;
  return 0;
}
void del() {
  int tx = rg[top][0], ty = rg[top--][1];
  f[tx] = tx;
  dis[tx] = 0;
  siz[ty] -= siz[tx];
}
void add(int v, int l, int r, int tl, int tr, int id) {
  if (l > tr || tl > r) return;
  if (tl <= l && r <= tr) {
    o[v].push_back(p[id]);
    return;
  }
  int mid = (l + r) >> 1;
  add(v * 2, l, mid, tl, tr, id);
  add(v * 2 + 1, mid + 1, r, tl, tr, id);
}
void ask(int v, int l, int r, node t) {
  int x, y, z, las = top;
  for (int i = 0; i < o[v].size(); i++)
    if (fux(x = o[v][i].x, y = o[v][i].y, z = o[v][i].z))
      t.ins(getdis(x) ^ getdis(y) ^ z);
  if (l == r) {
    for (int i = 0; i < que[l].size(); i++) {
      x = que[l][i].first, y = que[l][i].second;
      t.getmn(getdis(x) ^ getdis(y));
    }
  } else {
    int mid = (l + r) >> 1;
    ask(v * 2, l, mid, t);
    ask(v * 2 + 1, mid + 1, r, t);
  }
  while (top > las) del();
}
int main() {
  int op, x, y, z;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    if (x > y) swap(x, y);
    p[ys[make_pair(x, y)] = ++cnt] = (lst){1, x, y, z};
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d %d", &op, &x, &y);
    if (x > y) swap(x, y);
    if (op == 1)
      scanf("%d", &z), p[ys[make_pair(x, y)] = ++cnt] = (lst){i, x, y, z};
    if (op == 2)
      z = ys[make_pair(x, y)], add(1, 1, q, p[z].i, i - 1, z),
      ys[make_pair(x, y)] = 0;
    if (op == 3) que[i].push_back(make_pair(x, y));
  }
  for (int i = 1; i <= cnt; i++)
    if (ys[make_pair(p[i].x, p[i].y)]) add(1, 1, q, p[i].i, q, i);
  ask(1, 1, q, t);
  return 0;
}