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;
struct LinearBase {
  int w[30 + 5];
  inline void init(void) { memset(w, 0, sizeof w); }
  inline void insert(int x) {
    for (int i = 30; i >= 0; i--)
      if ((x >> i) & 1) {
        if (!w[i]) {
          w[i] = x;
          return;
        }
        x ^= w[i];
      }
  }
  inline int query(int x) {
    for (int i = 30; i >= 0; i--)
      if ((x ^ w[i]) < x) x = x ^ w[i];
    return x;
  }
} G;
const int N = 4e5 + 10;
int val[N], dis[N], fa[N];
namespace Union {
inline void init(int n) {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
inline int find(int x) { return x == fa[x] ? x : find(fa[x]); }
inline int GetDis(int x) {
  if (x == fa[x]) return 0;
  return val[x] ^ GetDis(fa[x]);
}
}  // namespace Union
struct edge {
  int x, y, z;
} e[N << 1];
struct Query {
  int x, y;
} q[N << 1];
map<pair<int, int>, int> h;
vector<edge> v[N << 2];
int n, m, times = 1, st[N << 1], ed[N << 1], cnt, Q;
int dep[N << 1];
namespace SegmentTree {
inline void insert(int p, int l, int r, int L, int R, edge E) {
  if (L <= l && r <= R) {
    v[p].push_back(E);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) insert(p << 1, l, mid, L, R, E);
  if (R > mid) insert(p << 1 | 1, mid + 1, r, L, R, E);
}
}  // namespace SegmentTree
inline void solve(int p, int l, int r, LinearBase G) {
  stack<edge> s;
  for (int i = 0; i < v[p].size(); i++) {
    int x = v[p][i].x, y = v[p][i].y, z = v[p][i].z;
    int u = Union::find(x), v = Union::find(y);
    z = z ^ Union::GetDis(x) ^ Union::GetDis(y);
    if (u == v)
      G.insert(z);
    else {
      if (dep[u] > dep[v]) swap(x, y), swap(u, v);
      edge now = (edge){u, v, 0};
      fa[u] = v;
      val[u] = z;
      if (dep[u] == dep[v]) dep[v]++, now.z = 1;
      s.push(now);
    }
  }
  if (l == r)
    printf("%d\n", G.query(Union::GetDis(q[l].x) ^ Union::GetDis(q[l].y)));
  else {
    int mid = (l + r) >> 1;
    solve(p << 1, l, mid, G);
    solve(p << 1 | 1, mid + 1, r, G);
  }
  while (!s.empty())
    val[fa[s.top().x] = s.top().x] = 0, dep[s.top().y] -= s.top().z, s.pop();
}
int main() {
  cin >> n >> m;
  Union::init(n);
  G.init();
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    h[make_pair(x, y)] = i;
    st[i] = 1;
    ed[i] = -1;
    e[i] = (edge){x, y, z};
  }
  cin >> Q;
  cnt = m;
  for (int i = 1, opt, x, y, d; i <= Q; i++) {
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) {
      scanf("%d", &d);
      h[make_pair(x, y)] = ++cnt;
      st[cnt] = times;
      ed[cnt] = -1;
      e[cnt] = (edge){x, y, d};
    } else if (opt == 2) {
      ed[h[make_pair(x, y)]] = times - 1;
    } else if (opt == 3) {
      q[times] = (Query){x, y};
      times++;
    }
  }
  times--;
  for (int i = 1; i <= cnt; i++)
    if (ed[i] == -1) ed[i] = times;
  for (int i = 1; i <= cnt; i++)
    if (st[i] <= ed[i]) SegmentTree::insert(1, 1, times, st[i], ed[i], e[i]);
  solve(1, 1, times, G);
  return 0;
}