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 N = 4e5 + 10;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
struct xxj {
  int p[30];
  xxj() { memset(p, 0, sizeof(p)); }
  void insert(int x) {
    for (int i = 29; ~i; i--)
      if (x >> i & 1) {
        if (!p[i]) {
          p[i] = x;
          break;
        }
        x ^= p[i];
      }
  }
  int query(int x) {
    for (int i = 29; ~i; i--) x = min(x, x ^ p[i]);
    return x;
  }
} I;
int f[N], tag[N], siz[N];
int getf(int x) { return x == f[x] ? x : getf(f[x]); }
int calc(int x) {
  int ret = 0;
  for (int i = x; i != f[i]; i = f[i]) ret ^= tag[i];
  return ret;
}
struct eve {
  int x, y, sz;
};
struct edge {
  int u, v, w;
} e[N];
struct query {
  int u, v, ans;
} q[N];
vector<edge> tr[N << 2];
void insert(int o, int l, int r, int L, int R, edge e) {
  if (L <= l && r <= R) {
    tr[o].push_back(e);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) insert((o << 1), l, mid, L, R, e);
  if (R > mid) insert((o << 1 | 1), mid + 1, r, L, R, e);
}
void solve(int o, int l, int r, xxj a) {
  vector<eve> E;
  for (edge e : tr[o]) {
    int u = e.u, v = e.v, w = e.w, x = getf(u), y = getf(v);
    if (x == y)
      a.insert(calc(u) ^ calc(v) ^ w);
    else {
      if (siz[x] > siz[y]) swap(x, y);
      int A = calc(u), B = calc(v);
      E.push_back({x, y, siz[y]});
      f[x] = y;
      siz[y] += siz[x];
      tag[x] = A ^ B ^ w;
    }
  }
  if (l == r) {
    if (q[l].u) q[l].ans = a.query(calc(q[l].u) ^ calc(q[l].v));
  } else {
    int mid = (l + r) >> 1;
    solve((o << 1), l, mid, a);
    solve((o << 1 | 1), mid + 1, r, a);
  }
  while (!E.empty()) {
    eve now = E.back();
    E.pop_back();
    int x = now.x, y = now.y, sz = now.sz;
    f[x] = x;
    siz[y] = sz;
    tag[x] = 0;
  }
}
int n, m, Q, tim = 1, st[N], ed[N];
map<pair<int, int>, int> M;
int main() {
  cin >> n >> m;
  memset(ed, -1, sizeof(ed));
  for (int i = 1; i <= m; i++) {
    int u = gi(), v = gi(), w = gi();
    if (u > v) swap(u, v);
    e[i] = (edge){u, v, w};
    M[make_pair(u, v)] = i;
    st[i] = 1;
  }
  cin >> Q;
  while (Q--) {
    int op = gi(), u = gi(), v = gi();
    if (u > v) swap(u, v);
    if (op == 1) {
      int w = gi();
      e[++m] = (edge){u, v, w};
      M[make_pair(u, v)] = m;
      st[m] = tim;
    } else if (op == 2)
      ed[M[make_pair(u, v)]] = tim - 1;
    else if (op == 3)
      q[tim++] = {u, v};
  }
  for (int i = 1; i <= m; i++) {
    if (ed[i] == -1) ed[i] = tim;
    if (st[i] <= ed[i]) insert(1, 1, tim, st[i], ed[i], e[i]);
  }
  for (int i = 1; i <= n; i++) f[i] = i, siz[i] = 1;
  solve(1, 1, tim, I);
  for (int i = 1; i < tim; i++) printf("%d\n", q[i].ans);
  return 0;
}