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;
int n, m, q, ans[((int)201 * 1000)], par[((int)201 * 1000)],
    val[((int)201 * 1000)];
pair<int, int> qu[((int)201 * 1000)];
set<pair<pair<int, int>, pair<int, int> > > s;
vector<pair<pair<int, int>, int> > seg[4 * ((int)201 * 1000)];
vector<int> now;
pair<int, int> root(int x) {
  if (par[x] < 0) return {x, 0};
  pair<int, int> res = root(par[x]);
  return {res.first, res.second ^ val[x]};
}
int mini(int x) {
  for (auto u : now) x = min(x, x ^ u);
  return x;
}
void add(int x) {
  for (auto u : now) x = min(x, x ^ u);
  if (!x) return;
  for (auto &u : now) u = min(u, u ^ x);
  now.push_back(x);
}
void update(int ql, int qr, int v, int u, int w, int xl = 0,
            int xr = ((int)201 * 1000), int id = 1) {
  if (qr <= xl || xr <= ql) return;
  if (ql <= xl && xr <= qr) {
    seg[id].push_back({{v, u}, w});
    return;
  }
  int mid = (xl + xr) / 2;
  update(ql, qr, v, u, w, xl, mid, id * 2);
  update(ql, qr, v, u, w, mid, xr, id * 2 + 1);
}
void walk(int xl = 0, int xr = ((int)201 * 1000), int id = 1) {
  vector<int> ex = now;
  vector<pair<pair<int, int>, int> > ex2;
  for (auto u : seg[id]) {
    pair<int, int> p1 = root(u.first.first), p2 = root(u.first.second);
    if (p1.first == p2.first)
      add(p1.second ^ p2.second ^ u.second);
    else {
      if (par[p1.first] > par[p2.first]) swap(p1, p2);
      ex2.push_back({{p1.first, p2.first}, par[p2.first]});
      par[p1.first] += par[p2.first];
      par[p2.first] = p1.first;
      val[p2.first] = p2.second ^ p1.second ^ u.second;
    }
  }
  if (xl == xr - 1) {
    if (xl < m)
      ans[xl] = mini(root(qu[xl].first).second ^ root(qu[xl].second).second);
  } else {
    int mid = (xl + xr) / 2;
    walk(xl, mid, id * 2);
    walk(mid, xr, id * 2 + 1);
  }
  now = ex;
  reverse(ex2.begin(), ex2.end());
  for (auto u : ex2) {
    par[u.first.second] = u.second;
    val[u.first.second] = 0;
    par[u.first.first] -= u.second;
  }
}
int main() {
  memset(par, -1, sizeof par);
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int v, u, w;
    scanf("%d%d%d", &v, &u, &w);
    if (v > u) swap(v, u);
    s.insert({{v, u}, {w, 0}});
  }
  scanf("%d", &q);
  m = 0;
  while (q--) {
    int t, v, u, w;
    scanf("%d%d%d", &t, &v, &u);
    if (v > u) swap(v, u);
    if (t == 1) scanf("%d", &w), s.insert({{v, u}, {w, m}});
    if (t == 2) {
      auto it = s.lower_bound({{v, u}, {0, 0}});
      update(it->second.second, m, v, u, it->second.first);
      s.erase(it);
    }
    if (t == 3) qu[m++] = {v, u};
  }
  for (auto u : s)
    update(u.second.second, m, u.first.first, u.first.second, u.second.first);
  walk();
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}