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 MN = 200010;
struct Edge {
  int u, v, w;
  bool operator<(const Edge &i) const {
    if (u != i.u) return u < i.u;
    if (v != i.v) return v < i.v;
    if (w != i.w) return w < i.w;
    return false;
  }
};
struct Info {
  int u, v, add;
};
int fa[MN], rnk[MN], Xor[MN];
void init() {
  for (int i = 0; i < MN; i++) {
    fa[i] = i;
    rnk[i] = 0;
    Xor[i] = 0;
  }
}
int diff(int u) {
  if (fa[u] == u)
    return 0;
  else
    return Xor[u] ^ diff(fa[u]);
}
int find(int u) {
  if (fa[u] == u)
    return u;
  else
    return find(fa[u]);
}
void mrg(int u, int v, int d, stack<Info> &stk) {
  d ^= diff(u);
  d ^= diff(v);
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (rnk[u] < rnk[v]) swap(u, v);
  Info info = {u, v, 0};
  fa[v] = u;
  Xor[v] = d;
  if (rnk[u] == rnk[v]) rnk[u]++, info.add++;
  stk.push(info);
}
void add(int v, vector<int> &basis) {
  for (int i = 0; i < basis.size(); i++) {
    v = min(v, v ^ basis[i]);
    if (basis[i] < v) {
      swap(basis[i], v);
    }
  }
  if (v) basis.push_back(v);
}
int N, M, Q;
map<Edge, int> la;
map<pair<int, int>, int> W;
pair<int, int> query[MN];
struct BIT {
  vector<vector<Edge> > tree;
  void init() { tree = vector<vector<Edge> >(4 * Q); }
  void upd(int a, int b, Edge e, int l, int r, int n) {
    if (b < l || r < a) return;
    if (a <= l && r <= b) {
      tree[n].push_back(e);
      return;
    }
    int m = (l + r) >> 1;
    upd(a, b, e, l, m, 2 * n);
    upd(a, b, e, m + 1, r, 2 * n + 1);
  }
  void dfs(int l, int r, int n, vector<int> basis) {
    stack<Info> stk;
    for (int i = 0; i < tree[n].size(); i++) {
      int u = tree[n][i].u;
      int v = tree[n][i].v;
      int w = tree[n][i].w;
      if (find(u) == find(v)) {
        int x = diff(u);
        int y = diff(v);
        add(x ^ y ^ w, basis);
      } else
        mrg(u, v, w, stk);
    }
    if (l == r) {
      if (query[l] != pair<int, int>(0, 0)) {
        int x = query[l].first;
        int y = query[l].second;
        int t = diff(x) ^ diff(y);
        for (int i = 0; i < basis.size(); i++) {
          t = min(t, t ^ basis[i]);
        }
        cout << t << '\n';
      }
    } else {
      int m = (l + r) >> 1;
      dfs(l, m, 2 * n, basis);
      dfs(m + 1, r, 2 * n + 1, basis);
    }
    while (!stk.empty()) {
      Info t = stk.top();
      stk.pop();
      fa[t.v] = t.v;
      rnk[t.u] -= t.add;
    }
  }
} bit;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    if (u > v) swap(u, v);
    la[{u, v, w}] = 0;
    W[{u, v}] = w;
  }
  cin >> Q;
  bit.init();
  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int x, y, d;
      cin >> x >> y >> d;
      x--;
      y--;
      if (x > y) swap(x, y);
      la[{x, y, d}] = i;
      W[{x, y}] = d;
    }
    if (t == 2) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      if (x > y) swap(x, y);
      int d = W[{x, y}];
      int s = la[{x, y, d}];
      bit.upd(s, i, {x, y, d}, 0, Q - 1, 1);
      la.erase({x, y, d});
    }
    if (t == 3) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      query[i] = pair<int, int>(x, y);
    }
  }
  for (auto it = la.begin(); it != la.end(); it++) {
    int s = it->second;
    bit.upd(s, Q - 1, it->first, 0, Q - 1, 1);
  }
  init();
  bit.dfs(0, Q - 1, 1, vector<int>());
}