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 = 1e6 + 5;
int Q[N], x[N], y[N], d[N];
vector<int> base;
int getid(int l, int r) { return (l + r + 2) | (l < r); }
void add(int x) {
  for (auto &t : base) x = min(x, x ^ t);
  if (x) {
    for (auto &t : base) t = min(t, t ^ x);
    base.push_back(x);
  }
}
int query(int x) {
  for (auto &t : base) x = min(x, x ^ t);
  return x;
}
vector<vector<int> > seg[N];
void cover(int ql, int qr, int l, int r, vector<int> t) {
  int n = getid(l, r);
  if (ql == l && qr == r) {
    seg[n].push_back(t);
    return;
  }
  int m = (l + r) / 2;
  if (qr <= m)
    cover(ql, qr, l, m, t);
  else if (ql > m)
    cover(ql, qr, m + 1, r, t);
  else {
    cover(ql, m, l, m, t);
    cover(m + 1, qr, m + 1, r, t);
  }
}
int fa[N], ra[N], w[N];
stack<pair<int *, int> > stk;
void init(int n) {
  for (int i = 1; i <= n; i++) fa[i] = i, ra[i] = w[i] = 0;
  while (!stk.empty()) stk.pop();
}
int find(int x) {
  while (fa[x] != x) x = fa[x];
  return x;
}
int get(int x) {
  int res = 0;
  while (x != fa[x]) {
    res ^= w[x];
    x = fa[x];
  }
  return res;
}
bool merge(int x, int y, int z) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return 0;
  if (ra[fx] < ra[fy]) {
    stk.push({&w[fx], w[fx]});
    w[fx] = get(x) ^ get(y) ^ z;
    stk.push({&fa[fx], fa[fx]});
    fa[fx] = fy;
  } else {
    stk.push({&w[fy], w[fy]});
    w[fy] = get(x) ^ get(y) ^ z;
    stk.push({&fa[fy], fa[fy]});
    fa[fy] = fx;
    if (ra[fx] == ra[fy]) {
      stk.push({&ra[fx], ra[fx]});
      ra[fx]++;
    }
  }
  return 1;
}
void rollback(int x) {
  while ((int)stk.size() > x) {
    *stk.top().first = stk.top().second;
    stk.pop();
  }
}
void solve(int l, int r) {
  int n = getid(l, r), m = (l + r) / 2, t = (int)stk.size();
  vector<int> tbase = base;
  for (int i = 0; i < (int)seg[n].size(); i++) {
    int u = seg[n][i][0], v = seg[n][i][1], w = seg[n][i][2];
    if (!merge(u, v, w)) add(get(u) ^ get(v) ^ w);
  }
  if (l == r) {
    if (Q[l] == 3) printf("%d\n", query(get(x[l]) ^ get(y[l])));
  } else {
    solve(l, m);
    solve(m + 1, r);
  }
  rollback(t);
  base = tbase;
}
int main() {
  int n, m, u, v, w;
  scanf("%d%d", &n, &m);
  map<pair<int, int>, pair<int, int> > make_pair;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    make_pair[{u, v}] = {w, 0};
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &Q[i]);
    if (Q[i] == 1) {
      scanf("%d%d%d", &x[i], &y[i], &d[i]);
      make_pair[{x[i], y[i]}] = {d[i], i};
    } else if (Q[i] == 2) {
      scanf("%d%d", &x[i], &y[i]);
      pair<int, int> t = make_pair[{x[i], y[i]}];
      cover(t.second, i - 1, 0, q, {x[i], y[i], t.first});
      make_pair.erase({x[i], y[i]});
    } else
      scanf("%d%d", &x[i], &y[i]);
  }
  for (auto &t : make_pair)
    cover(t.second.second, q, 0, q,
          {t.first.first, t.first.second, t.second.first});
  init(n);
  solve(0, q);
  return 0;
}