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 N = 1 << 18;
int uf[N];
int cost[N];
vector<pair<int, int>> h_uf;
vector<pair<int, int>> h_cost;
pair<int, int> query[N];
int ans[N];
bool sample;
struct edge {
  int u, v, w;
  edge(int u, int v, int w) : u(u), v(v), w(w) {}
};
vector<edge> seg[N * 2];
int find(int u) {
  while (uf[u] >= 0) {
    u = uf[u];
  }
  return u;
}
int find_cost(int u) {
  int res = 0;
  while (uf[u] >= 0) {
    res ^= cost[u];
    u = uf[u];
  }
  return res;
}
bool unite(int u, int v, int w) {
  int pu = find(u);
  int pv = find(v);
  if (pu == pv) return false;
  w ^= find_cost(u);
  w ^= find_cost(v);
  u = pu;
  v = pv;
  if (-uf[u] < -uf[v]) swap(u, v);
  h_uf.emplace_back(u, uf[u]);
  h_uf.emplace_back(v, uf[v]);
  h_cost.emplace_back(v, cost[v]);
  uf[u] += uf[v];
  uf[v] = u;
  cost[v] = w;
  return true;
}
void undo() {
  auto p = h_uf.back();
  h_uf.pop_back();
  auto q = h_uf.back();
  h_uf.pop_back();
  auto r = h_cost.back();
  h_cost.pop_back();
  uf[p.first] = p.second;
  uf[q.first] = q.second;
  cost[r.first] = r.second;
}
int find_cost(int u, int v) { return find_cost(u) ^ find_cost(v); }
void init_uf(int n) {
  for (int i = 0; i < n; i++) {
    uf[i] = -1;
  }
}
void insert(int l, int r, edge e, int k = 1, int ll = 0, int rr = N) {
  if (rr <= l || r <= ll) return;
  if (l <= ll && rr <= r) {
    seg[k].emplace_back(e);
    return;
  }
  insert(l, r, e, k * 2 + 0, ll, ll + rr >> 1);
  insert(l, r, e, k * 2 + 1, ll + rr >> 1, rr);
}
vector<int> normalize(vector<int> a) {
  int r = 0;
  for (int j = 29; j >= 0; j--) {
    int p = -1;
    for (int i = r; i < a.size(); i++) {
      if (a[i] >> j & 1) {
        p = i;
        break;
      }
    }
    if (p == -1) continue;
    swap(a[r], a[p]);
    for (int i = r + 1; i < a.size(); i++) {
      if (a[i] >> j & 1) {
        a[i] ^= a[r];
      }
    }
    r++;
  }
  a.resize(r);
  return a;
}
int find_min(int x, vector<int> &a) {
  for (int y : a) x = min(x, x ^ y);
  return x;
}
void dfs(vector<int> a, int k = 1, int l = 0, int r = N) {
  int cnt = 0;
  for (edge e : seg[k]) {
    if (unite(e.u, e.v, e.w)) {
      cnt++;
    } else {
      a.push_back(e.w ^ find_cost(e.u, e.v));
    }
  }
  a = normalize(a);
  if (r - l == 1) {
    if (query[l].second != 0) {
      ans[l] = find_min(find_cost(query[l].first, query[l].second), a);
    }
    return;
  }
  dfs(a, k * 2 + 0, l, l + r >> 1);
  dfs(a, k * 2 + 1, l + r >> 1, r);
  while (cnt--) undo();
}
int input() {
  int n;
  scanf("%d", &n);
  return n;
}
int main() {
  int n, m;
  cin >> n >> m;
  init_uf(n);
  map<pair<int, int>, pair<int, int>> mp;
  for (int i = 0; i < m; i++) {
    int u = input() - 1;
    int v = input() - 1;
    int w = input();
    mp[{u, v}] = {w, 0};
  }
  int q = input();
  for (int i = 1; i <= q; i++) {
    int type = input();
    int u = input() - 1;
    int v = input() - 1;
    if (type == 1) {
      int w = input();
      mp[{u, v}] = {w, i};
    } else if (type == 2) {
      auto it = mp.find({u, v});
      insert(it->second.second, i, edge(u, v, it->second.first));
      mp.erase(it);
    } else {
      query[i] = {u, v};
    }
  }
  for (auto p : mp) {
    int u = p.first.first;
    int v = p.first.second;
    int w = p.second.first;
    int s = p.second.second;
    insert(s, q + 1, edge(u, v, w));
  }
  sample = n <= 10;
  dfs({});
  for (int i = 1; i <= q; i++) {
    if (query[i].second != 0) {
      printf("%d\n", ans[i]);
    }
  }
}