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>
const int MAXN = 400010;
struct E {
  int x, y, v;
  bool operator<(E b) const { return x == b.x ? y < b.y : x < b.x; }
} es[MAXN];
int bak;
const int MAXQ = MAXN * 30;
int head[MAXN << 2], nxt[MAXQ], to[MAXQ], tot;
void addq(int b, int e) {
  nxt[++tot] = head[b];
  to[head[b] = tot] = e;
}
std::map<E, std::pair<int, int> > S;
void modify(int u, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) {
    return addq(u, v);
  }
  int mid = l + r >> 1;
  if (L <= mid) modify(u << 1, l, mid, L, R, v);
  if (mid < R) modify(u << 1 | 1, mid + 1, r, L, R, v);
}
struct linearbase {
  int a[32];
  linearbase() { memset(a, 0, 128); }
  void insert(int x) {
    for (int i = 31; ~i; --i)
      if (x >> i & 1) {
        if (!a[i]) a[i] = x;
        x ^= a[i];
      }
  }
  int query(int x) {
    for (int i = 31; ~i; --i)
      if ((x ^ a[i]) < x) x ^= a[i];
    return x;
  }
};
struct his {
  int x, v, r;
} st[MAXN << 1];
int top;
int fa[MAXN], val[MAXN], rnk[MAXN];
int n, m, initm, xs[MAXN], ys[MAXN], tnow = 1;
std::pair<int, int> find(int x) {
  int res = 0;
  while (x != fa[x]) {
    res ^= val[x];
    x = fa[x];
  }
  return std::make_pair(x, res);
}
void merge(int x, int y, int v, linearbase& L) {
  auto fx = find(x), fy = find(y);
  v ^= fx.second ^ fy.second;
  x = fx.first, y = fy.first;
  if (x == y) {
    return L.insert(v);
  }
  if (rnk[x] > rnk[y]) std::swap(x, y);
  st[++top] = (his){x, val[x], rnk[x]};
  fa[x] = y, val[x] = v;
  if (rnk[x] == rnk[y]) st[++top] = (his){y, val[y], rnk[y]++};
}
void restore(int hi) {
  while (top > hi) {
    auto t = st[top--];
    fa[t.x] = t.x;
    val[t.x] = t.v;
    rnk[t.x] = t.r;
  }
}
void solve(int u, int l, int r, linearbase now) {
  int cur = top, mid = l + r >> 1;
  for (int i = head[u]; i; i = nxt[i]) {
    auto t = es[to[i]];
    merge(t.x, t.y, t.v, now);
  }
  if (l == r) {
    auto fx = find(xs[l]), fy = find(ys[l]);
    int ans = 0;
    if (fx.first != fy.first)
      ans = -1;
    else
      ans = now.query(fx.second ^ fy.second);
    std::cout << ans << '\n';
    if (l >= tnow - 1) exit(0);
  }
  if (l < r) {
    solve(u << 1, l, mid, now);
    solve(u << 1 | 1, mid + 1, r, now);
  }
  restore(cur);
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  std::cin >> n >> initm;
  for (int i = 1, x, y, d; i <= initm; ++i) {
    std::cin >> x >> y >> d;
    ++bak;
    if (x > y) std::swap(x, y);
    S[es[bak] = (E){x, y, d}] = std::make_pair(tnow, bak);
  }
  std::cin >> m;
  for (int i = 1, opt, x, y, d; i <= m; ++i) {
    std::cin >> opt >> x >> y;
    if (x > y) std::swap(x, y);
    if (opt == 1) {
      std::cin >> d;
      ++bak;
      S[es[bak] = (E){x, y, d}] = std::make_pair(tnow, bak);
    } else if (opt == 2) {
      auto t = S.lower_bound((E){x, y, 0});
      auto v = t->second;
      if (tnow > v.first) modify(1, 1, m, v.first, tnow - 1, v.second);
      S.erase(t);
    } else {
      xs[tnow] = x, ys[tnow] = y;
      ++tnow;
    }
  }
  for (auto t : S) {
    auto v = t.second;
    if (tnow > v.first) modify(1, 1, m, v.first, tnow - 1, v.second);
  }
  for (int i = 1; i <= n; ++i) fa[i] = i;
  if (tnow > 1) solve(1, 1, m, linearbase());
  return 0;
}