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;
inline int read() {
  int x = 0;
  bool t = false;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = true, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return t ? -x : x;
}
struct xxj {
  int p[31];
  void insert(int x) {
    for (int i = 30; ~i; --i)
      if (x & (1 << i)) {
        if (!p[i]) {
          p[i] = x;
          break;
        }
        x ^= p[i];
      }
  }
  int Query(int x) {
    for (int i = 30; ~i; --i) x = min(x, x ^ p[i]);
    return x;
  }
} G;
struct Node {
  int u, v, w;
} p[200200 << 1];
pair<int, int> q[200200];
int n, m;
map<pair<int, int>, int> M;
vector<Node> seg[200200 << 2];
void Modify(int now, int l, int r, int L, int R, Node e) {
  if (L > R) return;
  if (L <= l && r <= R) {
    seg[now].push_back(e);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) Modify((now << 1), l, mid, L, R, e);
  if (R > mid) Modify((now << 1 | 1), mid + 1, r, L, R, e);
}
int tim, cnt, L[200200 << 1], R[200200 << 1];
int f[200200], sz[200200], Xor[200200];
int getf(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
int getxor(int x) {
  int ret = 0;
  while (x != f[x]) ret ^= Xor[x], x = f[x];
  return ret;
}
void Divide(int now, int l, int r, xxj G) {
  vector<Node> c;
  c.clear();
  for (int i = 0, lim = seg[now].size(); i < lim; ++i) {
    int u = seg[now][i].u, v = seg[now][i].v, w = seg[now][i].w;
    int f1 = getf(u), f2 = getf(v);
    if (f1 == f2)
      G.insert(getxor(u) ^ getxor(v) ^ w);
    else {
      if (sz[f1] > sz[f2]) swap(f1, f2), swap(u, v);
      w ^= getxor(v) ^ getxor(u);
      c.push_back((Node){f1, f2, sz[f2]});
      Xor[f1] = w;
      f[f1] = f2;
      sz[f2] += sz[f1];
    }
  }
  if (l == r)
    printf("%d\n", G.Query(getxor(q[l].first) ^ getxor(q[l].second)));
  else {
    int mid = (l + r) >> 1;
    Divide((now << 1), l, mid, G);
    Divide((now << 1 | 1), mid + 1, r, G);
  }
  for (int i = c.size() - 1; ~i; --i) {
    int u = c[i].u, v = c[i].v, w = c[i].w;
    sz[v] = w;
    f[u] = u;
    Xor[u] = 0;
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read(), w = read();
    p[++cnt] = (Node){x, y, w};
    L[cnt] = 1;
    M[make_pair(x, y)] = cnt;
    R[cnt] = -1;
  }
  int Q = read();
  for (int i = 1; i <= Q; ++i) {
    int opt = read(), x = read(), y = read();
    if (x > y) swap(x, y);
    if (opt == 1) {
      p[++cnt] = (Node){x, y, read()};
      L[cnt] = tim + 1;
      R[cnt] = -1;
      M[make_pair(x, y)] = cnt;
    } else if (opt == 2)
      R[M[make_pair(x, y)]] = tim;
    else
      q[++tim] = make_pair(x, y);
  }
  for (int i = 1; i <= cnt; ++i)
    if (R[i] == -1) R[i] = tim;
  for (int i = 1; i <= cnt; ++i) Modify(1, 1, tim, L[i], R[i], p[i]);
  for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;
  Divide(1, 1, tim, G);
  return 0;
}