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 = 4e5 + 5;
class edge {
 public:
  int u, v, c;
};
edge e[maxn];
vector<int> adj[4 * maxn], ask[maxn];
map<pair<int, int>, int> last;
int N, M, Q;
int basis[30];
int lab[maxn], dist[maxn];
vector<pair<int*, int>> data;
int add(int mask) {
  for (int i = 29; i >= 0; --i)
    if (mask >> i & 1) {
      if (!basis[i]) {
        basis[i] = mask;
        return i;
      }
      mask ^= basis[i];
    }
  return -1;
}
int FindLab(int u) { return lab[u] < 0 ? u : FindLab(lab[u]); }
int FindDist(int u) { return lab[u] < 0 ? 0 : (dist[u] ^ FindDist(lab[u])); }
void Change(int& u, int v) {
  data.push_back(make_pair(&u, u));
  u = v;
}
void rollback(int sz) {
  while (data.size() > sz) {
    (*data.back().first) = data.back().second;
    data.pop_back();
  }
}
void update(int x, int l, int r, int L, int R, int val) {
  if (L > r || l > R) return;
  if (L <= l && r <= R) {
    adj[x].push_back(val);
    return;
  }
  int mid = l + r >> 1;
  update(x * 2, l, mid, L, R, val);
  update(x * 2 + 1, mid + 1, r, L, R, val);
}
int Query(int u, int v) {
  int res = (FindDist(u) ^ FindDist(v));
  for (int i = 29; i >= 0; --i) {
    if (res > (res ^ basis[i])) res ^= basis[i];
  }
  return res;
}
int Merge(int u, int v, int c) {
  int du = FindDist(u);
  int dv = FindDist(v);
  u = FindLab(u);
  v = FindLab(v);
  c ^= du ^ dv;
  if (u == v) return add(c);
  if (lab[u] > lab[v]) swap(u, v);
  Change(lab[u], lab[u] + lab[v]);
  Change(lab[v], u);
  Change(dist[v], c);
  return -1;
}
void go(int x, int l, int r) {
  int tmp = data.size();
  vector<int> d;
  for (auto c : adj[x]) {
    d.push_back(Merge(e[c].u, e[c].v, e[c].c));
  }
  if (l == r) {
    for (auto c : ask[l]) {
      cout << Query(e[c].u, e[c].v) << '\n';
    }
  } else {
    int mid = l + r >> 1;
    go(x * 2, l, mid);
    go(x * 2 + 1, mid + 1, r);
  }
  for (auto& c : d)
    if (c != -1) basis[c] = 0;
  rollback(tmp);
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  fill_n(lab, maxn, -1);
  for (int i = 1; i <= M; ++i) {
    cin >> e[i].u >> e[i].v >> e[i].c;
    last[make_pair(e[i].u, e[i].v)] = i;
  }
  cin >> Q;
  Q += M;
  for (int i = M + 1; i <= Q; ++i) {
    int type;
    cin >> type;
    if (type == 1) {
      cin >> e[i].u >> e[i].v >> e[i].c;
      last[make_pair(e[i].u, e[i].v)] = i;
    } else if (type == 2) {
      cin >> e[i].u >> e[i].v;
      update(1, M, Q, max(M, last[make_pair(e[i].u, e[i].v)]), i,
             last[make_pair(e[i].u, e[i].v)]);
      last.erase(make_pair(e[i].u, e[i].v));
    } else {
      cin >> e[i].u >> e[i].v;
      ask[i].emplace_back(i);
    }
  }
  for (auto& all : last) {
    update(1, M, Q, max(M, all.second), Q, all.second);
  }
  go(1, M, Q);
}