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;
template <typename T>
inline T read() {
  register T sum = 0;
  register char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T &a) {
  a = read<T>();
  return a;
}
template <typename T, typename... Others>
inline void read(T &a, Others &...b) {
  a = read(a);
  read(b...);
}
struct Data {
  int x;
  int y;
  bool operator<(const Data &o) const {
    return x < o.x || (x == o.x && y < o.y);
  }
} Q[200010];
struct Edge {
  int x;
  int y;
  int v;
} e[200010 << 1], s[200010 << 1];
struct Basis {
  int v[31];
  void insert(int x) {
    for (int i = 30; i >= 0; i--)
      if (x & (1 << i)) {
        if (!v[i]) {
          v[i] = x;
          return;
        }
        x ^= v[i];
      }
  }
  int query(int x) {
    for (int i = 30; i >= 0; i--) x = min(x, x ^ v[i]);
    return x;
  }
} B;
int n, m, q, tp, cnt, tim, L[200010 << 1], R[200010 << 1], fa[200010],
    fv[200010], siz[200010];
vector<int> node[200010 << 2];
map<Data, int> mp;
int find(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
int findxor(int x) {
  int res = 0;
  while (x != fa[x]) res ^= fv[x], x = fa[x];
  return res;
}
void insert(int k, int l, int r, int x, int y, int z) {
  if (l >= x && r <= y) {
    node[k].push_back(z);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) insert(k << 1, l, mid, x, y, z);
  if (y > mid) insert(k << 1 | 1, mid + 1, r, x, y, z);
}
void query(int k, int l, int r, Basis v) {
  int t = tp, lim = node[k].size();
  for (int i = 0; i < lim; i++) {
    int x = find(e[node[k][i]].x), y = find(e[node[k][i]].y);
    int z =
        e[node[k][i]].v ^ findxor(e[node[k][i]].x) ^ findxor(e[node[k][i]].y);
    if (x != y) {
      if (siz[x] > siz[y]) swap(x, y);
      s[++tp] = (Edge){x, y, siz[y]};
      fa[x] = y;
      fv[x] = z;
      siz[y] += siz[x];
    } else
      v.insert(z);
  }
  if (l == r)
    printf("%d\n", v.query(findxor(Q[l].x) ^ findxor(Q[l].y)));
  else {
    int mid = (l + r) >> 1;
    query(k << 1, l, mid, v);
    query(k << 1 | 1, mid + 1, r, v);
  }
  while (tp > t) {
    fa[s[tp].x] = s[tp].x;
    fv[s[tp].x] = 0;
    siz[s[tp].y] = s[tp].v;
    tp -= 1;
  }
}
int main() {
  read(n, m);
  for (int i = 1; i <= m; i++) {
    cnt += 1;
    read(e[cnt].x, e[cnt].y, e[cnt].v);
    if (e[cnt].x > e[cnt].y) swap(e[cnt].x, e[cnt].y);
    mp[(Data){e[cnt].x, e[cnt].y}] = cnt;
    L[cnt] = 1;
    R[cnt] = -1;
  }
  q = read<int>();
  for (int i = 1; i <= q; i++) {
    int op = read<int>(), x = read<int>(), y = read<int>();
    if (x > y) swap(x, y);
    if (op == 1) {
      cnt += 1;
      L[cnt] = tim + 1;
      R[cnt] = -1;
      e[cnt].x = x;
      e[cnt].y = y;
      e[cnt].v = read<int>();
      mp[(Data){x, y}] = cnt;
    }
    if (op == 2) R[mp[(Data){x, y}]] = tim;
    if (op == 3) Q[++tim] = (Data){x, y};
  }
  for (int i = 1; i <= cnt; i++) {
    if (R[i] == -1) R[i] = tim;
    if (L[i] <= R[i]) insert(1, 1, tim, L[i], R[i], i);
  }
  for (int i = 1; i <= n; i++) fa[i] = i, siz[i] = 1;
  query(1, 1, tim, B);
  return 0;
}