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 maxN = 200000 + 5;
const int maxQ = 200000 + 5;
int lb[20][35], fa[maxN], W[maxN], sz[maxN];
int n, m, q;
struct Edge {
  int u, v, w;
};
vector<Edge> E[maxQ << 2];
vector<pair<int, int> > Q[maxQ << 2], Del[maxQ << 2];
map<pair<int, int>, pair<int, int> > mp;
void insert(int d, int val) {
  for (int i = 29; i >= 0; --i)
    if ((1 << i) & val) {
      if (lb[d][i])
        val ^= lb[d][i];
      else {
        lb[d][i] = val;
        return;
      }
    }
}
int query(int d, int val) {
  for (int i = 29; i >= 0; --i) {
    if ((val ^ lb[d][i]) < val) val ^= lb[d][i];
  }
  return val;
}
int find(int u, int &w) {
  if (fa[u] == u) return u;
  w ^= W[u];
  return find(fa[u], w);
}
void update(int u, int l, int r, int ul, int ur, Edge e) {
  if (ul <= l && r <= ur) {
    E[u].push_back(e);
    return;
  }
  int m = (l + r) >> 1;
  if (ul <= m) update(u << 1, l, m, ul, ur, e);
  if (m < ur) update(u << 1 | 1, m + 1, r, ul, ur, e);
}
void update2(int u, int l, int r, int x, pair<int, int> e) {
  if (l == r) {
    Q[u].push_back(e);
    return;
  }
  int m = (l + r) >> 1;
  if (x <= m)
    update2(u << 1, l, m, x, e);
  else
    update2(u << 1 | 1, m + 1, r, x, e);
}
void solve(int u, int l, int r, int d) {
  for (int i = 0; i <= 30; ++i) lb[d][i] = lb[d - 1][i];
  for (int i = 0; i != E[u].size(); ++i) {
    int x = E[u][i].u, y = E[u][i].v, w = E[u][i].w;
    x = find(x, w);
    y = find(y, w);
    if (x == y)
      insert(d, w);
    else {
      if (sz[x] > sz[y]) swap(x, y);
      fa[x] = y;
      sz[y] += sz[x];
      W[x] = w;
      Del[u].push_back(make_pair(x, y));
    }
  }
  if (l == r) {
    for (int i = 0; i != Q[u].size(); ++i) {
      int x = Q[u][i].first, y = Q[u][i].second, w = 0;
      x = find(x, w);
      y = find(y, w);
      printf("%d\n", query(d, w));
    }
  }
  if (l < r) {
    int m = (l + r) >> 1;
    solve(u << 1, l, m, d + 1);
    solve(u << 1 | 1, m + 1, r, d + 1);
  }
  for (int i = Del[u].size() - 1; i >= 0; --i) {
    int x = Del[u][i].first, y = Del[u][i].second;
    fa[x] = x;
    W[x] = 0;
    sz[y] -= sz[x];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (u > v) swap(u, v);
    mp[make_pair(u, v)] = make_pair(w, 1);
  }
  scanf("%d", &q);
  for (int u = 1; u <= n; ++u) {
    fa[u] = u;
    sz[u] = 1;
  }
  for (int i = 2; i <= q + 1; ++i) {
    int op, x, y, d;
    scanf("%d%d%d", &op, &x, &y);
    if (x > y) swap(x, y);
    if (op == 1) {
      scanf("%d", &d);
      mp[make_pair(x, y)] = make_pair(d, i);
    } else if (op == 2) {
      map<pair<int, int>, pair<int, int> >::iterator it =
          mp.find(make_pair(x, y));
      update(1, 1, q + 1, (*it).second.second, i - 1,
             (Edge){x, y, (*it).second.first});
      mp.erase(it);
    } else
      update2(1, 1, q + 1, i, make_pair(x, y));
  }
  for (map<pair<int, int>, pair<int, int> >::iterator it = mp.begin();
       it != mp.end(); ++it) {
    update(1, 1, q + 1, (*it).second.second, q + 1,
           (Edge){(*it).first.first, (*it).first.second, (*it).second.first});
  }
  solve(1, 1, q + 1, 1);
  return 0;
}