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;
inline int rd() {
  char ch = getchar();
  int i = 0, f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    i = (i << 1) + (i << 3) + ch - '0';
    ch = getchar();
  }
  return i * f;
}
const int N = 2e5 + 50, LIM = 30;
map<pair<int, int>, int> mp;
map<pair<int, int>, int> mp_v;
int n, m;
int rk[N], val[N], anc[N];
int base[LIM + 5], pos[LIM + 5], top;
struct data {
  int u, x, y, w, c;
  data(int u, int x, int y, int w, int c) : u(u), x(x), y(y), w(w), c(c) {}
  friend inline bool operator<(const data &a, const data &b) {
    return a.u < b.u;
  }
};
vector<data> qry[N * 4];
inline void insert(int k, int l, int r, int L, int R, const data &t) {
  if (L <= l && r <= R) {
    qry[k].push_back(t);
    return;
  }
  int mid = (l + r) >> 1;
  if (R <= mid)
    insert(k << 1, l, mid, L, R, t);
  else if (L > mid)
    insert(k << 1 | 1, mid + 1, r, L, R, t);
  else
    insert(k << 1, l, mid, L, R, t), insert(k << 1 | 1, mid + 1, r, L, R, t);
}
inline pair<int, int> getanc(int x) {
  int rs = 0;
  while (x != anc[x]) rs ^= val[x], x = anc[x];
  return make_pair(x, rs);
}
inline int inc(int x) {
  for (int i = LIM; ~i; i--)
    if (pos[i] && (x & (1 << i))) x ^= base[pos[i]];
  for (int i = LIM; ~i; i--)
    if (!pos[i] && (x & (1 << i))) {
      base[++top] = x;
      pos[i] = top;
      return i;
    }
  return -1;
}
inline int query(int x, int y) {
  x = getanc(x).second ^ getanc(y).second;
  for (int i = LIM; ~i; i--)
    if (pos[i] && (x & (1 << i))) x = x ^ base[pos[i]];
  return x;
}
inline void dfs(int k, int l, int r) {
  if (l == r) sort(qry[k].begin(), qry[k].end());
  for (int i = 0; i < qry[k].size(); ++i) {
    data t = qry[k][i];
    if (t.u == 1) {
      pair<int, int> x = getanc(t.x), y = getanc(t.y);
      if (x.first == y.first) {
        int p = inc(x.second ^ y.second ^ t.w);
        if (~p) qry[k][i].c = 3 + p;
      } else {
        if (rk[x.first] < rk[y.first]) swap(x, y);
        anc[y.first] = x.first;
        val[y.first] = t.w ^ x.second ^ y.second;
        if (rk[x.first] == rk[y.first])
          ++rk[x.first], qry[k][i].c = 2;
        else
          qry[k][i].c = 1;
        qry[k][i].x = x.first, qry[k][i].y = y.first;
      }
    } else
      printf("%d\n", query(t.x, t.y));
  }
  if (l != r) {
    int mid = (l + r) >> 1;
    dfs(k << 1, l, mid);
    dfs(k << 1 | 1, mid + 1, r);
  }
  for (int i = qry[k].size() - 1; i >= 0; i--) {
    data t = qry[k][i];
    if (!t.c) continue;
    if (t.c <= 2) {
      anc[t.y] = t.y;
      val[t.y] = 0;
      rk[t.x] -= (t.c - 1);
    } else {
      pos[t.c - 3] = 0;
      --top;
    }
  }
}
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= n; i++) anc[i] = i;
  for (int i = 1; i <= m; i++) {
    int x = rd(), y = rd(), w = rd();
    if (x > y) swap(x, y);
    mp[make_pair(x, y)] = 0;
    mp_v[make_pair(x, y)] = w;
  }
  m = rd();
  for (int i = 1; i <= m; i++) {
    int op = rd(), x = rd(), y = rd();
    if (x > y) swap(x, y);
    if (op == 1) {
      int w = rd();
      mp[make_pair(x, y)] = i;
      mp_v[make_pair(x, y)] = w;
    } else if (op == 2) {
      int pre = mp[make_pair(x, y)], w = mp_v[make_pair(x, y)];
      mp.erase(mp.find(make_pair(x, y)));
      mp_v.erase(mp_v.find(make_pair(x, y)));
      insert(1, 0, m, pre, i, data(1, x, y, w, 0));
    } else
      insert(1, 0, m, i, i, data(2, x, y, 0, 0));
  }
  for (map<pair<int, int>, int>::iterator it = mp.begin(), it2 = mp_v.begin();
       it != mp.end(); ++it, ++it2)
    insert(1, 0, m, it->second, m,
           data(1, it->first.first, it->first.second, it2->second, 0));
  dfs(1, 0, m);
}