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 ans[200005], t[200005], val[200005];
pair<int, int> qu[200005];
set<pair<pair<int, int>, pair<int, int>>> s;
vector<pair<pair<int, int>, int>> aint[800005];
vector<int> cur;
int n, m;
pair<int, int> findt(int nod) {
  if (t[nod] < 0) return make_pair(nod, 0);
  pair<int, int> ans = findt(t[nod]);
  return make_pair(ans.first, ans.second ^ val[nod]);
}
int mini(int x) {
  for (auto it : cur) x = min(x, x ^ it);
  return x;
}
void add(int x) {
  for (auto it : cur) x = min(x, x ^ it);
  if (x == 0) return;
  for (auto &it : cur) it = min(it, it ^ x);
  cur.push_back(x);
}
void update(int nod, int st, int dr, int l, int r, int v, int u, int w) {
  if (r <= st || dr <= l) return;
  if (l <= st && dr <= r) {
    aint[nod].push_back(make_pair(make_pair(v, u), w));
    return;
  }
  int mij = (st + dr) / 2;
  update(nod * 2, st, mij, l, r, v, u, w);
  update(nod * 2 + 1, mij, dr, l, r, v, u, w);
}
void calc(int nod, int st, int dr) {
  vector<int> aux = cur;
  vector<pair<pair<int, int>, int>> aux2;
  pair<int, int> p1, p2;
  for (auto it : aint[nod]) {
    p1 = findt(it.first.first);
    p2 = findt(it.first.second);
    if (p1.first == p2.first)
      add(p1.second ^ p2.second ^ it.second);
    else {
      if (t[p1.first] > t[p2.first]) swap(p1, p2);
      aux2.push_back(make_pair(make_pair(p1.first, p2.first), t[p2.first]));
      t[p1.first] += t[p2.first];
      t[p2.first] = p1.first;
      val[p2.first] = p1.second ^ p2.second ^ it.second;
    }
  }
  if (st == dr - 1) {
    if (st < m)
      ans[st] = mini(findt(qu[st].first).second ^ findt(qu[st].second).second);
  } else {
    int mij = (st + dr) / 2;
    calc(nod * 2, st, mij);
    calc(nod * 2 + 1, mij, dr);
  }
  cur = aux;
  reverse(aux2.begin(), aux2.end());
  for (auto it : aux2) {
    t[it.first.second] = it.second;
    val[it.first.second] = 0;
    t[it.first.first] -= it.second;
  }
}
int main() {
  memset(t, -1, sizeof(t));
  scanf("%d%d", &n, &m);
  int i, q, tip, x, y, w;
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &x, &y, &w);
    if (x > y) swap(x, y);
    s.insert(make_pair(make_pair(x, y), make_pair(w, 0)));
  }
  scanf("%d", &q);
  m = 0;
  for (i = 1; i <= q; i++) {
    scanf("%d%d%d", &tip, &x, &y);
    if (x > y) swap(x, y);
    if (tip == 1)
      scanf("%d", &w), s.insert(make_pair(make_pair(x, y), make_pair(w, m)));
    if (tip == 2) {
      auto it = s.lower_bound(make_pair(make_pair(x, y), make_pair(0, 0)));
      update(1, 0, n, it->second.second, m, x, y, it->second.first);
      s.erase(it);
    }
    if (tip == 3) qu[m++] = make_pair(x, y);
  }
  for (auto it : s)
    update(1, 0, n, it.second.second, m, it.first.first, it.first.second,
           it.second.first);
  calc(1, 0, n);
  for (i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}