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;
map<pair<int, int>, int> mp, tim;
pair<int, int> qry[200004];
vector<pair<pair<int, int>, int> > g[524300];
void updqry(int l, int r, int id, int a, int b, pair<pair<int, int>, int> x) {
  if (r < a || b < l) return;
  if (a <= l && r <= b) {
    g[id].push_back(x);
    return;
  }
  int mid = (l + r) >> 1;
  updqry(l, mid, id << 1, a, b, x), updqry(mid + 1, r, id << 1 | 1, a, b, x);
}
int bas[30];
void ins(int x) {
  for (int i = 29; ~i; i--)
    if ((1 << i) & x) {
      if (!bas[i]) {
        bas[i] = x;
        break;
      }
      x ^= bas[i];
    }
}
int f[200004], xorsum[200004], dep[200004];
stack<pair<pair<int, int>, int> > st;
pair<int, int> F(int x) {
  int res = 0;
  while (f[x] != x) res ^= xorsum[x], x = f[x];
  return make_pair(x, res);
}
void merge(int x, int y, int d) {
  if (dep[x] > dep[y]) swap(x, y);
  st.push(make_pair(make_pair(x, y), dep[y]));
  dep[y] = max(dep[y], dep[x] + 1);
  xorsum[x] = d, f[x] = y;
}
void solsegtree(int l, int r, int id) {
  int bas1[30];
  for (int i = 0; i < 30; i++) bas1[i] = bas[i];
  int cur = st.size();
  for (auto x : g[id]) {
    int u = x.first.first, v = x.first.second, d = x.second;
    pair<int, int> uu = F(u), vv = F(v);
    if (uu.first != vv.first)
      merge(uu.first, vv.first, d ^ uu.second ^ vv.second);
    else
      ins(uu.second ^ vv.second ^ d);
  }
  if (l != r) {
    int mid = (l + r) >> 1;
    solsegtree(l, mid, id << 1), solsegtree(mid + 1, r, id << 1 | 1);
  } else if (qry[l].first != 0) {
    int u = qry[l].first, v = qry[l].second;
    pair<int, int> uu = F(u), vv = F(v);
    int ans = uu.second ^ vv.second;
    for (int i = 29; ~i; i--)
      if (ans > (ans ^ bas[i])) ans ^= bas[i];
    printf("%d\n", ans);
  }
  for (int i = 0; i < 30; i++) bas[i] = bas1[i];
  while (st.size() > cur) {
    pair<pair<int, int>, int> x = st.top();
    st.pop();
    xorsum[x.first.first] = 0, f[x.first.first] = x.first.first;
    dep[x.first.second] = x.second;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v, d;
    scanf("%d%d%d", &u, &v, &d);
    if (u > v) swap(u, v);
    mp[make_pair(u, v)] = d;
    tim[make_pair(u, v)] = 1;
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int op, x, y, d;
    scanf("%d%d%d", &op, &x, &y);
    if (x > y) swap(x, y);
    if (op == 1) {
      scanf("%d", &d);
      mp[make_pair(x, y)] = d, tim[make_pair(x, y)] = i;
    }
    if (op == 2) {
      int times = tim[make_pair(x, y)], len = mp[make_pair(x, y)];
      updqry(1, q, 1, times, i - 1, make_pair(make_pair(x, y), len));
      tim[make_pair(x, y)] = 0;
    }
    if (op == 3) qry[i] = make_pair(x, y);
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  for (auto it = tim.begin(); it != tim.end(); it++)
    if ((it->second) != 0)
      updqry(1, q, 1, it->second, q, make_pair(it->first, mp[(it->first)]));
  solsegtree(1, q, 1);
}