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 _Tp>
inline _Tp read(_Tp& x) {
  char c11 = getchar(), ob = 0;
  x = 0;
  while (c11 ^ '-' && !isdigit(c11)) c11 = getchar();
  if (c11 == '-') c11 = getchar(), ob = 1;
  while (isdigit(c11)) x = x * 10 + c11 - '0', c11 = getchar();
  if (ob) x = -x;
  return x;
}
int n, m, Q, f[200050], siz[200050], bas[35][22], dis[200050];
map<pair<int, int>, int> ma;
struct edge {
  int from, to, v, st, en;
} e[800050];
struct question {
  int x, y, t;
} q[200050];
struct node {
  int from, to, sizfrom, sizto, disfrom, disto;
};
queue<node> g[22];
int finddis(int x) {
  int ret = 0;
  while (x != f[x]) {
    ret ^= dis[x];
    x = f[x];
  }
  return ret;
}
int find(int x) {
  while (x != f[x]) x = f[x];
  return x;
}
void clear(int dep) {
  while (!g[dep].empty()) {
    node u = g[dep].front();
    g[dep].pop();
    f[u.from] = u.from;
    siz[u.from] = u.sizfrom;
    dis[u.from] = u.disfrom;
    f[u.to] = u.to;
    siz[u.to] = u.sizto;
    dis[u.to] = u.disto;
  }
  for (int i = 1; i <= 30; ++i) bas[i][dep] = 0;
}
vector<int> vec[800005];
void cdq(int L, int R, int d, int rt) {
  for (int i = 0; i < vec[rt].size(); ++i) {
    edge u = e[vec[rt][i]];
    int a = find(u.from);
    int b = find(u.to);
    if (a != b) {
      g[d].push({a, b, siz[a], siz[b], dis[a], dis[b]});
      if (siz[a] > siz[b]) {
        f[b] = a;
        dis[b] = ((finddis(u.from)) ^ (finddis(u.to)) ^ u.v);
        siz[a] += siz[b];
      } else {
        f[a] = b;
        dis[a] = ((finddis(u.from)) ^ (finddis(u.to)) ^ u.v);
        siz[b] += siz[a];
      }
    } else {
      int g = ((finddis(u.from)) ^ (finddis(u.to)) ^ u.v);
      for (int j = 30; j >= 0; --j) {
        if ((g >> j)) {
          if (!bas[j][d]) {
            bas[j][d] = g;
            break;
          } else
            (g ^= bas[j][d]);
        }
      }
    }
  }
  if (L == R) {
    int a = finddis(q[L].x);
    int b = finddis(q[L].y);
    int ret = (a ^ b);
    for (int j = 30; j >= 0; --j) {
      if ((ret ^ bas[j][d]) < ret) {
        ret ^= bas[j][d];
      }
    }
    printf("%d\n", ret);
    clear(d);
    return;
  }
  int mid = (L + R) >> 1;
  for (int j = 0; j <= 30; ++j) bas[j][d + 1] = bas[j][d];
  cdq(L, mid, d + 1, rt << 1);
  for (int j = 0; j <= 30; ++j) bas[j][d + 1] = bas[j][d];
  cdq(mid + 1, R, d + 1, rt << 1 | 1);
  clear(d);
}
void ins(int d, int l, int r, int x, int y, int id) {
  if (x > y) return;
  if (l == x && r == y) {
    vec[d].push_back(id);
    return;
  }
  int mid = (l + r) / 2;
  if (y <= mid)
    ins(d * 2, l, mid, x, y, id);
  else if (x > mid)
    ins(d * 2 + 1, mid + 1, r, x, y, id);
  else
    ins(d * 2, l, mid, x, mid, id), ins(d * 2 + 1, mid + 1, r, mid + 1, y, id);
}
int main() {
  read(n);
  read(m);
  int a, b, c, d;
  int tot = 0, tq = 0;
  for (int i = 1; i <= m; ++i) {
    read(a);
    read(b);
    read(c);
    e[++tot] = {a, b, c, 1, 1061109567};
    ma[make_pair(a, b)] = tot;
  }
  for (int i = 1; i <= n; ++i) {
    f[i] = i;
    siz[i] = 1;
    dis[i] = 0;
  }
  read(Q);
  for (int i = 1; i <= Q; ++i) {
    read(a);
    if (a == 1) {
      read(b);
      read(c);
      read(d);
      e[++tot] = {b, c, d, tq + 1, 1061109567};
      ma[make_pair(b, c)] = tot;
    } else if (a == 2) {
      read(b);
      read(c);
      e[ma[make_pair(b, c)]].en = tq;
    } else {
      read(b);
      read(c);
      q[++tq] = {b, c, i};
    }
  }
  for (int i = 1; i <= tot; ++i)
    ins(1, 1, tq, e[i].st, e[i].en == 1061109567 ? tq : e[i].en, i);
  cdq(1, tq, 0, 1);
}