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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int kMaxN = 2000005;
vector<tuple<int, int, int>> queries[kMaxN];
vector<tuple<int, int, int>> updates[kMaxN];
int answer[kMaxN];
struct DSU {
  vector<int> link, dp, rank;
  DSU(int n) : link(n, -1), dp(n, 0), rank(n, 0) {}
  int Find(int& x) {
    int ret = 0;
    while (link[x] != -1) {
      ret ^= dp[x];
      x = link[x];
    }
    return ret;
  }
  vector<pair<int, int>> stk;
  int Union(int a, int b, int c) {
    c ^= Find(a);
    c ^= Find(b);
    if (a == b) return 0;
    if (rank[a] > rank[b]) swap(a, b);
    link[a] = b;
    dp[a] = c;
    rank[b] += (rank[a] == rank[b]);
    stk.emplace_back(a, b);
    return 1;
  }
  void Undo() {
    int a, b;
    tie(a, b) = stk.back();
    stk.pop_back();
    link[a] = -1;
    dp[a] = 0;
  }
};
void Add(int node, int b, int e, int l, int r, int x, int y, int c) {
  if (l > r) return;
  if (b == l && e == r) {
    updates[node].emplace_back(x, y, c);
    return;
  }
  int m = (b + e) / 2;
  Add(node * 2, b, m, l, min(m, r), x, y, c);
  Add(node * 2 + 1, m + 1, e, max(m + 1, l), r, x, y, c);
}
vector<int> ComputeBase(vector<int> V) {
  int at = 0, n = V.size();
  for (int bit = 29; bit >= 0; --bit) {
    if (at >= n) break;
    for (int i = at; i < n; ++i) {
      if (V[i] & 1 << bit) {
        swap(V[i], V[at]);
        break;
      }
    }
    if (V[at] & 1 << bit) {
      for (int i = 0; i < n; ++i) {
        if (i != at && (V[i] & 1 << bit)) V[i] ^= V[at];
      }
      at += 1;
    }
  }
  V.resize(at);
  return V;
}
int ComputeAnswer(vector<int> V, int val) {
  while (true) {
    int nxt = val, n = V.size();
    for (int i = 0; i < n; ++i) {
      nxt = min(nxt, val ^ V[i]);
    }
    if (nxt == val) break;
    val = nxt;
  }
  return val;
}
void Solve(int node, int b, int e, vector<int> base, DSU& dsu) {
  int uc = 0;
  for (auto itr : updates[node]) {
    int a, b, c;
    tie(a, b, c) = itr;
    if (dsu.Union(a, b, c))
      uc += 1;
    else
      base.push_back(c ^ dsu.Find(a) ^ dsu.Find(b));
  }
  base = ComputeBase(base);
  if (b == e) {
    for (auto itr : queries[b]) {
      int a, b, idx;
      tie(a, b, idx) = itr;
      answer[idx] = ComputeAnswer(base, dsu.Find(a) ^ dsu.Find(b));
    }
  } else {
    int m = (b + e) / 2;
    Solve(node * 2, b, m, base, dsu);
    Solve(node * 2 + 1, m + 1, e, base, dsu);
  }
  for (int i = 0; i < uc; ++i) dsu.Undo();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  map<pair<int, int>, pair<int, int>> edge_set;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    if (a > b) swap(a, b);
    edge_set[make_pair(a, b)] = make_pair(0, c);
  }
  int qc = 0;
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b, c;
      cin >> a >> b >> c;
      --a;
      --b;
      if (a > b) swap(a, b);
      edge_set[make_pair(a, b)] = make_pair(i, c);
    }
    if (t == 2) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      if (a > b) swap(a, b);
      auto p = edge_set[make_pair(a, b)];
      Add(1, 0, q, p.first, i, a, b, p.second);
      edge_set.erase(make_pair(a, b));
    }
    if (t == 3) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      queries[i].emplace_back(a, b, qc++);
    }
  }
  for (auto itr : edge_set) {
    int a, b, c, i;
    tie(a, b) = itr.first;
    tie(i, c) = itr.second;
    Add(1, 0, q, i, q, a, b, c);
  }
  DSU dsu(n);
  Solve(1, 0, q, {}, dsu);
  for (int i = 0; i < qc; ++i) {
    cout << answer[i] << '\n';
  }
  return 0;
}